Use block walk for ssa_cons_start
[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  * @version     $Id$
26  */
27 #include "config.h"
28
29 #include <assert.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdarg.h>
34 #include <regex.h>
35
36 #include "util.h"
37 #include "stat_timing.h"
38 #include "irprintf.h"
39 #include "statev.h"
40
41 #include "config.h"
42
43 #ifndef DISABLE_STATEV
44
45 #define MAX_TIMER 256
46
47 static FILE* stat_ev_file  = NULL;
48
49 int            stat_ev_enabled = 0;
50 int            stat_ev_timer_sp = 0;
51 timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
52 timing_ticks_t stat_ev_timer_start[MAX_TIMER];
53
54 static regex_t regex;
55 static regex_t *filter = NULL;
56 static inline int key_matches(const char *key)
57 {
58         if (!filter)
59                 return 1;
60
61         return regexec(filter, key, 0, NULL, 0) == 0;
62 }
63
64 void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
65 {
66         if (!key_matches(key))
67                 return;
68
69         fprintf(stat_ev_file, "%c;%s", ev, key);
70         if (fmt != NULL) {
71                 char buf[256];
72                 va_list args;
73
74                 va_start(args, fmt);
75                 ir_vsnprintf(buf, sizeof(buf), fmt, args);
76                 va_end(args);
77                 fprintf(stat_ev_file, ";%s", buf);
78         }
79         fprintf(stat_ev_file, "\n");
80 }
81
82 void stat_ev_begin(const char *prefix, const char *filt)
83 {
84         char buf[512];
85
86         snprintf(buf, sizeof(buf), "%s.ev", prefix);
87         stat_ev_file = fopen(buf, "wt");
88
89         if (filt && filt[0] != '\0') {
90                 filter = NULL;
91                 if (regcomp(&regex, filt, REG_EXTENDED) == 0)
92                         filter = &regex;
93         }
94
95         stat_ev_enabled = stat_ev_file != NULL;
96 }
97
98 void stat_ev_end(void)
99 {
100         if (stat_ev_file) {
101                 fclose(stat_ev_file);
102         }
103         if (filter != NULL)
104                 regfree(filter);
105         regfree(filter);
106 }
107
108 #endif