1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 // import java.io.FileWriter;
32 // import java.io.OutputStream;
33 // import java.io.PrintStream;
34 import java
.io
.PrintStream
;
35 import java
.io
.RandomAccessFile
;
36 // import java.io.StringWriter;
37 // import java.lang.Double;
40 public class PerformanceContainer
/* extends *//* implements */ {
41 private long m_nStartTime
;
44 simple helper functions to start/stop a timer, to know how long a process need in milliseconds
46 public long getStartTime()
48 return System
.currentTimeMillis();
50 public void setStartTime(long _nStartTime
)
52 m_nStartTime
= _nStartTime
;
56 return the time, which is done until last startTime()
58 private long meanTime(long _nCurrentTimer
)
60 if (_nCurrentTimer
== 0)
62 GlobalLogWriter
.println("Forgotten to initialise a start timer.");
65 long nMeanTime
= System
.currentTimeMillis();
66 return nMeanTime
- _nCurrentTimer
;
70 public long stopTimer()
72 if (m_nStartTime == 0)
74 System.out.println("Forgotten to initialise start timer.");
77 long nStopTime = System.currentTimeMillis();
78 return nStopTime - m_nStartTime;
82 final static int Load
= 0;
83 final static int Store
= 1;
84 final static int Print
= 2;
85 final static int OfficeStart
= 3;
86 final static int StoreAsPDF
= 4;
87 final static int OfficeStop
= 5;
88 final static int AllTime
= 6;
89 final static int LAST_VALUE
= 7; // THIS MUST BE ALWAYS THE LAST AND THE BIGGEST VALUE!
91 private long m_nTime
[];
92 private String m_sMSOfficeVersion
;
94 public PerformanceContainer()
96 m_nTime
= new long[LAST_VALUE
];
97 // @todo: is this need?
98 for (int i
=0;i
<LAST_VALUE
;i
++)
104 public void setTime(int _nIndex
, long _nValue
)
106 m_nTime
[_nIndex
] = _nValue
;
108 public long getTime(int _nIndex
)
110 return m_nTime
[_nIndex
];
113 public void startTime(int _nIndex
)
115 m_nTime
[_nIndex
] = getStartTime();
118 public void stopTime(int _nIndex
)
120 m_nTime
[_nIndex
] = meanTime(m_nTime
[_nIndex
]);
123 public String
getMSOfficeVersion()
125 return m_sMSOfficeVersion
;
128 public void print(PrintStream out
)
130 // String ls = System.getProperty("line.separator");
132 out
.println("loadtime=" + String
.valueOf(m_nTime
[ Load
]));
133 out
.println("storetime=" + String
.valueOf(m_nTime
[ Store
]));
134 out
.println("printtime=" + String
.valueOf(m_nTime
[ Print
]));
135 out
.println("officestarttime=" + String
.valueOf(m_nTime
[ OfficeStart
]));
136 out
.println("officestoptime=" + String
.valueOf(m_nTime
[ OfficeStop
]));
137 out
.println("storeaspdftime=" + String
.valueOf(m_nTime
[ StoreAsPDF
]));
138 out
.println("alltime=" + String
.valueOf(m_nTime
[ AllTime
]));
141 public void print(IniFile _aIniFile
, String _sSection
)
143 // String ls = System.getProperty("line.separator");
145 _aIniFile
.insertValue(_sSection
, "loadtime" , String
.valueOf(m_nTime
[ Load
]));
146 _aIniFile
.insertValue(_sSection
, "storetime" , String
.valueOf(m_nTime
[ Store
]));
147 _aIniFile
.insertValue(_sSection
, "printtime" , String
.valueOf(m_nTime
[ Print
]));
148 _aIniFile
.insertValue(_sSection
, "officestarttime" , String
.valueOf(m_nTime
[ OfficeStart
]));
149 _aIniFile
.insertValue(_sSection
, "officestoptime" , String
.valueOf(m_nTime
[ OfficeStop
]));
150 _aIniFile
.insertValue(_sSection
, "storeaspdftime" , String
.valueOf(m_nTime
[ StoreAsPDF
]));
151 _aIniFile
.insertValue(_sSection
, "alltime" , String
.valueOf(m_nTime
[ AllTime
]));
154 public static double stringToDouble(String _sStr
)
159 nValue
= Double
.parseDouble( _sStr
);
161 catch (NumberFormatException e
)
163 GlobalLogWriter
.println("Can't convert string to double " + _sStr
);
168 public static long secondsToMilliSeconds(double _nSeconds
)
170 return (long)(_nSeconds
* 1000.0);
174 Helper function, which read some values from a given file
176 sample of wordinfofile
177 name=c:\doc-pool\wntmsci\samples\msoffice\word\LineSpacing.doc
179 WordStartTime=0.340490102767944
180 WordLoadTime=0.650935888290405
181 WordPrintTime=0.580835103988647
183 public void readWordValuesFromFile(String sFilename
)
185 File aFile
= new File(sFilename
);
186 if (! aFile
.exists())
188 GlobalLogWriter
.println("couldn't find file " + sFilename
);
192 RandomAccessFile aRandomAccessFile
= null;
195 aRandomAccessFile
= new RandomAccessFile(aFile
,"r");
197 while (sLine
!= null)
199 sLine
= aRandomAccessFile
.readLine();
200 if ( (sLine
!= null) &&
201 (! (sLine
.length() < 2) ) &&
202 (! sLine
.startsWith("#")))
204 if (sLine
.startsWith("WordStartTime="))
206 String sTime
= sLine
.substring(14);
207 m_nTime
[OfficeStart
] = secondsToMilliSeconds(stringToDouble(sTime
));
209 else if (sLine
.startsWith("WordLoadTime="))
211 String sTime
= sLine
.substring(13);
212 m_nTime
[Load
] = secondsToMilliSeconds(stringToDouble(sTime
));
214 else if (sLine
.startsWith("WordPrintTime="))
216 String sTime
= sLine
.substring(14);
217 m_nTime
[Print
] = secondsToMilliSeconds(stringToDouble(sTime
));
219 else if (sLine
.startsWith("WordVersion="))
221 String sMSOfficeVersion
= sLine
.substring(12);
222 m_sMSOfficeVersion
= "Word:" + sMSOfficeVersion
;
224 else if (sLine
.startsWith("ExcelVersion="))
226 String sMSOfficeVersion
= sLine
.substring(13);
227 m_sMSOfficeVersion
= "Excel:" + sMSOfficeVersion
;
229 else if (sLine
.startsWith("PowerPointVersion="))
231 String sMSOfficeVersion
= sLine
.substring(18);
232 m_sMSOfficeVersion
= "PowerPoint:" + sMSOfficeVersion
;
237 catch (java
.io
.FileNotFoundException fne
)
239 GlobalLogWriter
.println("couldn't open file " + sFilename
);
240 GlobalLogWriter
.println("Message: " + fne
.getMessage());
242 catch (java
.io
.IOException ie
)
244 GlobalLogWriter
.println("Exception while reading file " + sFilename
);
245 GlobalLogWriter
.println("Message: " + ie
.getMessage());
249 aRandomAccessFile
.close();
251 catch (java
.io
.IOException ie
)
253 GlobalLogWriter
.println("Couldn't close file " + sFilename
);
254 GlobalLogWriter
.println("Message: " + ie
.getMessage());
258 // public static void main(String[] args)
260 // BorderRemover a = new BorderRemover();
263 // a.createNewImageWithoutBorder(args[0], args[1]);
265 // catch(java.io.IOException e)
267 // System.out.println("Exception caught.");