1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PerformanceContainer.java,v $
10 * $Revision: 1.1.2.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 // import java.io.FileWriter;
35 // import java.io.OutputStream;
36 // import java.io.PrintStream;
37 import java
.io
.PrintStream
;
38 import java
.io
.RandomAccessFile
;
39 // import java.io.StringWriter;
40 // import java.lang.Double;
43 public class PerformanceContainer
/* extends *//* implements */ {
44 private long m_nStartTime
;
47 simple helper functions to start/stop a timer, to know how long a process need in milliseconds
49 public long getStartTime()
51 return System
.currentTimeMillis();
53 public void setStartTime(long _nStartTime
)
55 m_nStartTime
= _nStartTime
;
59 return the time, which is done until last startTime()
61 private long meanTime(long _nCurrentTimer
)
63 if (_nCurrentTimer
== 0)
65 GlobalLogWriter
.get().println("Forgotten to initialise a start timer.");
68 long nMeanTime
= System
.currentTimeMillis();
69 return nMeanTime
- _nCurrentTimer
;
73 public long stopTimer()
75 if (m_nStartTime == 0)
77 System.out.println("Forgotten to initialise start timer.");
80 long nStopTime = System.currentTimeMillis();
81 return nStopTime - m_nStartTime;
85 final static int Load
= 0;
86 final static int Store
= 1;
87 final static int Print
= 2;
88 final static int OfficeStart
= 3;
89 final static int StoreAsPDF
= 4;
90 final static int OfficeStop
= 5;
91 final static int AllTime
= 6;
92 final static int LAST_VALUE
= 7; // THIS MUST BE ALWAYS THE LAST AND THE BIGGEST VALUE!
94 private long m_nTime
[];
95 private String m_sMSOfficeVersion
;
97 public PerformanceContainer()
99 m_nTime
= new long[LAST_VALUE
];
100 // @todo: is this need?
101 for (int i
=0;i
<LAST_VALUE
;i
++)
107 public void setTime(int _nIndex
, long _nValue
)
109 m_nTime
[_nIndex
] = _nValue
;
111 public long getTime(int _nIndex
)
113 return m_nTime
[_nIndex
];
116 public void startTime(int _nIndex
)
118 m_nTime
[_nIndex
] = getStartTime();
121 public void stopTime(int _nIndex
)
123 m_nTime
[_nIndex
] = meanTime(m_nTime
[_nIndex
]);
126 public String
getMSOfficeVersion()
128 return m_sMSOfficeVersion
;
131 public void print(PrintStream out
)
133 // String ls = System.getProperty("line.separator");
135 out
.println("loadtime=" + String
.valueOf(m_nTime
[ Load
]));
136 out
.println("storetime=" + String
.valueOf(m_nTime
[ Store
]));
137 out
.println("printtime=" + String
.valueOf(m_nTime
[ Print
]));
138 out
.println("officestarttime=" + String
.valueOf(m_nTime
[ OfficeStart
]));
139 out
.println("officestoptime=" + String
.valueOf(m_nTime
[ OfficeStop
]));
140 out
.println("storeaspdftime=" + String
.valueOf(m_nTime
[ StoreAsPDF
]));
141 out
.println("alltime=" + String
.valueOf(m_nTime
[ AllTime
]));
144 public void print(IniFile _aIniFile
, String _sSection
)
146 // String ls = System.getProperty("line.separator");
148 _aIniFile
.insertValue(_sSection
, "loadtime" , String
.valueOf(m_nTime
[ Load
]));
149 _aIniFile
.insertValue(_sSection
, "storetime" , String
.valueOf(m_nTime
[ Store
]));
150 _aIniFile
.insertValue(_sSection
, "printtime" , String
.valueOf(m_nTime
[ Print
]));
151 _aIniFile
.insertValue(_sSection
, "officestarttime" , String
.valueOf(m_nTime
[ OfficeStart
]));
152 _aIniFile
.insertValue(_sSection
, "officestoptime" , String
.valueOf(m_nTime
[ OfficeStop
]));
153 _aIniFile
.insertValue(_sSection
, "storeaspdftime" , String
.valueOf(m_nTime
[ StoreAsPDF
]));
154 _aIniFile
.insertValue(_sSection
, "alltime" , String
.valueOf(m_nTime
[ AllTime
]));
157 public static double stringToDouble(String _sStr
)
162 nValue
= Double
.parseDouble( _sStr
);
164 catch (NumberFormatException e
)
166 GlobalLogWriter
.get().println("Can't convert string to double " + _sStr
);
171 public static long secondsToMilliSeconds(double _nSeconds
)
173 return (long)(_nSeconds
* 1000.0);
177 Helper function, which read some values from a given file
179 sample of wordinfofile
180 name=c:\doc-pool\wntmsci\samples\msoffice\word\LineSpacing.doc
182 WordStartTime=0.340490102767944
183 WordLoadTime=0.650935888290405
184 WordPrintTime=0.580835103988647
186 public void readWordValuesFromFile(String sFilename
)
188 File aFile
= new File(sFilename
);
189 if (! aFile
.exists())
191 GlobalLogWriter
.get().println("couldn't find file " + sFilename
);
195 RandomAccessFile aRandomAccessFile
= null;
198 aRandomAccessFile
= new RandomAccessFile(aFile
,"r");
200 while (sLine
!= null)
202 sLine
= aRandomAccessFile
.readLine();
203 if ( (sLine
!= null) &&
204 (! (sLine
.length() < 2) ) &&
205 (! sLine
.startsWith("#")))
207 if (sLine
.startsWith("WordStartTime="))
209 String sTime
= sLine
.substring(14);
210 m_nTime
[OfficeStart
] = secondsToMilliSeconds(stringToDouble(sTime
));
212 else if (sLine
.startsWith("WordLoadTime="))
214 String sTime
= sLine
.substring(13);
215 m_nTime
[Load
] = secondsToMilliSeconds(stringToDouble(sTime
));
217 else if (sLine
.startsWith("WordPrintTime="))
219 String sTime
= sLine
.substring(14);
220 m_nTime
[Print
] = secondsToMilliSeconds(stringToDouble(sTime
));
222 else if (sLine
.startsWith("WordVersion="))
224 String sMSOfficeVersion
= sLine
.substring(12);
225 m_sMSOfficeVersion
= "Word:" + sMSOfficeVersion
;
227 else if (sLine
.startsWith("ExcelVersion="))
229 String sMSOfficeVersion
= sLine
.substring(13);
230 m_sMSOfficeVersion
= "Excel:" + sMSOfficeVersion
;
232 else if (sLine
.startsWith("PowerPointVersion="))
234 String sMSOfficeVersion
= sLine
.substring(18);
235 m_sMSOfficeVersion
= "PowerPoint:" + sMSOfficeVersion
;
240 catch (java
.io
.FileNotFoundException fne
)
242 GlobalLogWriter
.get().println("couldn't open file " + sFilename
);
243 GlobalLogWriter
.get().println("Message: " + fne
.getMessage());
245 catch (java
.io
.IOException ie
)
247 GlobalLogWriter
.get().println("Exception while reading file " + sFilename
);
248 GlobalLogWriter
.get().println("Message: " + ie
.getMessage());
252 aRandomAccessFile
.close();
254 catch (java
.io
.IOException ie
)
256 GlobalLogWriter
.get().println("Couldn't close file " + sFilename
);
257 GlobalLogWriter
.get().println("Message: " + ie
.getMessage());
261 // public static void main(String[] args)
263 // BorderRemover a = new BorderRemover();
266 // a.createNewImageWithoutBorder(args[0], args[1]);
268 // catch(java.io.IOException e)
270 // System.out.println("Exception caught.");