* src/vm/cycles-stats.c (cycles_stats_print): Made count, floor, and ceiling
[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 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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id$
32
33 */
34
35 #ifndef _CYCLES_STATS_H
36 #define _CYCLES_STATS_H
37
38 #include "config.h"
39 #include "vm/types.h"
40
41 #if defined(ENABLE_CYCLES_STATS)
42
43 #include <stdio.h>
44
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##_max = 0;                                \
51     static u8 cycles_stats_##name##_min = 1000000000;
52
53 #define CYCLES_STATS_GET(var)                                               \
54         (var) = asm_get_cycle_count()                                           \
55
56 #define CYCLES_STATS_COUNT(name,cyclesexpr)                                 \
57     do {                                                                    \
58         u8 cyc = (cyclesexpr);                                              \
59         if (cyc > cycles_stats_##name##_max)                                \
60             cycles_stats_##name##_max = cyc;                                \
61         if (cyc < cycles_stats_##name##_min)                                \
62             cycles_stats_##name##_min = cyc;                                \
63         cyc /= CYCLES_STATS_##name##_DIV;                                   \
64         if (cyc < CYCLES_STATS_##name##_MAX)                                \
65             cycles_stats_##name##_bins[cyc]++;                              \
66         else                                                                \
67             cycles_stats_##name##_bins[CYCLES_STATS_##name##_MAX]++;        \
68         cycles_stats_##name##_count++;                                      \
69     } while (0)
70
71 #define CYCLES_STATS_PRINT(name,file)                                       \
72     do {                                                                    \
73         cycles_stats_print((file), #name,                                   \
74             CYCLES_STATS_##name##_MAX, CYCLES_STATS_##name##_DIV,           \
75             cycles_stats_##name##_bins, cycles_stats_##name##_count,        \
76             cycles_stats_##name##_min, cycles_stats_##name##_max);          \
77     } while (0)
78
79 void cycles_stats_print(FILE *file,
80                                             const char *name, int nbins, int div,
81                                             u4 *bins, u8 count, u8 min, u8 max);
82
83
84 #else /* !defined(ENABLE_CYCLES_STATS) */
85
86 #define CYCLES_STATS_DECLARE(name,nbins,divisor)
87 #define CYCLES_STATS_GET(var)
88 #define CYCLES_STATS_COUNT(name,cyclesexpr)
89 #define CYCLES_STATS_PRINT(name,file)
90
91 #endif /* defined(ENABLE_CYCLES_STATS) */
92
93 #endif /* _CYCLES_STATS_H */
94
95 /*
96  * These are local overrides for various environment variables in Emacs.
97  * Please do not remove this and leave it at the end of the file, where
98  * Emacs will automagically detect them.
99  * ---------------------------------------------------------------------
100  * Local variables:
101  * mode: c
102  * indent-tabs-mode: t
103  * c-basic-offset: 4
104  * tab-width: 4
105  * End:
106  * vim:noexpandtab:sw=4:ts=4:
107  */