remove extended basic block support
[libfirm] / ir / stat / statev.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Statistic events.
23  * @author      Sebastian Hack
24  * @date        17.06.2007
25  */
26 #include "config.h"
27
28 #include <assert.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <regex.h>
34
35 #include "util.h"
36 #include "stat_timing.h"
37 #include "irprintf.h"
38 #include "statev.h"
39
40 #include "config.h"
41
42 #ifndef DISABLE_STATEV
43
44 #define MAX_TIMER 256
45
46 static FILE* stat_ev_file  = NULL;
47
48 int            stat_ev_enabled = 0;
49 int            stat_ev_timer_sp = 0;
50 timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
51 timing_ticks_t stat_ev_timer_start[MAX_TIMER];
52
53 static regex_t regex;
54 static regex_t *filter = NULL;
55 static inline int key_matches(const char *key)
56 {
57         if (!filter)
58                 return 1;
59
60         return regexec(filter, key, 0, NULL, 0) == 0;
61 }
62
63 void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
64 {
65         if (!key_matches(key))
66                 return;
67
68         fprintf(stat_ev_file, "%c;%s", ev, key);
69         if (fmt != NULL) {
70                 char buf[256];
71                 va_list args;
72
73                 va_start(args, fmt);
74                 ir_vsnprintf(buf, sizeof(buf), fmt, args);
75                 va_end(args);
76                 fprintf(stat_ev_file, ";%s", buf);
77         }
78         fprintf(stat_ev_file, "\n");
79 }
80
81 void stat_ev_begin(const char *prefix, const char *filt)
82 {
83         char buf[512];
84
85         snprintf(buf, sizeof(buf), "%s.ev", prefix);
86         stat_ev_file = fopen(buf, "wt");
87
88         if (filt && filt[0] != '\0') {
89                 filter = NULL;
90                 if (regcomp(&regex, filt, REG_EXTENDED) == 0)
91                         filter = &regex;
92         }
93
94         stat_ev_enabled = stat_ev_file != NULL;
95 }
96
97 void stat_ev_end(void)
98 {
99         if (stat_ev_file) {
100                 fclose(stat_ev_file);
101         }
102         if (filter != NULL)
103                 regfree(filter);
104 }
105
106 #endif