1 /* statistics.c - global varables for statistics
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
29 $Id: statistics.c 1735 2004-12-07 14:33:27Z twisti $
35 #include <sys/resource.h>
37 #include "statistics.h"
38 #include "toolbox/logging.h"
42 /* global variables */
44 static s8 loadingtime = 0; /* accumulated loading time */
45 static s8 loadingstarttime = 0;
46 static s8 loadingstoptime = 0;
47 static s4 loadingtime_recursion = 0;
49 static s8 compilingtime = 0; /* accumulated compile time */
50 static s8 compilingstarttime = 0;
51 static s8 compilingstoptime = 0;
52 static s4 compilingtime_recursion = 0;
58 s4 globalallocateddumpsize = 0;
59 s4 globaluseddumpsize = 0;
61 int count_class_infos = 0; /* variables for measurements */
62 int count_const_pool_len = 0;
63 int count_vftbl_len = 0;
64 int count_all_methods = 0;
65 int count_methods_marked_used = 0; /* RTA */
67 int count_vmcode_len = 0;
68 int count_extable_len = 0;
69 int count_class_loads = 0;
70 int count_class_inits = 0;
72 int count_utf_len = 0; /* size of utf hash */
73 int count_utf_new = 0; /* calls of utf_new */
74 int count_utf_new_found = 0; /* calls of utf_new with fast return */
76 int count_jit_calls = 0;
77 int count_methods = 0;
79 int count_pcmd_activ = 0;
80 int count_pcmd_drop = 0;
81 int count_pcmd_zero = 0;
82 int count_pcmd_const_store = 0;
83 int count_pcmd_const_alu = 0;
84 int count_pcmd_const_bra = 0;
85 int count_pcmd_load = 0;
86 int count_pcmd_move = 0;
87 int count_load_instruction = 0;
88 int count_pcmd_store = 0;
89 int count_pcmd_store_comb = 0;
90 int count_dup_instruction = 0;
91 int count_pcmd_op = 0;
92 int count_pcmd_mem = 0;
93 int count_pcmd_met = 0;
94 int count_pcmd_bra = 0;
95 int count_pcmd_table = 0;
96 int count_pcmd_return = 0;
97 int count_pcmd_returnx = 0;
98 int count_check_null = 0;
99 int count_check_bound = 0;
100 int count_max_basic_blocks = 0;
101 int count_basic_blocks = 0;
102 int count_javainstr = 0;
103 int count_max_javainstr = 0;
104 int count_javacodesize = 0;
105 int count_javaexcsize = 0;
107 int count_tryblocks = 0;
108 int count_code_len = 0;
109 int count_data_len = 0;
110 int count_cstub_len = 0;
111 int count_nstub_len = 0;
112 int count_max_new_stack = 0;
113 int count_upper_bound_new_stack = 0;
114 static int count_block_stack_init[11] = {
119 int *count_block_stack = count_block_stack_init;
120 static int count_analyse_iterations_init[5] = {
123 int *count_analyse_iterations = count_analyse_iterations_init;
124 static int count_method_bb_distribution_init[9] = {
128 int *count_method_bb_distribution = count_method_bb_distribution_init;
129 static int count_block_size_distribution_init[18] = {
135 int *count_block_size_distribution = count_block_size_distribution_init;
136 static int count_store_length_init[21] = {
143 int *count_store_length = count_store_length_init;
144 static int count_store_depth_init[11] = {
149 int *count_store_depth = count_store_depth_init;
152 /* getcputime *********************************** ******************************
154 Returns the used CPU time in microseconds
156 *******************************************************************************/
163 getrusage(RUSAGE_SELF, &ru);
164 sec = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
165 usec = ru.ru_utime.tv_usec + ru.ru_stime.tv_usec;
167 return sec * 1000000 + usec;
171 /* loadingtime_stop ************************************************************
175 *******************************************************************************/
177 void loadingtime_start()
179 loadingtime_recursion++;
181 if (loadingtime_recursion == 1)
182 loadingstarttime = getcputime();
186 /* loadingtime_stop ************************************************************
190 *******************************************************************************/
192 void loadingtime_stop()
194 if (loadingtime_recursion == 1) {
195 loadingstoptime = getcputime();
196 loadingtime += (loadingstoptime - loadingstarttime);
199 loadingtime_recursion--;
203 /* compilingtime_stop **********************************************************
207 *******************************************************************************/
209 void compilingtime_start()
211 compilingtime_recursion++;
213 if (compilingtime_recursion == 1)
214 compilingstarttime = getcputime();
218 /* compilingtime_stop **********************************************************
222 *******************************************************************************/
224 void compilingtime_stop()
226 if (compilingtime_recursion == 1) {
227 compilingstoptime = getcputime();
228 compilingtime += (compilingstoptime - compilingstarttime);
231 compilingtime_recursion--;
235 /* print_times *****************************************************************
237 Prints a summary of CPU time usage.
239 *******************************************************************************/
243 s8 totaltime = getcputime();
244 s8 runtime = totaltime - loadingtime - compilingtime;
245 char logtext[MAXLOGTEXT];
247 #if defined(__I386__) || defined(__POWERPC__)
248 sprintf(logtext, "Time for loading classes: %lld secs, %lld millis",
250 sprintf(logtext, "Time for loading classes: %ld secs, %ld millis",
252 loadingtime / 1000000, (loadingtime % 1000000) / 1000);
255 #if defined(__I386__) || defined(__POWERPC__)
256 sprintf(logtext, "Time for compiling code: %lld secs, %lld millis",
258 sprintf(logtext, "Time for compiling code: %ld secs, %ld millis",
260 compilingtime / 1000000, (compilingtime % 1000000) / 1000);
263 #if defined(__I386__) || defined(__POWERPC__)
264 sprintf(logtext, "Time for running program: %lld secs, %lld millis",
266 sprintf(logtext, "Time for running program: %ld secs, %ld millis",
268 runtime / 1000000, (runtime % 1000000) / 1000);
271 #if defined(__I386__) || defined(__POWERPC__)
272 sprintf(logtext, "Total time: %lld secs, %lld millis",
274 sprintf(logtext, "Total time: %ld secs, %ld millis",
276 totaltime / 1000000, (totaltime % 1000000) / 1000);
281 /* print_stats *****************************************************************
283 outputs detailed compiler statistics
285 *******************************************************************************/
289 char logtext[MAXLOGTEXT];
291 sprintf(logtext, "Number of JitCompiler Calls: %d", count_jit_calls);
293 sprintf(logtext, "Number of compiled Methods: %d", count_methods);
296 sprintf(logtext, "Number of Methods marked Used: %d", count_methods_marked_used);
299 sprintf(logtext, "Number of max basic blocks per method: %d", count_max_basic_blocks);
301 sprintf(logtext, "Number of compiled basic blocks: %d", count_basic_blocks);
303 sprintf(logtext, "Number of max JavaVM-Instructions per method: %d", count_max_javainstr);
305 sprintf(logtext, "Number of compiled JavaVM-Instructions: %d", count_javainstr);
307 sprintf(logtext, "Size of compiled JavaVM-Instructions: %d(%d)", count_javacodesize,
308 count_javacodesize - count_methods * 18);
310 sprintf(logtext, "Size of compiled Exception Tables: %d", count_javaexcsize);
312 sprintf(logtext, "Number of Machine-Instructions: %d", count_code_len >> 2);
314 sprintf(logtext, "Number of Spills: %d", count_spills);
316 sprintf(logtext, "Number of Activ Pseudocommands: %5d", count_pcmd_activ);
318 sprintf(logtext, "Number of Drop Pseudocommands: %5d", count_pcmd_drop);
320 sprintf(logtext, "Number of Const Pseudocommands: %5d (zero:%5d)", count_pcmd_load, count_pcmd_zero);
322 sprintf(logtext, "Number of ConstAlu Pseudocommands: %5d (cmp: %5d, store:%5d)", count_pcmd_const_alu, count_pcmd_const_bra, count_pcmd_const_store);
324 sprintf(logtext, "Number of Move Pseudocommands: %5d", count_pcmd_move);
326 sprintf(logtext, "Number of Load Pseudocommands: %5d", count_load_instruction);
328 sprintf(logtext, "Number of Store Pseudocommands: %5d (combined: %5d)", count_pcmd_store, count_pcmd_store - count_pcmd_store_comb);
330 sprintf(logtext, "Number of OP Pseudocommands: %5d", count_pcmd_op);
332 sprintf(logtext, "Number of DUP Pseudocommands: %5d", count_dup_instruction);
334 sprintf(logtext, "Number of Mem Pseudocommands: %5d", count_pcmd_mem);
336 sprintf(logtext, "Number of Method Pseudocommands: %5d", count_pcmd_met);
338 sprintf(logtext, "Number of Branch Pseudocommands: %5d (rets:%5d, Xrets: %5d)",
339 count_pcmd_bra, count_pcmd_return, count_pcmd_returnx);
341 sprintf(logtext, "Number of Table Pseudocommands: %5d", count_pcmd_table);
343 sprintf(logtext, "Number of Useful Pseudocommands: %5d", count_pcmd_table +
344 count_pcmd_bra + count_pcmd_load + count_pcmd_mem + count_pcmd_op);
346 sprintf(logtext, "Number of Null Pointer Checks: %5d", count_check_null);
348 sprintf(logtext, "Number of Array Bound Checks: %5d", count_check_bound);
350 sprintf(logtext, "Number of Try-Blocks: %d", count_tryblocks);
352 sprintf(logtext, "Maximal count of stack elements: %d", count_max_new_stack);
354 sprintf(logtext, "Upper bound of max stack elements: %d", count_upper_bound_new_stack);
356 sprintf(logtext, "Distribution of stack sizes at block boundary");
358 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
360 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_block_stack[0],
361 count_block_stack[1], count_block_stack[2], count_block_stack[3], count_block_stack[4],
362 count_block_stack[5], count_block_stack[6], count_block_stack[7], count_block_stack[8],
363 count_block_stack[9], count_block_stack[10]);
365 sprintf(logtext, "Distribution of store stack depth");
367 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 >=10");
369 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_depth[0],
370 count_store_depth[1], count_store_depth[2], count_store_depth[3], count_store_depth[4],
371 count_store_depth[5], count_store_depth[6], count_store_depth[7], count_store_depth[8],
372 count_store_depth[9], count_store_depth[10]);
374 sprintf(logtext, "Distribution of store creator chains first part");
376 sprintf(logtext, " 0 1 2 3 4 5 6 7 8 9 ");
378 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[0],
379 count_store_length[1], count_store_length[2], count_store_length[3], count_store_length[4],
380 count_store_length[5], count_store_length[6], count_store_length[7], count_store_length[8],
381 count_store_length[9]);
383 sprintf(logtext, "Distribution of store creator chains second part");
385 sprintf(logtext, " 10 11 12 13 14 15 16 17 18 19 >=20");
387 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_store_length[10],
388 count_store_length[11], count_store_length[12], count_store_length[13], count_store_length[14],
389 count_store_length[15], count_store_length[16], count_store_length[17], count_store_length[18],
390 count_store_length[19], count_store_length[20]);
392 sprintf(logtext, "Distribution of analysis iterations");
394 sprintf(logtext, " 1 2 3 4 >=5");
396 sprintf(logtext, "%5d%5d%5d%5d%5d", count_analyse_iterations[0], count_analyse_iterations[1],
397 count_analyse_iterations[2], count_analyse_iterations[3], count_analyse_iterations[4]);
399 sprintf(logtext, "Distribution of basic blocks per method");
401 sprintf(logtext, " <= 5 <=10 <=15 <=20 <=30 <=40 <=50 <=75 >75");
403 sprintf(logtext, "%5d%5d%5d%5d%5d%5d%5d%5d%5d", count_method_bb_distribution[0],
404 count_method_bb_distribution[1], count_method_bb_distribution[2], count_method_bb_distribution[3],
405 count_method_bb_distribution[4], count_method_bb_distribution[5], count_method_bb_distribution[6],
406 count_method_bb_distribution[7], count_method_bb_distribution[8]);
408 sprintf(logtext, "Distribution of basic block sizes");
411 " 0 1 2 3 4 5 6 7 8 9 <13 <15 <17 <19 <21 <26 <31 >30");
413 sprintf(logtext, "%3d%5d%5d%5d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d%4d",
414 count_block_size_distribution[0], count_block_size_distribution[1], count_block_size_distribution[2],
415 count_block_size_distribution[3], count_block_size_distribution[4], count_block_size_distribution[5],
416 count_block_size_distribution[6], count_block_size_distribution[7], count_block_size_distribution[8],
417 count_block_size_distribution[9], count_block_size_distribution[10], count_block_size_distribution[11],
418 count_block_size_distribution[12], count_block_size_distribution[13], count_block_size_distribution[14],
419 count_block_size_distribution[15], count_block_size_distribution[16], count_block_size_distribution[17]);
421 sprintf(logtext, "Size of Code Area (Kb): %10.3f", (float) count_code_len / 1024);
423 sprintf(logtext, "Size of data Area (Kb): %10.3f", (float) count_data_len / 1024);
425 sprintf(logtext, "Size of Class Infos (Kb):%10.3f", (float) (count_class_infos) / 1024);
427 sprintf(logtext, "Size of Const Pool (Kb): %10.3f", (float) (count_const_pool_len + count_utf_len) / 1024);
429 sprintf(logtext, "Size of Vftbl (Kb): %10.3f", (float) count_vftbl_len / 1024);
431 sprintf(logtext, "Size of comp stub (Kb): %10.3f", (float) count_cstub_len / 1024);
433 sprintf(logtext, "Size of native stub (Kb):%10.3f", (float) count_nstub_len / 1024);
435 sprintf(logtext, "Size of Utf (Kb): %10.3f", (float) count_utf_len / 1024);
437 sprintf(logtext, "Size of VMCode (Kb): %10.3f(%d)", (float) count_vmcode_len / 1024,
438 count_vmcode_len - 18 * count_all_methods);
440 sprintf(logtext, "Size of ExTable (Kb): %10.3f", (float) count_extable_len / 1024);
442 sprintf(logtext, "Number of class loads: %d", count_class_loads);
444 sprintf(logtext, "Number of class inits: %d", count_class_inits);
446 sprintf(logtext, "Number of loaded Methods: %d\n\n", count_all_methods);
449 sprintf(logtext, "Calls of utf_new: %22d", count_utf_new);
451 sprintf(logtext, "Calls of utf_new (element found): %6d\n\n", count_utf_new_found);
456 /* mem_usagelog ****************************************************************
458 prints some memory related infos
460 *******************************************************************************/
462 void mem_usagelog(bool givewarnings)
464 if ((memoryusage != 0) && givewarnings) {
465 dolog("Allocated memory not returned: %d", (s4) memoryusage);
468 if ((globalallocateddumpsize != 0) && givewarnings) {
469 dolog("Dump memory not returned: %d", (s4) globalallocateddumpsize);
472 dolog("Random/Dump - max. memory usage: %dkB/%dkB",
473 (s4) ((maxmemusage + 1023) / 1024),
474 (s4) ((maxdumpsize + 1023) / 1024));
479 * These are local overrides for various environment variables in Emacs.
480 * Please do not remove this and leave it at the end of the file, where
481 * Emacs will automagically detect them.
482 * ---------------------------------------------------------------------
485 * indent-tabs-mode: t