- get_Block_cfgpred_arr() IS supported, but should not be in the official
[libfirm] / ir / stat / statev.h
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
28 #ifndef FIRM_STATEVENT_H
29 #define FIRM_STATEVENT_H
30
31 #if !defined(FIRM_STATISTICS) || defined(DISABLE_STATEV)
32
33 #define stat_ev_do(expr)
34 #define stat_ev_if                  if (0)
35 #define stat_ev_dbl(name, val)
36 #define stat_ev_int(name, val)
37 #define stat_ev(name)
38 #define stat_ev_emit(name, value)
39
40 #define stat_ev_cnt_decl(var)
41 #define stat_ev_cnt_inc(var)
42 #define stat_ev_cnt_done(name, var)
43 #define stat_ev_tim_push()
44 #define stat_ev_tim_pop(name)
45
46 #define stat_ev_ctx_push(key)
47 #define stat_ev_ctx_push_str(key, str)
48 #define stat_ev_ctx_push_fmt(key, fmt, value)
49 #define stat_ev_ctx_push_fobj(key, firm_object)
50 #define stat_ev_ctx_pop(key)
51 #define stat_ev_flush()
52
53 #else
54
55 #include <stdio.h>
56 #include "stat_timing.h"
57
58 extern void               stat_ev_printf(char ev_type, const char *key, const char *fmt, ...);
59
60 extern int                stat_ev_enabled;
61 extern int                stat_ev_timer_sp;
62 extern timing_ticks_t     stat_ev_timer_elapsed[];
63 extern timing_ticks_t     stat_ev_timer_start[];
64 extern timing_sched_env_t stat_ev_sched_rt;
65 extern timing_sched_env_t stat_ev_sched_normal;
66
67 static inline __attribute__((unused)) void stat_ev_tim_push(void) {
68         timing_ticks_t temp;
69         int sp = stat_ev_timer_sp++;
70         timing_ticks(temp);
71         if (sp == 0)
72                 timing_sched_set(&stat_ev_sched_rt);
73         else {
74                 timing_ticks_sub(temp, stat_ev_timer_start[sp - 1]);
75                 timing_ticks_add(stat_ev_timer_elapsed[sp - 1], temp);
76         }
77         timing_ticks_init(stat_ev_timer_elapsed[sp]);
78         timing_ticks(stat_ev_timer_start[sp]);
79 }
80
81 static inline __attribute__((unused)) void stat_ev_tim_pop(const char *name) {
82         int sp;
83         timing_ticks_t temp;
84         timing_ticks(temp);
85         sp = --stat_ev_timer_sp;
86         timing_ticks_sub(temp, stat_ev_timer_start[sp]);
87         timing_ticks_add(stat_ev_timer_elapsed[sp], temp);
88         if (name != NULL && stat_ev_enabled)
89                 stat_ev_printf('E', name, "%g", timing_ticks_dbl(stat_ev_timer_elapsed[sp]));
90         if (sp == 0)
91                 timing_sched_set(&stat_ev_sched_normal);
92         else
93                 timing_ticks(stat_ev_timer_start[sp - 1]);
94 }
95
96 #define stat_ev_ctx_push_fmt(key, fmt, value) \
97         do { \
98                 if (stat_ev_enabled) { \
99                         stat_ev_tim_push(); \
100                         stat_ev_printf('P', key, fmt, (value)); \
101                         stat_ev_tim_pop(NULL); \
102                 } \
103         } while(0)
104
105 #define stat_ev_ctx_pop(key) \
106         do { \
107                 if (stat_ev_enabled) { \
108                         stat_ev_tim_push(); \
109                         stat_ev_printf('O', key, NULL); \
110                         stat_ev_tim_pop(NULL); \
111                 } \
112         } while(0)
113
114 #define stat_ev_emit(name, value) \
115         do { \
116                 if (stat_ev_enabled) { \
117                         stat_ev_tim_push(); \
118                         stat_ev_printf('E', name, "%g", (double) (value)); \
119                         stat_ev_tim_pop(NULL); \
120                 } \
121         } while(0)
122
123 #define stat_ev_ctx_push_fobj(key, firm_object) stat_ev_ctx_push_fmt((key), "%+F", (firm_object))
124 #define stat_ev_ctx_push_str(key, str)          stat_ev_ctx_push_fmt((key), "%s", (str))
125 #define stat_ev_ctx_push(key)                   stat_ev_ctx_push_fmt((key), "X", NULL)
126
127 #define stat_ev_dbl(name, val)      stat_ev_emit((name), (val))
128 #define stat_ev_int(name, val)      stat_ev_dbl((name), (double) (val))
129 #define stat_ev(name)               stat_ev_emit((name), 0.0)
130
131 #define stat_ev_cnt_decl(var)       int stat_ev_cnt_var_ ## var = 0
132 #define stat_ev_cnt_inc(var)        do { ++stat_ev_cnt_var_ ## var; } while(0)
133 #define stat_ev_cnt_done(var, name) stat_ev_emit((name), stat_ev_cnt_var_ ## var)
134
135 #define stat_ev_do(expr)            (stat_ev_enabled ? ((expr), 1) : 0)
136 #define stat_ev_if                  if (stat_ev_enabled)
137
138 /**
139  * Initialize the stat ev machinery.
140  * @param filename_prefix  The prefix of the filename (.ev or .ev.gz will be appended).
141  * @param filter           All pushes, pops and events will be filtered by this.
142  *                         If we have regex support, you can give an extended regex here.
143  *                         If not, each key will be matched against this.
144  *                         Matched means, we look if the key starts with @p filter.
145  *                         If NULL is given, each key passes, ie thefilter is always TRUE.
146  */
147 void stat_ev_begin(const char *filename_prefix, const char *filter);
148 void stat_ev_end(void);
149
150 #define stat_ev_flush()             do { if (stat_ev_enabled) fflush(stat_ev_enabled); } while(0)
151
152 #endif
153
154 #endif /* FIRM_STATEVENT_H */