1 /* src/vm/cycles-stats.c - functions 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
38 #if defined(ENABLE_CYCLES_STATS)
42 #include "vm/cycles-stats.h"
44 struct cycles_stats_percentile {
49 static struct cycles_stats_percentile cycles_stats_percentile_defs[] = {
50 { 10, "10%-percentile" },
52 { 90, "90%-percentile" },
53 { 99, "99%-percentile" },
54 { 0, NULL } /* sentinel */
57 void cycles_stats_print(FILE *file,
58 const char *name, int nbins, int div,
59 u4 *bins, u8 count, u8 min, u8 max)
62 struct cycles_stats_percentile *pcd;
68 fprintf(file,"\t%s: %u calls\n",
71 fprintf(file,"\t%s cycles distribution:\n", name);
73 fprintf(file,"\t\t%20s = %llu\n", "min", (unsigned long long)min);
75 pcd = cycles_stats_percentile_defs;
76 for (; pcd->name; pcd++) {
77 floor = (count * pcd->pct) / 100;
78 ceiling = (count * pcd->pct + 99) / 100;
83 assert( ceiling <= floor + 1 );
85 for (i=0; i<nbins; ++i) {
87 /* { invariant: `cumul` samples are < `p` } */
89 /* check if percentile lies exactly at the bin boundary */
91 if (floor == cumul && floor == ceiling) {
96 /* check if percentile lies within this bin */
98 if (cumul <= floor && ceiling <= cumul + bins[i]) {
99 percentile = p + (double)div/2.0;
106 /* { invariant: `cumul` samples are < `p` } */
109 /* check if percentile lies exactly at the bin boundary */
111 if (floor == cumul && floor == ceiling) {
115 if (percentile >= 0) {
116 fprintf(file,"\t\t%20s = %.1f\n", pcd->name, percentile);
119 fprintf(file,"\t\t%20s = unknown (> %llu)\n", pcd->name, (unsigned long long)p);
123 fprintf(file,"\t\t%20s = %llu\n", "max", (unsigned long long)max);
126 for (i=0; i<nbins; ++i) {
128 fprintf(file,"\t\t< %5d: %10lu (%3d%%) %10lu\n",
130 (unsigned long) cumul,
131 (int)((cumul * 100) / count),
132 (unsigned long) bins[i]);
135 fprintf(file,"\t\t>= %5d: %10s (----) %10lu\n",
138 (unsigned long) bins[nbins]);
141 #endif /* defined(ENABLE_CYCLES_STATS) */
144 * These are local overrides for various environment variables in Emacs.
145 * Please do not remove this and leave it at the end of the file, where
146 * Emacs will automagically detect them.
147 * ---------------------------------------------------------------------
150 * indent-tabs-mode: t
154 * vim:noexpandtab:sw=4:ts=4: