2 * Copyright (C) 1995-2008 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
38 #include "stat_timing.h"
47 #define FIRM_HAVE_REGEX
50 #if defined HAVE_LIBZ && defined HAVE_ZLIB_H
51 #define FIRM_HAVE_LIBZ
60 #define mfprintf gzprintf
61 static gzFile* stat_ev_file = NULL;
65 #define mfprintf fprintf
66 static FILE* stat_ev_file = NULL;
68 #endif /* FIRM_HAVE_LIBZ */
70 int stat_ev_enabled = 0;
71 int stat_ev_timer_sp = 0;
72 timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
73 timing_ticks_t stat_ev_timer_start[MAX_TIMER];
74 timing_sched_env_t stat_ev_sched_rt;
75 timing_sched_env_t stat_ev_sched_normal;
77 #ifdef FIRM_HAVE_REGEX
80 static regex_t *filter = NULL;
81 static INLINE int key_matches(const char *key)
86 return regexec(filter, key, 0, NULL, 0) == 0;
90 static char filter[128] = { '\0' };
91 static INLINE int key_matches(const char *key)
95 for (i = 0; filter[i] != '\0'; ++i) {
96 if (key[i] != filter[i])
102 #endif /* FIRM_HAVE_REGEX */
105 void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
107 if (!key_matches(key))
110 mfprintf(stat_ev_file, "%c;%s", ev, key);
116 ir_vsnprintf(buf, sizeof(buf), fmt, args);
118 mfprintf(stat_ev_file, ";%s", buf);
120 mfprintf(stat_ev_file, "\n");
123 void stat_ev_begin(const char *prefix, const char *filt)
127 #ifdef FIRM_HAVE_LIBZ
128 snprintf(buf, sizeof(buf), "%s.ev.gz", prefix);
129 stat_ev_file = gzopen(buf, "wt9");
131 snprintf(buf, sizeof(buf), "%s.ev", prefix);
132 stat_ev_file = fopen(buf, "wt");
135 if (filt && filt[0] != '\0') {
136 #ifdef FIRM_HAVE_REGEX
138 if (regcomp(®ex, filt, REG_EXTENDED) == 0)
141 strncpy(filter, filt, sizeof(filter) - sizeof(filter[0]));
142 #endif /* FIRM_HAVE_REGEX */
145 stat_ev_enabled = stat_ev_file != NULL;
146 timing_sched_get(&stat_ev_sched_normal);
147 timing_sched_prepare_max_prio(&stat_ev_sched_rt);
150 void stat_ev_end(void)
153 #ifdef FIRM_HAVE_LIBZ
154 gzflush(stat_ev_file, 1);
155 gzclose(stat_ev_file);
157 fclose(stat_ev_file);