1 /* src/vm/cycles-stats.h - macros for cycle count statistics
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Edwin Steiner
35 #ifndef _CYCLES_STATS_H
36 #define _CYCLES_STATS_H
41 #if defined(ENABLE_CYCLES_STATS)
45 #define CYCLES_STATS_DECLARE(name,nbins,divisor) \
46 static const int CYCLES_STATS_##name##_MAX = (nbins); \
47 static const int CYCLES_STATS_##name##_DIV = (divisor); \
48 static u4 cycles_stats_##name##_bins[(nbins) + 1] = { 0 }; \
49 static u4 cycles_stats_##name##_count = 0; \
50 static u8 cycles_stats_##name##_total = 0; \
51 static u8 cycles_stats_##name##_max = 0; \
52 static u8 cycles_stats_##name##_min = 1000000000;
54 #define CYCLES_STATS_GET(var) \
55 (var) = asm_get_cycle_count() \
57 #define CYCLES_STATS_COUNT(name,cyclesexpr) \
59 u8 cyc = (cyclesexpr); \
60 cycles_stats_##name##_total += cyc; \
61 if (cyc > cycles_stats_##name##_max) \
62 cycles_stats_##name##_max = cyc; \
63 if (cyc < cycles_stats_##name##_min) \
64 cycles_stats_##name##_min = cyc; \
65 cyc /= CYCLES_STATS_##name##_DIV; \
66 if (cyc < CYCLES_STATS_##name##_MAX) \
67 cycles_stats_##name##_bins[cyc]++; \
69 cycles_stats_##name##_bins[CYCLES_STATS_##name##_MAX]++; \
70 cycles_stats_##name##_count++; \
73 #define CYCLES_STATS_COUNT_OVER(name,ovname,cyclesexpr) \
75 u8 cyc = (cyclesexpr); \
76 if (cyc / CYCLES_STATS_##name##_DIV >= CYCLES_STATS_##name##_MAX) \
77 CYCLES_STATS_COUNT(ovname,cyc); \
80 #define CYCLES_STATS_PRINT(name,file) \
82 cycles_stats_print((file), #name, \
83 CYCLES_STATS_##name##_MAX, CYCLES_STATS_##name##_DIV, \
84 cycles_stats_##name##_bins, cycles_stats_##name##_count, \
85 cycles_stats_##name##_total, \
86 cycles_stats_##name##_min, cycles_stats_##name##_max, 0); \
89 #define CYCLES_STATS_PRINT_OVERHEAD(name,file) \
91 cycles_stats_print((file), #name, \
92 CYCLES_STATS_##name##_MAX, CYCLES_STATS_##name##_DIV, \
93 cycles_stats_##name##_bins, cycles_stats_##name##_count, \
94 cycles_stats_##name##_total, \
95 cycles_stats_##name##_min, cycles_stats_##name##_max, 1); \
98 #define CYCLES_STATS_DECLARE_AND_START \
99 u8 cycles_start = asm_get_cycle_count(); \
102 #define CYCLES_STATS_DECLARE_AND_START_WITH_OVERHEAD \
103 u8 cycles_start = asm_get_cycle_count(); \
104 u8 cycles_overhead = asm_get_cycle_count(); \
107 #define CYCLES_STATS_END(name) \
108 cycles_end = asm_get_cycle_count(); \
109 CYCLES_STATS_COUNT(name, cycles_end - cycles_start);
111 #define CYCLES_STATS_END_WITH_OVERHEAD(name,ovname) \
112 cycles_end = asm_get_cycle_count(); \
113 CYCLES_STATS_COUNT(ovname, cycles_overhead - cycles_start); \
114 CYCLES_STATS_COUNT(name, cycles_end - cycles_overhead);
116 void cycles_stats_print(FILE *file,
117 const char *name, int nbins, int div,
118 u4 *bins, u8 count, u8 total, u8 min, u8 max,
122 #else /* !defined(ENABLE_CYCLES_STATS) */
124 #define CYCLES_STATS_DECLARE(name,nbins,divisor)
125 #define CYCLES_STATS_GET(var)
126 #define CYCLES_STATS_COUNT(name,cyclesexpr)
127 #define CYCLES_STATS_COUNT_OVER(name,ovname,cyclesexpr)
128 #define CYCLES_STATS_PRINT(name,file)
129 #define CYCLES_STATS_PRINT_OVERHEAD(name,file)
130 #define CYCLES_STATS_DECLARE_AND_START
131 #define CYCLES_STATS_DECLARE_AND_START_WITH_OVERHEAD
132 #define CYCLES_STATS_END(name)
133 #define CYCLES_STATS_END_WITH_OVERHEAD(name,ovname)
135 #endif /* defined(ENABLE_CYCLES_STATS) */
137 #endif /* _CYCLES_STATS_H */
140 * These are local overrides for various environment variables in Emacs.
141 * Please do not remove this and leave it at the end of the file, where
142 * Emacs will automagically detect them.
143 * ---------------------------------------------------------------------
146 * indent-tabs-mode: t
150 * vim:noexpandtab:sw=4:ts=4: