summaryrefslogtreecommitdiffhomepage
path: root/ir/stat
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2014-07-08 14:43:15 +0200
committerMatthias Braun <matze@braunis.de>2014-07-08 14:43:15 +0200
commit05b0ea2e217ea1bca1c80c9d4416301283bc2516 (patch)
tree143ce845819852a6afa5fa048cd8200d5ebe76df /ir/stat
parent6b2210ddab736a38227d4764160a3c42d4d55fde (diff)
statev: cleanup, optimized hot function, show warnings if something fails
Diffstat (limited to 'ir/stat')
-rw-r--r--ir/stat/statev.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/ir/stat/statev.c b/ir/stat/statev.c
index 343f6fb..656823e 100644
--- a/ir/stat/statev.c
+++ b/ir/stat/statev.c
@@ -9,11 +9,12 @@
* @author Sebastian Hack
* @date 17.06.2007
*/
+#include <assert.h>
+#include <regex.h>
+#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
-#include <regex.h>
-#include <assert.h>
#include "stat_timing.h"
#include "irprintf.h"
@@ -24,17 +25,18 @@
int (stat_ev_enabled) = 0;
-static FILE *stat_ev_file = NULL;
-static int stat_ev_timer_sp = 0;
+static FILE *stat_ev_file;
+static int stat_ev_timer_sp;
static timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
static timing_ticks_t stat_ev_timer_start[MAX_TIMER];
static regex_t regex;
-static regex_t *filter = NULL;
-static inline int key_matches(const char *key)
+static regex_t *filter;
+
+static bool key_matches(const char *key)
{
- if (!filter)
- return 1;
+ if (filter == NULL)
+ return true;
return regexec(filter, key, 0, NULL, 0) == 0;
}
@@ -44,14 +46,14 @@ static void stat_ev_vprintf(char ev, const char *key, const char *fmt, va_list a
if (!key_matches(key))
return;
- fprintf(stat_ev_file, "%c;%s", ev, key);
+ putc(ev, stat_ev_file);
+ putc(';', stat_ev_file);
+ fputs(key, stat_ev_file);
if (fmt != NULL) {
- char buf[256];
-
- ir_vsnprintf(buf, sizeof(buf), fmt, ap);
- fprintf(stat_ev_file, ";%s", buf);
+ putc(';', stat_ev_file);
+ ir_vfprintf(stat_ev_file, fmt, ap);
}
- fprintf(stat_ev_file, "\n");
+ putc('\n', stat_ev_file);
}
static void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
@@ -183,11 +185,19 @@ void stat_ev_begin(const char *prefix, const char *filt)
snprintf(buf, sizeof(buf), "%s.ev", prefix);
stat_ev_file = fopen(buf, "wt");
+ if (stat_ev_file == NULL) {
+ fprintf(stderr, "Warning: Couldn't create statev output '%s'\n", buf);
+ }
- if (filt && filt[0] != '\0') {
+ if (filt != NULL && filt[0] != '\0') {
filter = NULL;
- if (regcomp(&regex, filt, REG_EXTENDED) == 0)
+ if (regcomp(&regex, filt, REG_EXTENDED) == 0) {
filter = &regex;
+ } else {
+ fprintf(stderr,
+ "Warning: Couldn't parse statev filter expression '%s'\n",
+ filt);
+ }
}
stat_ev_enabled = stat_ev_file != NULL;