2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Statistic events.
23 * @author Sebastian Hack
35 #include <libcore/lc_timing.h>
49 static ctx_t ctx_stack[MAX_CTX];
51 static unsigned long time_in_ev = 0;
52 static int ctx_sp = -1;
53 static FILE *file_ev = NULL;
55 static lc_timer_t *timer = NULL;
57 int stat_ev_enabled = 0;
59 #define get_time() lc_timer_elapsed_usec(timer)
61 void stat_ev_ctx_push(const char *key, const char *value)
64 unsigned long start = get_time();
65 ctx_t *ctx = &ctx_stack[ctx_sp + 1];
66 unsigned hash = firm_fnv_hash_str(key);
68 hash = HASH_COMBINE(hash, firm_fnv_hash_str(value));
70 hash = HASH_COMBINE(hash, ctx_stack[ctx_sp].hash);
72 strncpy(ctx->key, key, array_size(ctx->key));
73 strncpy(ctx->value, value, array_size(ctx->key));
77 fprintf(file_ev, "P %10x %30s %30s\n", ctx->hash, key, value);
79 time_in_ev += get_time() - start;
83 void stat_ev_ctx_push_fobj(const char *key, const void *firm_object)
87 ir_snprintf(buf, sizeof(buf), "%+F", firm_object);
88 stat_ev_ctx_push(key, buf);
92 void stat_ev_ctx_pop(void)
96 fprintf(file_ev, "O %10x\n", ctx_stack[ctx_sp].hash);
101 void stat_ev_emit(const char *name, double value)
104 unsigned long start = get_time();
105 unsigned id = ctx_sp >= 0 ? ctx_stack[ctx_sp].hash : 0;
107 fprintf(file_ev, "E %10x %30s %30f %10ld %10ld\n", id, name, value, start, time_in_ev);
108 time_in_ev += get_time() - start;
112 void stat_ev_begin(const char *prefix)
116 snprintf(buf, sizeof(buf), "%s.ev", prefix);
121 file_ev = fopen(buf, "wt");
122 timer = lc_timer_register("stat_ev", "firm stat event timer");
124 lc_timer_start(timer);
127 void stat_ev_end(void)
130 lc_timer_stop(timer);
135 void stat_ev_flush(void)
137 unsigned long start = get_time();
140 time_in_ev += get_time() - start;