1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.filter.config.tools.utils;
25 
26 //_______________________________________________
27 // imports
28 import java.util.*;
29 import java.lang.*;
30 
31 //_______________________________________________
32 // implementation
33 public class AnalyzeStartupLog
34 {
35     private class OperationTime
36     {
37         /** name the measured operation. */
38         public java.lang.String sOperation;
39 
40         /** contains the time value, when this operation was started. */
41         public long nStartTime;
42 
43         /** contains the time value, when this operation was finished. */
44         public long nEndTime;
45 
46         /** text inside log file, which identifies the start time value. */
47         public java.lang.String sStartMsg;
48 
49         /** text inside log file, which identifies the end time value. */
50         public java.lang.String sEndMsg;
51     }
52 
53     //_________________________________
54     // main
55 
main(java.lang.String[] lCmdLine)56     public static void main(java.lang.String[] lCmdLine)
57     {
58         int nExit = 0;
59         try
60         {
61             // analyze command line
62             ConfigHelper aCmdLine  = new ConfigHelper("", lCmdLine);
63             java.lang.String        sLogDir   = aCmdLine.getString("logdir"  );
64             java.lang.String        sDataFile = aCmdLine.getString("datafile");
65 
66             if (sLogDir == null || sDataFile == null)
67             {
68                 System.err.println("AnalyzeStartupLog lodir=<dir> datafile=<file>");
69                 System.err.println("E.g.: AnalyzeStartupLog lodir=c:\\temp\\logs datafile=c:\\temp\\data.csv");
70                 System.exit(--nExit);
71             }
72 
73             // get list of all log files
74             boolean bRecursive = true;
75             java.util.Vector lLogs = FileHelper.getSystemFilesFromDir(new java.io.File(sLogDir), bRecursive);
76             if (lLogs == null || lLogs.isEmpty())
77             {
78                 System.err.println("log dir is empty");
79                 System.exit(--nExit);
80             }
81 
82             // analyze it
83             java.lang.StringBuffer sOut = new java.lang.StringBuffer(1000);
84             sOut.append("log;t_cfg_start;t_cfg_end;t_fwk_start;t_fwk_end;t_sfx_start;t_sfx_end;t_types_start;t_types_end;t_filters_start;t_filters_end;");
85             sOut.append("t_filters_swriter_start;t_filters_swriter_end;t_filters_sweb_start;t_filters_sweb_end;t_filters_sglobal_start;t_filters_sglobal_end;t_filters_scalc_start;t_filters_scalc_end;t_filters_sdraw_start;t_filters_sdraw_end;t_filters_simpress_start;t_filters_simpress_end;t_filters_schart_start;t_filters_schart_end;t_filters_smath_start;t_filters_smath_end;");
86             sOut.append("t_others_start;t_others_end;d_cfg;d_fwk;d_sfx;d_types;d_filters;d_others;d_complete\n");
87 
88             java.util.Enumeration aIt = lLogs.elements();
89             while (aIt.hasMoreElements())
90             {
91                 java.io.File           aLog    = (java.io.File)aIt.nextElement();
92                 java.io.FileReader     aReader = new java.io.FileReader(aLog);
93                 java.io.BufferedReader aBuffer = new java.io.BufferedReader(aReader);
94 
95                 long t_cfg_start                = 0;
96                 long t_cfg_end                  = 0;
97 
98                 long t_fwk_start                = 0;
99                 long t_fwk_end                  = 0;
100 
101                 long t_sfx_start                = 0;
102                 long t_sfx_end                  = 0;
103 
104                 long t_types_start              = 0;
105                 long t_types_end                = 0;
106 
107                 long t_filters_start            = 0;
108                 long t_filters_end              = 0;
109 
110                 long t_filters_swriter_start    = 0;
111                 long t_filters_swriter_end      = 0;
112 
113                 long t_filters_sweb_start       = 0;
114                 long t_filters_sweb_end         = 0;
115 
116                 long t_filters_sglobal_start    = 0;
117                 long t_filters_sglobal_end      = 0;
118 
119                 long t_filters_scalc_start      = 0;
120                 long t_filters_scalc_end        = 0;
121 
122                 long t_filters_sdraw_start      = 0;
123                 long t_filters_sdraw_end        = 0;
124 
125                 long t_filters_simpress_start   = 0;
126                 long t_filters_simpress_end     = 0;
127 
128                 long t_filters_schart_start     = 0;
129                 long t_filters_schart_end       = 0;
130 
131                 long t_filters_smath_start      = 0;
132                 long t_filters_smath_end        = 0;
133 
134                 long t_others_start             = 0;
135                 long t_others_end               = 0;
136 
137                 while (true)
138                 {
139                     java.lang.String sLine = aBuffer.readLine();
140                     if (sLine == null)
141                         break;
142 
143                     if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : { creation ConfigItem [file=standard, version=6, mode=3]"))
144                         t_cfg_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
145                     else
146                     if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : } creation ConfigItem"))
147                         t_cfg_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
148                     else
149                     if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : { reading TypeDetection.xml"))
150                         t_fwk_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
151                     else
152                     if (sLine.endsWith("| framework (as96863) ::FilterCache::FilterCache : } reading TypeDetection.xml"))
153                         t_fwk_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
154                     else
155                     if (sLine.endsWith("{ framework (as96863) ::FilterCFGAccess::impl_loadTypes"))
156                         t_types_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
157                     else
158                     if (sLine.endsWith("} framework (as96863) ::FilterCFGAccess::impl_loadTypes"))
159                         t_types_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
160                     else
161                     if (sLine.endsWith("{ framework (as96863) ::FilterCFGAccess::impl_loadFilters"))
162                         t_filters_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
163                     else
164                     if (sLine.endsWith("} framework (as96863) ::FilterCFGAccess::impl_loadFilters"))
165                         t_filters_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
166                     else
167                     if (sLine.endsWith("{ reading FilterGroup [swriter]"))
168                         t_filters_swriter_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
169                     else
170                     if (sLine.endsWith("} reading FilterGroup [swriter]"))
171                         t_filters_swriter_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
172                     else
173                     if (sLine.endsWith("{ reading FilterGroup [sweb]"))
174                         t_filters_sweb_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
175                     else
176                     if (sLine.endsWith("} reading FilterGroup [sweb]"))
177                         t_filters_sweb_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
178                     else
179                     if (sLine.endsWith("{ reading FilterGroup [sglobal]"))
180                         t_filters_sglobal_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
181                     else
182                     if (sLine.endsWith("} reading FilterGroup [sglobal]"))
183                         t_filters_sglobal_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
184                     else
185                     if (sLine.endsWith("{ reading FilterGroup [scalc]"))
186                         t_filters_scalc_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
187                     else
188                     if (sLine.endsWith("} reading FilterGroup [scalc]"))
189                         t_filters_scalc_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
190                     else
191                     if (sLine.endsWith("{ reading FilterGroup [sdraw]"))
192                         t_filters_sdraw_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
193                     else
194                     if (sLine.endsWith("} reading FilterGroup [sdraw]"))
195                         t_filters_sdraw_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
196                     else
197                     if (sLine.endsWith("{ reading FilterGroup [simpress]"))
198                         t_filters_simpress_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
199                     else
200                     if (sLine.endsWith("} reading FilterGroup [simpress]"))
201                         t_filters_simpress_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
202                     else
203                     if (sLine.endsWith("{ reading FilterGroup [schart]"))
204                         t_filters_schart_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
205                     else
206                     if (sLine.endsWith("} reading FilterGroup [schart]"))
207                         t_filters_schart_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
208                     else
209                     if (sLine.endsWith("{ reading FilterGroup [smath]"))
210                         t_filters_smath_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
211                     else
212                     if (sLine.endsWith("} reading FilterGroup [smath]"))
213                         t_filters_smath_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
214                     else
215                     if (sLine.endsWith("{ framework (as96863) ::FilterCFGAccess::impl_loadDetectors"))
216                         t_others_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
217                     else
218                     if (sLine.endsWith("} framework (as96863) ::FilterCFGAccess::impl_loadContentHandlers"))
219                         t_others_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
220                     else
221                     if (sLine.endsWith("} framework (as96863) ::FilterCache::FilterCache"))
222                         t_sfx_start = new java.lang.Long(sLine.substring(0, 6)).longValue();
223                     else
224                     if (sLine.endsWith("} desktop (lo119109) OfficeWrapper::OfficeWrapper"))
225                         t_sfx_end = new java.lang.Long(sLine.substring(0, 6)).longValue();
226                 }
227 
228                 sOut.append(aLog.getName()               );
229                 sOut.append(";"                          );
230                 sOut.append(t_cfg_start                  );
231                 sOut.append(";"                          );
232                 sOut.append(t_cfg_end                    );
233                 sOut.append(";"                          );
234                 sOut.append(t_fwk_start                  );
235                 sOut.append(";"                          );
236                 sOut.append(t_fwk_end                    );
237                 sOut.append(";"                          );
238                 sOut.append(t_sfx_start                  );
239                 sOut.append(";"                          );
240                 sOut.append(t_sfx_end                    );
241                 sOut.append(";"                          );
242                 sOut.append(t_types_start                );
243                 sOut.append(";"                          );
244                 sOut.append(t_types_end                  );
245                 sOut.append(";"                          );
246                 sOut.append(t_filters_start              );
247                 sOut.append(";"                          );
248                 sOut.append(t_filters_end                );
249                 sOut.append(";"                          );
250 
251                 sOut.append(t_filters_swriter_start      );
252                 sOut.append(";"                          );
253                 sOut.append(t_filters_swriter_end        );
254                 sOut.append(";"                          );
255                 sOut.append(t_filters_sweb_start         );
256                 sOut.append(";"                          );
257                 sOut.append(t_filters_sweb_end           );
258                 sOut.append(";"                          );
259                 sOut.append(t_filters_sglobal_start      );
260                 sOut.append(";"                          );
261                 sOut.append(t_filters_sglobal_end        );
262                 sOut.append(";"                          );
263                 sOut.append(t_filters_scalc_start        );
264                 sOut.append(";"                          );
265                 sOut.append(t_filters_scalc_end          );
266                 sOut.append(";"                          );
267                 sOut.append(t_filters_sdraw_start        );
268                 sOut.append(";"                          );
269                 sOut.append(t_filters_sdraw_end          );
270                 sOut.append(";"                          );
271                 sOut.append(t_filters_simpress_start     );
272                 sOut.append(";"                          );
273                 sOut.append(t_filters_simpress_end       );
274                 sOut.append(";"                          );
275                 sOut.append(t_filters_schart_start       );
276                 sOut.append(";"                          );
277                 sOut.append(t_filters_schart_end         );
278                 sOut.append(";"                          );
279                 sOut.append(t_filters_smath_start        );
280                 sOut.append(";"                          );
281                 sOut.append(t_filters_smath_end          );
282                 sOut.append(";"                          );
283 
284                 sOut.append(t_others_start               );
285                 sOut.append(";"                          );
286                 sOut.append(t_others_end                 );
287                 sOut.append(";"                          );
288                 sOut.append(t_cfg_end    -t_cfg_start    );
289                 sOut.append(";"                          );
290                 sOut.append(t_fwk_end    -t_fwk_start    );
291                 sOut.append(";"                          );
292                 sOut.append(t_sfx_end    -t_sfx_start    );
293                 sOut.append(";"                          );
294                 sOut.append(t_types_end  -t_types_start  );
295                 sOut.append(";"                          );
296                 sOut.append(t_filters_end-t_filters_start);
297                 sOut.append(";"                          );
298                 sOut.append(t_others_end -t_others_start );
299                 sOut.append(";"                          );
300                 sOut.append(t_others_end -t_cfg_start    );
301                 sOut.append("\n"                         );
302 
303                 aBuffer.close();
304             }
305 
306             java.io.FileWriter aCSV  = new java.io.FileWriter(sDataFile);
307             java.lang.String   sData = sOut.toString();
308             aCSV.write(sData, 0, sData.length());
309             aCSV.flush();
310             aCSV.close();
311         }
312         catch(java.lang.Throwable exAny)
313         {
314             System.err.println(exAny.getMessage());
315             exAny.printStackTrace();
316             System.exit(--nExit);
317         }
318 
319         System.exit(0);
320     }
321 }
322