1 /* statistics.c - global varables for statistics
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,
9 This file is part of CACAO.
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.
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.
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
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Christian Thalinger
30 $Id: statistics.c 1224 2004-06-30 19:13:37Z twisti $
36 #include <sys/resource.h>
38 #include "statistics.h"
39 #include "toolbox/logging.h"
42 /* global variables */
45 s8 compilingtime = 0; /* accumulated compile time */
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;
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 */
60 int count_jit_calls = 0;
61 int count_methods = 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;
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] = {
103 int *count_block_stack = count_block_stack_init;
104 static int count_analyse_iterations_init[5] = {
107 int *count_analyse_iterations = count_analyse_iterations_init;
108 static int count_method_bb_distribution_init[9] = {
112 int *count_method_bb_distribution = count_method_bb_distribution_init;
113 static int count_block_size_distribution_init[18] = {
119 int *count_block_size_distribution = count_block_size_distribution_init;
120 static int count_store_length_init[21] = {
127 int *count_store_length = count_store_length_init;
128 static int count_store_depth_init[11] = {
133 int *count_store_depth = count_store_depth_init;
136 /* getcputime *********************************** ******************************
138 Returns the used CPU time in microseconds
140 *******************************************************************************/
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;
151 return sec * 1000000 + usec;
155 /* print_times *****************************************************************
157 Prints a summary of CPU time usage.
159 *******************************************************************************/
163 s8 totaltime = getcputime();
164 s8 runtime = totaltime - loadingtime - compilingtime;
165 char logtext[MAXLOGTEXT];
167 #if defined(__I386__) || defined(__POWERPC__)
168 sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
170 sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
172 loadingtime / 1000000, (loadingtime % 1000000) / 1000);
175 #if defined(__I386__) || defined(__POWERPC__)
176 sprintf(logtext, "Time for compiling code: %lld secs, %lld millis",
178 sprintf(logtext, "Time for compiling code: %ld secs, %ld millis",
180 compilingtime / 1000000, (compilingtime % 1000000) / 1000);
183 #if defined(__I386__) || defined(__POWERPC__)
184 sprintf(logtext, "Time for running program: %lld secs, %lld millis",
186 sprintf(logtext, "Time for running program: %ld secs, %ld millis",
188 runtime / 1000000, (runtime % 1000000) / 1000);
191 #if defined(__I386__) || defined(__POWERPC__)
192 sprintf(logtext, "Total time: %lld secs, %lld millis",
194 sprintf(logtext, "Total time: %ld secs, %ld millis",
196 totaltime / 1000000, (totaltime % 1000000) / 1000);
201 /* print_stats *****************************************************************
203 outputs detailed compiler statistics
205 *******************************************************************************/
209 char logtext[MAXLOGTEXT];
211 sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
213 sprintf(logtext, "Number of compiled Methods: %d", count_methods);
215 sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
217 sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
219 sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
221 sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
223 sprintf(logtext, "Size of compiled JavaVM-Instructions: %d(%d)", count_javacodesize,
224 count_javacodesize - count_methods * 18);
226 sprintf(logtext, "Size of compiled Exception Tables: %d", count_javaexcsize);
228 sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
230 sprintf(logtext, "Number of Spills: %d", count_spills);
232 sprintf(logtext, "Number of Activ Pseudocommands: %5d", count_pcmd_activ);
234 sprintf(logtext, "Number of Drop Pseudocommands: %5d", count_pcmd_drop);
236 sprintf(logtext, "Number of Const Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
238 sprintf(logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
240 sprintf(logtext, "Number of Move Pseudocommands: %5d", count_pcmd_move);
242 sprintf(logtext, "Number of Load Pseudocommands: %5d", count_load_instruction);
244 sprintf(logtext, "Number of Store Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
246 sprintf(logtext, "Number of OP Pseudocommands: %5d", count_pcmd_op);
248 sprintf(logtext, "Number of DUP Pseudocommands: %5d", count_dup_instruction);
250 sprintf(logtext, "Number of Mem Pseudocommands: %5d", count_pcmd_mem);
252 sprintf(logtext, "Number of Method Pseudocommands: %5d", count_pcmd_met);
254 sprintf(logtext, "Number of Branch Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
255 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
257 sprintf(logtext, "Number of Table Pseudocommands: %5d", count_pcmd_table);
259 sprintf(logtext, "Number of Useful Pseudocommands: %5d", count_pcmd_table +
260 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
262 sprintf(logtext, "Number of Null Pointer Checks: %5d", count_check_null);
264 sprintf(logtext, "Number of Array Bound Checks: %5d", count_check_bound);
266 sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
268 sprintf(logtext, "Maximal count of stack elements: %d", count_max_new_stack);
270 sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
272 sprintf(logtext, "Distribution of stack sizes at block boundary");
274 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
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]);
281 sprintf(logtext, "Distribution of store stack depth");
283 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
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]);
290 sprintf(logtext, "Distribution of store creator chains first part");
292 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 ");
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]);
299 sprintf(logtext, "Distribution of store creator chains second part");
301 sprintf(logtext, " 10 11 12 13 14 15 16 17 18 19 >=20");
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]);
308 sprintf(logtext, "Distribution of analysis iterations");
310 sprintf(logtext, " 1 2 3 4 >=5");
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]);
315 sprintf(logtext, "Distribution of basic blocks per method");
317 sprintf(logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
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]);
324 sprintf(logtext, "Distribution of basic block sizes");
327 " 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
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]);
337 sprintf(logtext, "Size of Code Area (Kb): %10.3f", (float) count_code_len / 1024);
339 sprintf(logtext, "Size of data Area (Kb): %10.3f", (float) count_data_len / 1024);
341 sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
343 sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
345 sprintf(logtext, "Size of Vftbl (Kb): %10.3f", (float) count_vftbl_len / 1024);
347 sprintf(logtext, "Size of comp stub (Kb): %10.3f", (float) count_cstub_len / 1024);
349 sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
351 sprintf(logtext, "Size of Utf (Kb): %10.3f", (float) count_utf_len / 1024);
353 sprintf(logtext, "Size of VMCode (Kb): %10.3f(%d)", (float) count_vmcode_len / 1024,
354 count_vmcode_len - 18 * count_all_methods);
356 sprintf(logtext, "Size of ExTable (Kb): %10.3f", (float) count_extable_len / 1024);
358 sprintf(logtext, "Number of class loads: %d", count_class_loads);
360 sprintf(logtext, "Number of class inits: %d", count_class_inits);
362 sprintf(logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
365 sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
367 sprintf(logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
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 * ---------------------------------------------------------------------
379 * indent-tabs-mode: t