src/vm/cycles-stats.h: Switched from asm_get_cycle_count to md_get_cycle_count.
[cacao.git] / src / vm / cycles-stats.h
1 /* src/vm/cycles-stats.h - macros for cycle count statistics
2
3    Copyright (C) 1996-2005, 2006, 2009
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25 #ifndef _CYCLES_STATS_H
26 #define _CYCLES_STATS_H
27
28 #include "config.h"
29 #include "vm/types.h"
30
31 #if defined(ENABLE_CYCLES_STATS)
32
33 #include <stdio.h>
34
35 #include "md.h"
36
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;
45
46 #define CYCLES_STATS_GET(var)                                               \
47         (var) = md_get_cycle_count()                                            \
48
49 #define CYCLES_STATS_COUNT(name,cyclesexpr)                                 \
50     do {                                                                    \
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]++;                              \
60         else                                                                \
61             cycles_stats_##name##_bins[CYCLES_STATS_##name##_MAX]++;        \
62         cycles_stats_##name##_count++;                                      \
63     } while (0)
64
65 #define CYCLES_STATS_COUNT_OVER(name,ovname,cyclesexpr)                     \
66     do {                                                                    \
67         u8 cyc = (cyclesexpr);                                              \
68         if (cyc / CYCLES_STATS_##name##_DIV >= CYCLES_STATS_##name##_MAX)   \
69             CYCLES_STATS_COUNT(ovname,cyc);                                 \
70     } while (0)
71
72 #define CYCLES_STATS_PRINT(name,file)                                       \
73     do {                                                                    \
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);       \
79     } while (0)
80
81 #define CYCLES_STATS_PRINT_OVERHEAD(name,file)                              \
82     do {                                                                    \
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);       \
88     } while (0)
89
90 #define CYCLES_STATS_DECLARE_AND_START                                      \
91     u8 cycles_start = md_get_cycle_count();                                 \
92     u8 cycles_end;
93
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();                              \
97     u8 cycles_end;
98
99 #define CYCLES_STATS_END(name)                                              \
100     cycles_end = md_get_cycle_count();                                      \
101     CYCLES_STATS_COUNT(name, cycles_end - cycles_start);
102
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);
107
108 #ifdef __cplusplus
109 extern "C" {
110 #endif
111
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,
115                                                 int overhead);
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121
122 #else /* !defined(ENABLE_CYCLES_STATS) */
123
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)
134
135 #endif /* defined(ENABLE_CYCLES_STATS) */
136
137 #endif /* _CYCLES_STATS_H */
138
139 /*
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  * ---------------------------------------------------------------------
144  * Local variables:
145  * mode: c
146  * indent-tabs-mode: t
147  * c-basic-offset: 4
148  * tab-width: 4
149  * End:
150  * vim:noexpandtab:sw=4:ts=4:
151  */