nativeLoad remove #ifdef JOWENNDEBUG
[cacao.git] / statistics.c
1 /* statistics.c - global varables for statistics
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    Institut f. Computersprachen, TU Wien
5    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6    S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
7    J. Wenninger
8
9    This file is part of CACAO.
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24    02111-1307, USA.
25
26    Contact: cacao@complang.tuwien.ac.at
27
28    Authors: Christian Thalinger
29
30    $Id: statistics.c 1418 2004-10-19 14:11:58Z carolyn $
31
32 */
33
34
35 #include <sys/time.h>
36 #include <sys/resource.h>
37 #include "global.h"
38 #include "statistics.h"
39 #include "toolbox/logging.h"
40 #include "options.h"
41
42
43 /* global variables */
44
45 static s8 loadingtime = 0;              /* accumulated loading time           */
46 static s8 loadingstarttime = 0;
47 static s8 loadingstoptime = 0;
48 static s4 loadingtime_recursion = 0;
49
50 static s8 compilingtime = 0;            /* accumulated compile time           */
51 static s8 compilingstarttime = 0;
52 static s8 compilingstoptime = 0;
53 static s4 compilingtime_recursion = 0;
54
55 int count_class_infos = 0;              /* variables for measurements         */
56 int count_const_pool_len = 0;
57 int count_vftbl_len = 0;
58 int count_all_methods = 0;
59 int count_methods_marked_used = 0;  /* RTA */
60
61 int count_vmcode_len = 0;
62 int count_extable_len = 0;
63 int count_class_loads = 0;
64 int count_class_inits = 0;
65
66 int count_utf_len = 0;                  /* size of utf hash                   */
67 int count_utf_new = 0;                  /* calls of utf_new                   */
68 int count_utf_new_found  = 0;           /* calls of utf_new with fast return  */
69
70 int count_jit_calls = 0;
71 int count_methods = 0;
72 int count_spills = 0;
73 int count_pcmd_activ = 0;
74 int count_pcmd_drop = 0;
75 int count_pcmd_zero = 0;
76 int count_pcmd_const_store = 0;
77 int count_pcmd_const_alu = 0;
78 int count_pcmd_const_bra = 0;
79 int count_pcmd_load = 0;
80 int count_pcmd_move = 0;
81 int count_load_instruction = 0;
82 int count_pcmd_store = 0;
83 int count_pcmd_store_comb = 0;
84 int count_dup_instruction = 0;
85 int count_pcmd_op = 0;
86 int count_pcmd_mem = 0;
87 int count_pcmd_met = 0;
88 int count_pcmd_bra = 0;
89 int count_pcmd_table = 0;
90 int count_pcmd_return = 0;
91 int count_pcmd_returnx = 0;
92 int count_check_null = 0;
93 int count_check_bound = 0;
94 int count_max_basic_blocks = 0;
95 int count_basic_blocks = 0;
96 int count_javainstr = 0;
97 int count_max_javainstr = 0;
98 int count_javacodesize = 0;
99 int count_javaexcsize = 0;
100 int count_calls = 0;
101 int count_tryblocks = 0;
102 int count_code_len = 0;
103 int count_data_len = 0;
104 int count_cstub_len = 0;
105 int count_nstub_len = 0;
106 int count_max_new_stack = 0;
107 int count_upper_bound_new_stack = 0;
108 static int count_block_stack_init[11] = {
109         0, 0, 0, 0, 0, 
110         0, 0, 0, 0, 0, 
111         0
112 };
113 int *count_block_stack = count_block_stack_init;
114 static int count_analyse_iterations_init[5] = {
115         0, 0, 0, 0, 0
116 };
117 int *count_analyse_iterations = count_analyse_iterations_init;
118 static int count_method_bb_distribution_init[9] = {
119         0, 0, 0, 0, 0,
120         0, 0, 0, 0
121 };
122 int *count_method_bb_distribution = count_method_bb_distribution_init;
123 static int count_block_size_distribution_init[18] = {
124         0, 0, 0, 0, 0,
125         0, 0, 0, 0, 0,
126         0, 0, 0, 0, 0,
127         0, 0, 0
128 };
129 int *count_block_size_distribution = count_block_size_distribution_init;
130 static int count_store_length_init[21] = {
131         0, 0, 0, 0, 0,
132         0, 0, 0, 0, 0,
133         0, 0, 0, 0, 0,
134         0, 0, 0, 0, 0,
135         0
136 };
137 int *count_store_length = count_store_length_init;
138 static int count_store_depth_init[11] = {
139         0, 0, 0, 0, 0,
140         0, 0, 0, 0, 0,
141         0
142 };
143 int *count_store_depth = count_store_depth_init;
144
145
146 /* getcputime *********************************** ******************************
147
148    Returns the used CPU time in microseconds
149         
150 *******************************************************************************/
151
152 s8 getcputime()
153 {
154         struct rusage ru;
155         int sec, usec;
156
157         getrusage(RUSAGE_SELF, &ru);
158         sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
159         usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
160
161         return sec * 1000000 + usec;
162 }
163
164
165 /* loadingtime_stop ************************************************************
166
167    XXX
168
169 *******************************************************************************/
170
171 void loadingtime_start()
172 {
173         loadingtime_recursion++;
174
175         if (loadingtime_recursion == 1)
176                 loadingstarttime = getcputime();
177 }
178
179
180 /* loadingtime_stop ************************************************************
181
182    XXX
183
184 *******************************************************************************/
185
186 void loadingtime_stop()
187 {
188         if (loadingtime_recursion == 1) {
189                 loadingstoptime = getcputime();
190                 loadingtime += (loadingstoptime - loadingstarttime);
191         }
192
193         loadingtime_recursion--;
194 }
195
196
197 /* compilingtime_stop **********************************************************
198
199    XXX
200
201 *******************************************************************************/
202
203 void compilingtime_start()
204 {
205         compilingtime_recursion++;
206
207         if (compilingtime_recursion == 1)
208                 compilingstarttime = getcputime();
209 }
210
211
212 /* compilingtime_stop **********************************************************
213
214    XXX
215
216 *******************************************************************************/
217
218 void compilingtime_stop()
219 {
220         if (compilingtime_recursion == 1) {
221                 compilingstoptime = getcputime();
222                 compilingtime += (compilingstoptime - compilingstarttime);
223         }
224
225         compilingtime_recursion--;
226 }
227
228
229 /* print_times *****************************************************************
230
231    Prints a summary of CPU time usage.
232
233 *******************************************************************************/
234
235 void print_times()
236 {
237         s8 totaltime = getcputime();
238         s8 runtime = totaltime - loadingtime - compilingtime;
239         char logtext[MAXLOGTEXT];
240
241 #if defined(__I386__) || defined(__POWERPC__)
242         sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
243 #else
244         sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
245 #endif
246                         loadingtime / 1000000, (loadingtime % 1000000) / 1000);
247         log_text(logtext);
248
249 #if defined(__I386__) || defined(__POWERPC__) 
250         sprintf(logtext, "Time for compiling code:  %lld secs, %lld millis",
251 #else
252         sprintf(logtext, "Time for compiling code:  %ld secs, %ld millis",
253 #endif
254                         compilingtime / 1000000, (compilingtime % 1000000) / 1000);
255         log_text(logtext);
256
257 #if defined(__I386__) || defined(__POWERPC__) 
258         sprintf(logtext, "Time for running program: %lld secs, %lld millis",
259 #else
260         sprintf(logtext, "Time for running program: %ld secs, %ld millis",
261 #endif
262                         runtime / 1000000, (runtime % 1000000) / 1000);
263         log_text(logtext);
264
265 #if defined(__I386__) || defined(__POWERPC__) 
266         sprintf(logtext, "Total time: %lld secs, %lld millis",
267 #else
268         sprintf(logtext, "Total time: %ld secs, %ld millis",
269 #endif
270                         totaltime / 1000000, (totaltime % 1000000) / 1000);
271         log_text(logtext);
272 }
273
274
275 /* print_stats *****************************************************************
276
277    outputs detailed compiler statistics
278
279 *******************************************************************************/
280
281 void print_stats()
282 {
283         char logtext[MAXLOGTEXT];
284
285         sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
286         log_text(logtext);
287         sprintf(logtext, "Number of compiled Methods: %d", count_methods);
288         log_text(logtext);
289         if (opt_rt) {
290           sprintf(logtext, "Number of Methods marked Used: %d", count_methods_marked_used);
291           log_text(logtext);
292           }
293         sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
294         log_text(logtext);
295         sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
296         log_text(logtext);
297         sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
298         log_text(logtext);
299         sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
300         log_text(logtext);
301         sprintf(logtext, "Size of compiled JavaVM-Instructions:   %d(%d)", count_javacodesize,
302                         count_javacodesize - count_methods * 18);
303         log_text(logtext);
304         sprintf(logtext, "Size of compiled Exception Tables:      %d", count_javaexcsize);
305         log_text(logtext);
306         sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
307         log_text(logtext);
308         sprintf(logtext, "Number of Spills: %d", count_spills);
309         log_text(logtext);
310         sprintf(logtext, "Number of Activ    Pseudocommands: %5d", count_pcmd_activ);
311         log_text(logtext);
312         sprintf(logtext, "Number of Drop     Pseudocommands: %5d", count_pcmd_drop);
313         log_text(logtext);
314         sprintf(logtext, "Number of Const    Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
315         log_text(logtext);
316         sprintf(logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
317         log_text(logtext);
318         sprintf(logtext, "Number of Move     Pseudocommands: %5d", count_pcmd_move);
319         log_text(logtext);
320         sprintf(logtext, "Number of Load     Pseudocommands: %5d", count_load_instruction);
321         log_text(logtext);
322         sprintf(logtext, "Number of Store    Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
323         log_text(logtext);
324         sprintf(logtext, "Number of OP       Pseudocommands: %5d", count_pcmd_op);
325         log_text(logtext);
326         sprintf(logtext, "Number of DUP      Pseudocommands: %5d", count_dup_instruction);
327         log_text(logtext);
328         sprintf(logtext, "Number of Mem      Pseudocommands: %5d", count_pcmd_mem);
329         log_text(logtext);
330         sprintf(logtext, "Number of Method   Pseudocommands: %5d", count_pcmd_met);
331         log_text(logtext);
332         sprintf(logtext, "Number of Branch   Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
333                         count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
334         log_text(logtext);
335         sprintf(logtext, "Number of Table    Pseudocommands: %5d", count_pcmd_table);
336         log_text(logtext);
337         sprintf(logtext, "Number of Useful   Pseudocommands: %5d", count_pcmd_table +
338                         count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
339         log_text(logtext);
340         sprintf(logtext, "Number of Null Pointer Checks:     %5d", count_check_null);
341         log_text(logtext);
342         sprintf(logtext, "Number of Array Bound Checks:      %5d", count_check_bound);
343         log_text(logtext);
344         sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
345         log_text(logtext);
346         sprintf(logtext, "Maximal count of stack elements:   %d", count_max_new_stack);
347         log_text(logtext);
348         sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
349         log_text(logtext);
350         sprintf(logtext, "Distribution of stack sizes at block boundary");
351         log_text(logtext);
352         sprintf(logtext, "    0    1    2    3    4    5    6    7    8    9    >=10");
353         log_text(logtext);
354         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_block_stack[0],
355                         count_block_stack[1], count_block_stack[2], count_block_stack[3], count_block_stack[4],
356                         count_block_stack[5], count_block_stack[6], count_block_stack[7], count_block_stack[8],
357                         count_block_stack[9], count_block_stack[10]);
358         log_text(logtext);
359         sprintf(logtext, "Distribution of store stack depth");
360         log_text(logtext);
361         sprintf(logtext, "    0    1    2    3    4    5    6    7    8    9    >=10");
362         log_text(logtext);
363         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_depth[0],
364                         count_store_depth[1], count_store_depth[2], count_store_depth[3], count_store_depth[4],
365                         count_store_depth[5], count_store_depth[6], count_store_depth[7], count_store_depth[8],
366                         count_store_depth[9], count_store_depth[10]);
367         log_text(logtext);
368         sprintf(logtext, "Distribution of store creator chains first part");
369         log_text(logtext);
370         sprintf(logtext, "    0    1    2    3    4    5    6    7    8    9  ");
371         log_text(logtext);
372         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[0],
373                         count_store_length[1], count_store_length[2], count_store_length[3], count_store_length[4],
374                         count_store_length[5], count_store_length[6], count_store_length[7], count_store_length[8],
375                         count_store_length[9]);
376         log_text(logtext);
377         sprintf(logtext, "Distribution of store creator chains second part");
378         log_text(logtext);
379         sprintf(logtext, "   10   11   12   13   14   15   16   17   18   19  >=20");
380         log_text(logtext);
381         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[10],
382                         count_store_length[11], count_store_length[12], count_store_length[13], count_store_length[14],
383                         count_store_length[15], count_store_length[16], count_store_length[17], count_store_length[18],
384                         count_store_length[19], count_store_length[20]);
385         log_text(logtext);
386         sprintf(logtext, "Distribution of analysis iterations");
387         log_text(logtext);
388         sprintf(logtext, "    1    2    3    4    >=5");
389         log_text(logtext);
390         sprintf(logtext, "%5d%5d%5d%5d%5d", count_analyse_iterations[0], count_analyse_iterations[1],
391                         count_analyse_iterations[2], count_analyse_iterations[3], count_analyse_iterations[4]);
392         log_text(logtext);
393         sprintf(logtext, "Distribution of basic blocks per method");
394         log_text(logtext);
395         sprintf(logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75  >75");
396         log_text(logtext);
397         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_method_bb_distribution[0],
398                         count_method_bb_distribution[1], count_method_bb_distribution[2], count_method_bb_distribution[3],
399                         count_method_bb_distribution[4], count_method_bb_distribution[5], count_method_bb_distribution[6],
400                         count_method_bb_distribution[7], count_method_bb_distribution[8]);
401         log_text(logtext);
402         sprintf(logtext, "Distribution of basic block sizes");
403         log_text(logtext);
404         sprintf(logtext,
405                          "  0    1    2    3    4   5   6   7   8   9 <13 <15 <17 <19 <21 <26 <31 >30");
406         log_text(logtext);
407         sprintf(logtext, "%3d%5d%5d%5d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d",
408                         count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
409                         count_block_size_distribution[3], count_block_size_distribution[4], count_block_size_distribution[5],
410                         count_block_size_distribution[6], count_block_size_distribution[7], count_block_size_distribution[8],
411                         count_block_size_distribution[9], count_block_size_distribution[10], count_block_size_distribution[11],
412                         count_block_size_distribution[12], count_block_size_distribution[13], count_block_size_distribution[14],
413                         count_block_size_distribution[15], count_block_size_distribution[16], count_block_size_distribution[17]);
414         log_text(logtext);
415         sprintf(logtext, "Size of Code Area (Kb):  %10.3f", (float) count_code_len / 1024);
416         log_text(logtext);
417         sprintf(logtext, "Size of data Area (Kb):  %10.3f", (float) count_data_len / 1024);
418         log_text(logtext);
419         sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
420         log_text(logtext);
421         sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
422         log_text(logtext);
423         sprintf(logtext, "Size of Vftbl (Kb):      %10.3f", (float) count_vftbl_len / 1024);
424         log_text(logtext);
425         sprintf(logtext, "Size of comp stub (Kb):  %10.3f", (float) count_cstub_len / 1024);
426         log_text(logtext);
427         sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
428         log_text(logtext);
429         sprintf(logtext, "Size of Utf (Kb):        %10.3f", (float) count_utf_len / 1024);
430         log_text(logtext);
431         sprintf(logtext, "Size of VMCode (Kb):     %10.3f(%d)", (float) count_vmcode_len / 1024,
432                         count_vmcode_len - 18 * count_all_methods);
433         log_text(logtext);
434         sprintf(logtext, "Size of ExTable (Kb):    %10.3f", (float) count_extable_len / 1024);
435         log_text(logtext);
436         sprintf(logtext, "Number of class loads:   %d", count_class_loads);
437         log_text(logtext);
438         sprintf(logtext, "Number of class inits:   %d", count_class_inits);
439         log_text(logtext);
440         sprintf(logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
441         log_text(logtext);
442
443         sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
444         log_text(logtext);
445         sprintf(logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
446         log_text(logtext);
447 }
448
449
450 /*
451  * These are local overrides for various environment variables in Emacs.
452  * Please do not remove this and leave it at the end of the file, where
453  * Emacs will automagically detect them.
454  * ---------------------------------------------------------------------
455  * Local variables:
456  * mode: c
457  * indent-tabs-mode: t
458  * c-basic-offset: 4
459  * tab-width: 4
460  * End:
461  */