1 /* src/vm/cycles-stats.h - macros for cycle count statistics
3 Copyright (C) 1996-2005, 2006, 2009
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #ifndef _CYCLES_STATS_H
26 #define _CYCLES_STATS_H
31 #if defined(ENABLE_CYCLES_STATS)
37 #define CYCLES_STATS_DECLARE(name,nbins,divisor) \
38 static const int CYCLES_STATS_##name##_MAX = (nbins); \
39 static const int CYCLES_STATS_##name##_DIV = (divisor); \
40 static u4 cycles_stats_##name##_bins[(nbins) + 1] = { 0 }; \
41 static u4 cycles_stats_##name##_count = 0; \
42 static u8 cycles_stats_##name##_total = 0; \
43 static u8 cycles_stats_##name##_max = 0; \
44 static u8 cycles_stats_##name##_min = 1000000000;
46 #define CYCLES_STATS_GET(var) \
47 (var) = md_get_cycle_count() \
49 #define CYCLES_STATS_COUNT(name,cyclesexpr) \
51 u8 cyc = (cyclesexpr); \
52 cycles_stats_##name##_total += cyc; \
53 if (cyc > cycles_stats_##name##_max) \
54 cycles_stats_##name##_max = cyc; \
55 if (cyc < cycles_stats_##name##_min) \
56 cycles_stats_##name##_min = cyc; \
57 cyc /= CYCLES_STATS_##name##_DIV; \
58 if (cyc < CYCLES_STATS_##name##_MAX) \
59 cycles_stats_##name##_bins[cyc]++; \
61 cycles_stats_##name##_bins[CYCLES_STATS_##name##_MAX]++; \
62 cycles_stats_##name##_count++; \
65 #define CYCLES_STATS_COUNT_OVER(name,ovname,cyclesexpr) \
67 u8 cyc = (cyclesexpr); \
68 if (cyc / CYCLES_STATS_##name##_DIV >= CYCLES_STATS_##name##_MAX) \
69 CYCLES_STATS_COUNT(ovname,cyc); \
72 #define CYCLES_STATS_PRINT(name,file) \
74 cycles_stats_print((file), #name, \
75 CYCLES_STATS_##name##_MAX, CYCLES_STATS_##name##_DIV, \
76 cycles_stats_##name##_bins, cycles_stats_##name##_count, \
77 cycles_stats_##name##_total, \
78 cycles_stats_##name##_min, cycles_stats_##name##_max, 0); \
81 #define CYCLES_STATS_PRINT_OVERHEAD(name,file) \
83 cycles_stats_print((file), #name, \
84 CYCLES_STATS_##name##_MAX, CYCLES_STATS_##name##_DIV, \
85 cycles_stats_##name##_bins, cycles_stats_##name##_count, \
86 cycles_stats_##name##_total, \
87 cycles_stats_##name##_min, cycles_stats_##name##_max, 1); \
90 #define CYCLES_STATS_DECLARE_AND_START \
91 u8 cycles_start = md_get_cycle_count(); \
94 #define CYCLES_STATS_DECLARE_AND_START_WITH_OVERHEAD \
95 u8 cycles_start = md_get_cycle_count(); \
96 u8 cycles_overhead = md_get_cycle_count(); \
99 #define CYCLES_STATS_END(name) \
100 cycles_end = md_get_cycle_count(); \
101 CYCLES_STATS_COUNT(name, cycles_end - cycles_start);
103 #define CYCLES_STATS_END_WITH_OVERHEAD(name,ovname) \
104 cycles_end = md_get_cycle_count(); \
105 CYCLES_STATS_COUNT(ovname, cycles_overhead - cycles_start); \
106 CYCLES_STATS_COUNT(name, cycles_end - cycles_overhead);
112 void cycles_stats_print(FILE *file,
113 const char *name, int nbins, int div,
114 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: