X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fstat%2Fstatev.c;h=b095392ddadacfb212be893a9968fdf18ed34926;hb=e997eedfb605aa149004122d63c7c54a8e384132;hp=3d61face24e8a12c73e4f5076c4958c5521cb9ec;hpb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;p=libfirm diff --git a/ir/stat/statev.c b/ir/stat/statev.c index 3d61face2..b095392dd 100644 --- a/ir/stat/statev.c +++ b/ir/stat/statev.c @@ -1,20 +1,6 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** @@ -22,7 +8,6 @@ * @brief Statistic events. * @author Sebastian Hack * @date 17.06.2007 - * @version $Id$ */ #include "config.h" @@ -31,48 +16,25 @@ #include #include #include +#include #include "util.h" #include "stat_timing.h" #include "irprintf.h" -#include "statev.h" +#include "statev_t.h" #include "config.h" -#if defined(FIRM_STATISTICS) && !defined(DISABLE_STATEV) - -#ifdef HAVE_REGEX_H -#define FIRM_HAVE_REGEX -#endif - -#if defined HAVE_LIBZ && defined HAVE_ZLIB_H -#define FIRM_HAVE_LIBZ -#endif - - #define MAX_TIMER 256 -#ifdef FIRM_HAVE_LIBZ -#include - -#define mfprintf gzprintf -static gzFile stat_ev_file = NULL; - -#else - -#define mfprintf fprintf -static FILE* stat_ev_file = NULL; - -#endif /* FIRM_HAVE_LIBZ */ +int (stat_ev_enabled) = 0; -int stat_ev_enabled = 0; -int stat_ev_timer_sp = 0; -timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER]; -timing_ticks_t stat_ev_timer_start[MAX_TIMER]; +static FILE *stat_ev_file = NULL; +static int stat_ev_timer_sp = 0; +static timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER]; +static timing_ticks_t stat_ev_timer_start[MAX_TIMER]; -#ifdef FIRM_HAVE_REGEX -#include -static regex_t regex; +static regex_t regex; static regex_t *filter = NULL; static inline int key_matches(const char *key) { @@ -82,60 +44,155 @@ static inline int key_matches(const char *key) return regexec(filter, key, 0, NULL, 0) == 0; } -#else -static char filter[128] = { '\0' }; -static inline int key_matches(const char *key) +static void stat_ev_vprintf(char ev, const char *key, const char *fmt, va_list ap) { - int i = 0; + if (!key_matches(key)) + return; - for (i = 0; filter[i] != '\0'; ++i) { - if (key[i] != filter[i]) - return 0; + fprintf(stat_ev_file, "%c;%s", ev, key); + if (fmt != NULL) { + char buf[256]; + + ir_vsnprintf(buf, sizeof(buf), fmt, ap); + fprintf(stat_ev_file, ";%s", buf); } + fprintf(stat_ev_file, "\n"); +} - return 1; +static void stat_ev_printf(char ev, const char *key, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + stat_ev_vprintf(ev, key, fmt, ap); + va_end(ap); } -#endif /* FIRM_HAVE_REGEX */ +void stat_ev_tim_push(void) +{ + timing_ticks_t temp; + int sp = stat_ev_timer_sp++; + timing_ticks(temp); + if (sp == 0) { + timing_enter_max_prio(); + } else { + timing_ticks_sub(temp, stat_ev_timer_start[sp - 1]); + timing_ticks_add(stat_ev_timer_elapsed[sp - 1], temp); + } + timing_ticks_init(stat_ev_timer_elapsed[sp]); + timing_ticks(stat_ev_timer_start[sp]); +} -void stat_ev_printf(char ev, const char *key, const char *fmt, ...) +void stat_ev_tim_pop(const char *name) { - if (!key_matches(key)) + int sp; + timing_ticks_t temp; + timing_ticks(temp); + sp = --stat_ev_timer_sp; + timing_ticks_sub(temp, stat_ev_timer_start[sp]); + timing_ticks_add(stat_ev_timer_elapsed[sp], temp); + if (name != NULL && stat_ev_enabled) + stat_ev_printf('E', name, "%g", timing_ticks_dbl(stat_ev_timer_elapsed[sp])); + if (sp == 0) { + timing_leave_max_prio(); + } else { + timing_ticks(stat_ev_timer_start[sp - 1]); + } +} + +void do_stat_ev_ctx_push_vfmt(const char *key, const char *fmt, va_list ap) +{ + stat_ev_tim_push(); + stat_ev_vprintf('P', key, fmt, ap); + stat_ev_tim_pop(NULL); +} + +void (stat_ev_ctx_push_fmt)(const char *key, const char *fmt, ...) +{ + if (!stat_ev_enabled) return; - mfprintf(stat_ev_file, "%c;%s", ev, key); - if (fmt != NULL) { - char buf[256]; - va_list args; + va_list ap; + va_start(ap, fmt); + do_stat_ev_ctx_push_vfmt(key, fmt, ap); + va_end(ap); +} - va_start(args, fmt); - ir_vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - mfprintf(stat_ev_file, ";%s", buf); - } - mfprintf(stat_ev_file, "\n"); +void (stat_ev_ctx_push_str)(const char *key, const char *str) +{ + stat_ev_ctx_push_str_(key, str); +} + +void do_stat_ev_ctx_pop(const char *key) +{ + stat_ev_tim_push(); + stat_ev_printf('O', key, NULL); + stat_ev_tim_pop(NULL); +} + +void (stat_ev_ctx_pop)(const char *key) +{ + stat_ev_ctx_pop_(key); +} + +void do_stat_ev_dbl(const char *name, double value) +{ + stat_ev_tim_push(); + stat_ev_printf('E', name, "%g", value); + stat_ev_tim_pop(NULL); +} + +void (stat_ev_dbl)(const char *name, double value) +{ + stat_ev_dbl_(name, value); +} + +void do_stat_ev_int(const char *name, int value) +{ + stat_ev_tim_push(); + stat_ev_printf('E', name, "%d", value); + stat_ev_tim_pop(NULL); +} + +void (stat_ev_int)(const char *name, int value) +{ + stat_ev_int_(name, value); +} + +void do_stat_ev_ull(const char *name, unsigned long long value) +{ + stat_ev_tim_push(); + stat_ev_printf('E', name, "%llu", value); + stat_ev_tim_pop(NULL); +} + +void (stat_ev_ull)(const char *name, unsigned long long value) +{ + stat_ev_ull_(name, value); +} + +void do_stat_ev(const char *name) +{ + stat_ev_tim_push(); + stat_ev_printf('E', name, "0.0"); + stat_ev_tim_pop(NULL); +} + +void (stat_ev)(const char *name) +{ + stat_ev_(name); } void stat_ev_begin(const char *prefix, const char *filt) { char buf[512]; -#ifdef FIRM_HAVE_LIBZ - snprintf(buf, sizeof(buf), "%s.ev.gz", prefix); - stat_ev_file = gzopen(buf, "wt9"); -#else snprintf(buf, sizeof(buf), "%s.ev", prefix); stat_ev_file = fopen(buf, "wt"); -#endif if (filt && filt[0] != '\0') { -#ifdef FIRM_HAVE_REGEX filter = NULL; if (regcomp(®ex, filt, REG_EXTENDED) == 0) filter = ®ex; -#else - strncpy(filter, filt, sizeof(filter) - sizeof(filter[0])); -#endif /* FIRM_HAVE_REGEX */ } stat_ev_enabled = stat_ev_file != NULL; @@ -144,13 +201,8 @@ void stat_ev_begin(const char *prefix, const char *filt) void stat_ev_end(void) { if (stat_ev_file) { -#ifdef FIRM_HAVE_LIBZ - gzflush(stat_ev_file, 1); - gzclose(stat_ev_file); -#else fclose(stat_ev_file); -#endif } + if (filter != NULL) + regfree(filter); } - -#endif