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
36 #include "stat_timing.h"
43 #define FIRM_HAVE_REGEX
46 #if defined HAVE_LIBZ && defined HAVE_ZLIB_H
47 #define FIRM_HAVE_LIBZ
56 #define mfprintf gzprintf
57 static gzFile* stat_ev_file = NULL;
61 #define mfprintf fprintf
62 static FILE* stat_ev_file = NULL;
64 #endif /* FIRM_HAVE_LIBZ */
66 int stat_ev_enabled = 0;
67 int stat_ev_timer_sp = 0;
68 timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
69 timing_ticks_t stat_ev_timer_start[MAX_TIMER];
71 #ifdef FIRM_HAVE_REGEX
74 static regex_t *filter = NULL;
75 static inline int key_matches(const char *key)
80 return regexec(filter, key, 0, NULL, 0) == 0;
84 static char filter[128] = { '\0' };
85 static inline int key_matches(const char *key)
89 for (i = 0; filter[i] != '\0'; ++i) {
90 if (key[i] != filter[i])
96 #endif /* FIRM_HAVE_REGEX */
99 void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
101 if (!key_matches(key))
104 mfprintf(stat_ev_file, "%c;%s", ev, key);
110 ir_vsnprintf(buf, sizeof(buf), fmt, args);
112 mfprintf(stat_ev_file, ";%s", buf);
114 mfprintf(stat_ev_file, "\n");
117 void stat_ev_begin(const char *prefix, const char *filt)
121 #ifdef FIRM_HAVE_LIBZ
122 snprintf(buf, sizeof(buf), "%s.ev.gz", prefix);
123 stat_ev_file = gzopen(buf, "wt9");
125 snprintf(buf, sizeof(buf), "%s.ev", prefix);
126 stat_ev_file = fopen(buf, "wt");
129 if (filt && filt[0] != '\0') {
130 #ifdef FIRM_HAVE_REGEX
132 if (regcomp(®ex, filt, REG_EXTENDED) == 0)
135 strncpy(filter, filt, sizeof(filter) - sizeof(filter[0]));
136 #endif /* FIRM_HAVE_REGEX */
139 stat_ev_enabled = stat_ev_file != NULL;
142 void stat_ev_end(void)
145 #ifdef FIRM_HAVE_LIBZ
146 gzflush(stat_ev_file, 1);
147 gzclose(stat_ev_file);
149 fclose(stat_ev_file);