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 1418 2004-10-19 14:11:58Z carolyn $
36 #include <sys/resource.h>
38 #include "statistics.h"
39 #include "toolbox/logging.h"
43 /* global variables */
45 static s8 loadingtime = 0; /* accumulated loading time */
46 static s8 loadingstarttime = 0;
47 static s8 loadingstoptime = 0;
48 static s4 loadingtime_recursion = 0;
50 static s8 compilingtime = 0; /* accumulated compile time */
51 static s8 compilingstarttime = 0;
52 static s8 compilingstoptime = 0;
53 static s4 compilingtime_recursion = 0;
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 */
61 int count_vmcode_len = 0;
62 int count_extable_len = 0;
63 int count_class_loads = 0;
64 int count_class_inits = 0;
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 */
70 int count_jit_calls = 0;
71 int count_methods = 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;
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] = {
113 int *count_block_stack = count_block_stack_init;
114 static int count_analyse_iterations_init[5] = {
117 int *count_analyse_iterations = count_analyse_iterations_init;
118 static int count_method_bb_distribution_init[9] = {
122 int *count_method_bb_distribution = count_method_bb_distribution_init;
123 static int count_block_size_distribution_init[18] = {
129 int *count_block_size_distribution = count_block_size_distribution_init;
130 static int count_store_length_init[21] = {
137 int *count_store_length = count_store_length_init;
138 static int count_store_depth_init[11] = {
143 int *count_store_depth = count_store_depth_init;
146 /* getcputime *********************************** ******************************
148 Returns the used CPU time in microseconds
150 *******************************************************************************/
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;
161 return sec * 1000000 + usec;
165 /* loadingtime_stop ************************************************************
169 *******************************************************************************/
171 void loadingtime_start()
173 loadingtime_recursion++;
175 if (loadingtime_recursion == 1)
176 loadingstarttime = getcputime();
180 /* loadingtime_stop ************************************************************
184 *******************************************************************************/
186 void loadingtime_stop()
188 if (loadingtime_recursion == 1) {
189 loadingstoptime = getcputime();
190 loadingtime += (loadingstoptime - loadingstarttime);
193 loadingtime_recursion--;
197 /* compilingtime_stop **********************************************************
201 *******************************************************************************/
203 void compilingtime_start()
205 compilingtime_recursion++;
207 if (compilingtime_recursion == 1)
208 compilingstarttime = getcputime();
212 /* compilingtime_stop **********************************************************
216 *******************************************************************************/
218 void compilingtime_stop()
220 if (compilingtime_recursion == 1) {
221 compilingstoptime = getcputime();
222 compilingtime += (compilingstoptime - compilingstarttime);
225 compilingtime_recursion--;
229 /* print_times *****************************************************************
231 Prints a summary of CPU time usage.
233 *******************************************************************************/
237 s8 totaltime = getcputime();
238 s8 runtime = totaltime - loadingtime - compilingtime;
239 char logtext[MAXLOGTEXT];
241 #if defined(__I386__) || defined(__POWERPC__)
242 sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
244 sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
246 loadingtime / 1000000, (loadingtime % 1000000) / 1000);
249 #if defined(__I386__) || defined(__POWERPC__)
250 sprintf(logtext, "Time for compiling code: %lld secs, %lld millis",
252 sprintf(logtext, "Time for compiling code: %ld secs, %ld millis",
254 compilingtime / 1000000, (compilingtime % 1000000) / 1000);
257 #if defined(__I386__) || defined(__POWERPC__)
258 sprintf(logtext, "Time for running program: %lld secs, %lld millis",
260 sprintf(logtext, "Time for running program: %ld secs, %ld millis",
262 runtime / 1000000, (runtime % 1000000) / 1000);
265 #if defined(__I386__) || defined(__POWERPC__)
266 sprintf(logtext, "Total time: %lld secs, %lld millis",
268 sprintf(logtext, "Total time: %ld secs, %ld millis",
270 totaltime / 1000000, (totaltime % 1000000) / 1000);
275 /* print_stats *****************************************************************
277 outputs detailed compiler statistics
279 *******************************************************************************/
283 char logtext[MAXLOGTEXT];
285 sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
287 sprintf(logtext, "Number of compiled Methods: %d", count_methods);
290 sprintf(logtext, "Number of Methods marked Used: %d", count_methods_marked_used);
293 sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
295 sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
297 sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
299 sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
301 sprintf(logtext, "Size of compiled JavaVM-Instructions: %d(%d)", count_javacodesize,
302 count_javacodesize - count_methods * 18);
304 sprintf(logtext, "Size of compiled Exception Tables: %d", count_javaexcsize);
306 sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
308 sprintf(logtext, "Number of Spills: %d", count_spills);
310 sprintf(logtext, "Number of Activ Pseudocommands: %5d", count_pcmd_activ);
312 sprintf(logtext, "Number of Drop Pseudocommands: %5d", count_pcmd_drop);
314 sprintf(logtext, "Number of Const Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
316 sprintf(logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
318 sprintf(logtext, "Number of Move Pseudocommands: %5d", count_pcmd_move);
320 sprintf(logtext, "Number of Load Pseudocommands: %5d", count_load_instruction);
322 sprintf(logtext, "Number of Store Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
324 sprintf(logtext, "Number of OP Pseudocommands: %5d", count_pcmd_op);
326 sprintf(logtext, "Number of DUP Pseudocommands: %5d", count_dup_instruction);
328 sprintf(logtext, "Number of Mem Pseudocommands: %5d", count_pcmd_mem);
330 sprintf(logtext, "Number of Method Pseudocommands: %5d", count_pcmd_met);
332 sprintf(logtext, "Number of Branch Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
333 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
335 sprintf(logtext, "Number of Table Pseudocommands: %5d", count_pcmd_table);
337 sprintf(logtext, "Number of Useful Pseudocommands: %5d", count_pcmd_table +
338 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
340 sprintf(logtext, "Number of Null Pointer Checks: %5d", count_check_null);
342 sprintf(logtext, "Number of Array Bound Checks: %5d", count_check_bound);
344 sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
346 sprintf(logtext, "Maximal count of stack elements: %d", count_max_new_stack);
348 sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
350 sprintf(logtext, "Distribution of stack sizes at block boundary");
352 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
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]);
359 sprintf(logtext, "Distribution of store stack depth");
361 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
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]);
368 sprintf(logtext, "Distribution of store creator chains first part");
370 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 ");
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]);
377 sprintf(logtext, "Distribution of store creator chains second part");
379 sprintf(logtext, " 10 11 12 13 14 15 16 17 18 19 >=20");
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]);
386 sprintf(logtext, "Distribution of analysis iterations");
388 sprintf(logtext, " 1 2 3 4 >=5");
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]);
393 sprintf(logtext, "Distribution of basic blocks per method");
395 sprintf(logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
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]);
402 sprintf(logtext, "Distribution of basic block sizes");
405 " 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
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]);
415 sprintf(logtext, "Size of Code Area (Kb): %10.3f", (float) count_code_len / 1024);
417 sprintf(logtext, "Size of data Area (Kb): %10.3f", (float) count_data_len / 1024);
419 sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
421 sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
423 sprintf(logtext, "Size of Vftbl (Kb): %10.3f", (float) count_vftbl_len / 1024);
425 sprintf(logtext, "Size of comp stub (Kb): %10.3f", (float) count_cstub_len / 1024);
427 sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
429 sprintf(logtext, "Size of Utf (Kb): %10.3f", (float) count_utf_len / 1024);
431 sprintf(logtext, "Size of VMCode (Kb): %10.3f(%d)", (float) count_vmcode_len / 1024,
432 count_vmcode_len - 18 * count_all_methods);
434 sprintf(logtext, "Size of ExTable (Kb): %10.3f", (float) count_extable_len / 1024);
436 sprintf(logtext, "Number of class loads: %d", count_class_loads);
438 sprintf(logtext, "Number of class inits: %d", count_class_inits);
440 sprintf(logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
443 sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
445 sprintf(logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
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 * ---------------------------------------------------------------------
457 * indent-tabs-mode: t