Next save.
[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 1224 2004-06-30 19:13:37Z twisti $
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
41
42 /* global variables */
43
44 s8 loadingtime = 0;
45 s8 compilingtime = 0;                   /* accumulated compile time           */
46
47 int count_class_infos = 0;              /* variables for measurements         */
48 int count_const_pool_len = 0;
49 int count_vftbl_len = 0;
50 int count_all_methods = 0;
51 int count_vmcode_len = 0;
52 int count_extable_len = 0;
53 int count_class_loads = 0;
54 int count_class_inits = 0;
55
56 int count_utf_len = 0;                  /* size of utf hash                   */
57 int count_utf_new = 0;                  /* calls of utf_new                   */
58 int count_utf_new_found  = 0;           /* calls of utf_new with fast return  */
59
60 int count_jit_calls = 0;
61 int count_methods = 0;
62 int count_spills = 0;
63 int count_pcmd_activ = 0;
64 int count_pcmd_drop = 0;
65 int count_pcmd_zero = 0;
66 int count_pcmd_const_store = 0;
67 int count_pcmd_const_alu = 0;
68 int count_pcmd_const_bra = 0;
69 int count_pcmd_load = 0;
70 int count_pcmd_move = 0;
71 int count_load_instruction = 0;
72 int count_pcmd_store = 0;
73 int count_pcmd_store_comb = 0;
74 int count_dup_instruction = 0;
75 int count_pcmd_op = 0;
76 int count_pcmd_mem = 0;
77 int count_pcmd_met = 0;
78 int count_pcmd_bra = 0;
79 int count_pcmd_table = 0;
80 int count_pcmd_return = 0;
81 int count_pcmd_returnx = 0;
82 int count_check_null = 0;
83 int count_check_bound = 0;
84 int count_max_basic_blocks = 0;
85 int count_basic_blocks = 0;
86 int count_javainstr = 0;
87 int count_max_javainstr = 0;
88 int count_javacodesize = 0;
89 int count_javaexcsize = 0;
90 int count_calls = 0;
91 int count_tryblocks = 0;
92 int count_code_len = 0;
93 int count_data_len = 0;
94 int count_cstub_len = 0;
95 int count_nstub_len = 0;
96 int count_max_new_stack = 0;
97 int count_upper_bound_new_stack = 0;
98 static int count_block_stack_init[11] = {
99         0, 0, 0, 0, 0, 
100         0, 0, 0, 0, 0, 
101         0
102 };
103 int *count_block_stack = count_block_stack_init;
104 static int count_analyse_iterations_init[5] = {
105         0, 0, 0, 0, 0
106 };
107 int *count_analyse_iterations = count_analyse_iterations_init;
108 static int count_method_bb_distribution_init[9] = {
109         0, 0, 0, 0, 0,
110         0, 0, 0, 0
111 };
112 int *count_method_bb_distribution = count_method_bb_distribution_init;
113 static int count_block_size_distribution_init[18] = {
114         0, 0, 0, 0, 0,
115         0, 0, 0, 0, 0,
116         0, 0, 0, 0, 0,
117         0, 0, 0
118 };
119 int *count_block_size_distribution = count_block_size_distribution_init;
120 static int count_store_length_init[21] = {
121         0, 0, 0, 0, 0,
122         0, 0, 0, 0, 0,
123         0, 0, 0, 0, 0,
124         0, 0, 0, 0, 0,
125         0
126 };
127 int *count_store_length = count_store_length_init;
128 static int count_store_depth_init[11] = {
129         0, 0, 0, 0, 0,
130         0, 0, 0, 0, 0,
131         0
132 };
133 int *count_store_depth = count_store_depth_init;
134
135
136 /* getcputime *********************************** ******************************
137
138    Returns the used CPU time in microseconds
139         
140 *******************************************************************************/
141
142 s8 getcputime()
143 {
144         struct rusage ru;
145         int sec, usec;
146
147         getrusage(RUSAGE_SELF, &ru);
148         sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
149         usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
150
151         return sec * 1000000 + usec;
152 }
153
154
155 /* print_times *****************************************************************
156
157    Prints a summary of CPU time usage.
158
159 *******************************************************************************/
160
161 void print_times()
162 {
163         s8 totaltime = getcputime();
164         s8 runtime = totaltime - loadingtime - compilingtime;
165         char logtext[MAXLOGTEXT];
166
167 #if defined(__I386__) || defined(__POWERPC__)
168         sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
169 #else
170         sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
171 #endif
172                         loadingtime / 1000000, (loadingtime % 1000000) / 1000);
173         log_text(logtext);
174
175 #if defined(__I386__) || defined(__POWERPC__) 
176         sprintf(logtext, "Time for compiling code:  %lld secs, %lld millis",
177 #else
178         sprintf(logtext, "Time for compiling code:  %ld secs, %ld millis",
179 #endif
180                         compilingtime / 1000000, (compilingtime % 1000000) / 1000);
181         log_text(logtext);
182
183 #if defined(__I386__) || defined(__POWERPC__) 
184         sprintf(logtext, "Time for running program: %lld secs, %lld millis",
185 #else
186         sprintf(logtext, "Time for running program: %ld secs, %ld millis",
187 #endif
188                         runtime / 1000000, (runtime % 1000000) / 1000);
189         log_text(logtext);
190
191 #if defined(__I386__) || defined(__POWERPC__) 
192         sprintf(logtext, "Total time: %lld secs, %lld millis",
193 #else
194         sprintf(logtext, "Total time: %ld secs, %ld millis",
195 #endif
196                         totaltime / 1000000, (totaltime % 1000000) / 1000);
197         log_text(logtext);
198 }
199
200
201 /* print_stats *****************************************************************
202
203    outputs detailed compiler statistics
204
205 *******************************************************************************/
206
207 void print_stats()
208 {
209         char logtext[MAXLOGTEXT];
210
211         sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
212         log_text(logtext);
213         sprintf(logtext, "Number of compiled Methods: %d", count_methods);
214         log_text(logtext);
215         sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
216         log_text(logtext);
217         sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
218         log_text(logtext);
219         sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
220         log_text(logtext);
221         sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
222         log_text(logtext);
223         sprintf(logtext, "Size of compiled JavaVM-Instructions:   %d(%d)", count_javacodesize,
224                         count_javacodesize - count_methods * 18);
225         log_text(logtext);
226         sprintf(logtext, "Size of compiled Exception Tables:      %d", count_javaexcsize);
227         log_text(logtext);
228         sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
229         log_text(logtext);
230         sprintf(logtext, "Number of Spills: %d", count_spills);
231         log_text(logtext);
232         sprintf(logtext, "Number of Activ    Pseudocommands: %5d", count_pcmd_activ);
233         log_text(logtext);
234         sprintf(logtext, "Number of Drop     Pseudocommands: %5d", count_pcmd_drop);
235         log_text(logtext);
236         sprintf(logtext, "Number of Const    Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
237         log_text(logtext);
238         sprintf(logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
239         log_text(logtext);
240         sprintf(logtext, "Number of Move     Pseudocommands: %5d", count_pcmd_move);
241         log_text(logtext);
242         sprintf(logtext, "Number of Load     Pseudocommands: %5d", count_load_instruction);
243         log_text(logtext);
244         sprintf(logtext, "Number of Store    Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
245         log_text(logtext);
246         sprintf(logtext, "Number of OP       Pseudocommands: %5d", count_pcmd_op);
247         log_text(logtext);
248         sprintf(logtext, "Number of DUP      Pseudocommands: %5d", count_dup_instruction);
249         log_text(logtext);
250         sprintf(logtext, "Number of Mem      Pseudocommands: %5d", count_pcmd_mem);
251         log_text(logtext);
252         sprintf(logtext, "Number of Method   Pseudocommands: %5d", count_pcmd_met);
253         log_text(logtext);
254         sprintf(logtext, "Number of Branch   Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
255                         count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
256         log_text(logtext);
257         sprintf(logtext, "Number of Table    Pseudocommands: %5d", count_pcmd_table);
258         log_text(logtext);
259         sprintf(logtext, "Number of Useful   Pseudocommands: %5d", count_pcmd_table +
260                         count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
261         log_text(logtext);
262         sprintf(logtext, "Number of Null Pointer Checks:     %5d", count_check_null);
263         log_text(logtext);
264         sprintf(logtext, "Number of Array Bound Checks:      %5d", count_check_bound);
265         log_text(logtext);
266         sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
267         log_text(logtext);
268         sprintf(logtext, "Maximal count of stack elements:   %d", count_max_new_stack);
269         log_text(logtext);
270         sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
271         log_text(logtext);
272         sprintf(logtext, "Distribution of stack sizes at block boundary");
273         log_text(logtext);
274         sprintf(logtext, "    0    1    2    3    4    5    6    7    8    9    >=10");
275         log_text(logtext);
276         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_block_stack[0],
277                         count_block_stack[1], count_block_stack[2], count_block_stack[3], count_block_stack[4],
278                         count_block_stack[5], count_block_stack[6], count_block_stack[7], count_block_stack[8],
279                         count_block_stack[9], count_block_stack[10]);
280         log_text(logtext);
281         sprintf(logtext, "Distribution of store stack depth");
282         log_text(logtext);
283         sprintf(logtext, "    0    1    2    3    4    5    6    7    8    9    >=10");
284         log_text(logtext);
285         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_depth[0],
286                         count_store_depth[1], count_store_depth[2], count_store_depth[3], count_store_depth[4],
287                         count_store_depth[5], count_store_depth[6], count_store_depth[7], count_store_depth[8],
288                         count_store_depth[9], count_store_depth[10]);
289         log_text(logtext);
290         sprintf(logtext, "Distribution of store creator chains first part");
291         log_text(logtext);
292         sprintf(logtext, "    0    1    2    3    4    5    6    7    8    9  ");
293         log_text(logtext);
294         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[0],
295                         count_store_length[1], count_store_length[2], count_store_length[3], count_store_length[4],
296                         count_store_length[5], count_store_length[6], count_store_length[7], count_store_length[8],
297                         count_store_length[9]);
298         log_text(logtext);
299         sprintf(logtext, "Distribution of store creator chains second part");
300         log_text(logtext);
301         sprintf(logtext, "   10   11   12   13   14   15   16   17   18   19  >=20");
302         log_text(logtext);
303         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[10],
304                         count_store_length[11], count_store_length[12], count_store_length[13], count_store_length[14],
305                         count_store_length[15], count_store_length[16], count_store_length[17], count_store_length[18],
306                         count_store_length[19], count_store_length[20]);
307         log_text(logtext);
308         sprintf(logtext, "Distribution of analysis iterations");
309         log_text(logtext);
310         sprintf(logtext, "    1    2    3    4    >=5");
311         log_text(logtext);
312         sprintf(logtext, "%5d%5d%5d%5d%5d", count_analyse_iterations[0], count_analyse_iterations[1],
313                         count_analyse_iterations[2], count_analyse_iterations[3], count_analyse_iterations[4]);
314         log_text(logtext);
315         sprintf(logtext, "Distribution of basic blocks per method");
316         log_text(logtext);
317         sprintf(logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75  >75");
318         log_text(logtext);
319         sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_method_bb_distribution[0],
320                         count_method_bb_distribution[1], count_method_bb_distribution[2], count_method_bb_distribution[3],
321                         count_method_bb_distribution[4], count_method_bb_distribution[5], count_method_bb_distribution[6],
322                         count_method_bb_distribution[7], count_method_bb_distribution[8]);
323         log_text(logtext);
324         sprintf(logtext, "Distribution of basic block sizes");
325         log_text(logtext);
326         sprintf(logtext,
327                          "  0    1    2    3    4   5   6   7   8   9 <13 <15 <17 <19 <21 <26 <31 >30");
328         log_text(logtext);
329         sprintf(logtext, "%3d%5d%5d%5d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d",
330                         count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
331                         count_block_size_distribution[3], count_block_size_distribution[4], count_block_size_distribution[5],
332                         count_block_size_distribution[6], count_block_size_distribution[7], count_block_size_distribution[8],
333                         count_block_size_distribution[9], count_block_size_distribution[10], count_block_size_distribution[11],
334                         count_block_size_distribution[12], count_block_size_distribution[13], count_block_size_distribution[14],
335                         count_block_size_distribution[15], count_block_size_distribution[16], count_block_size_distribution[17]);
336         log_text(logtext);
337         sprintf(logtext, "Size of Code Area (Kb):  %10.3f", (float) count_code_len / 1024);
338         log_text(logtext);
339         sprintf(logtext, "Size of data Area (Kb):  %10.3f", (float) count_data_len / 1024);
340         log_text(logtext);
341         sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
342         log_text(logtext);
343         sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
344         log_text(logtext);
345         sprintf(logtext, "Size of Vftbl (Kb):      %10.3f", (float) count_vftbl_len / 1024);
346         log_text(logtext);
347         sprintf(logtext, "Size of comp stub (Kb):  %10.3f", (float) count_cstub_len / 1024);
348         log_text(logtext);
349         sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
350         log_text(logtext);
351         sprintf(logtext, "Size of Utf (Kb):        %10.3f", (float) count_utf_len / 1024);
352         log_text(logtext);
353         sprintf(logtext, "Size of VMCode (Kb):     %10.3f(%d)", (float) count_vmcode_len / 1024,
354                         count_vmcode_len - 18 * count_all_methods);
355         log_text(logtext);
356         sprintf(logtext, "Size of ExTable (Kb):    %10.3f", (float) count_extable_len / 1024);
357         log_text(logtext);
358         sprintf(logtext, "Number of class loads:   %d", count_class_loads);
359         log_text(logtext);
360         sprintf(logtext, "Number of class inits:   %d", count_class_inits);
361         log_text(logtext);
362         sprintf(logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
363         log_text(logtext);
364
365         sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
366         log_text(logtext);
367         sprintf(logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
368         log_text(logtext);
369 }
370
371
372 /*
373  * These are local overrides for various environment variables in Emacs.
374  * Please do not remove this and leave it at the end of the file, where
375  * Emacs will automagically detect them.
376  * ---------------------------------------------------------------------
377  * Local variables:
378  * mode: c
379  * indent-tabs-mode: t
380  * c-basic-offset: 4
381  * tab-width: 4
382  * End:
383  */