Commit 05b0ea2e authored by Matthias Braun's avatar Matthias Braun
Browse files

statev: cleanup, optimized hot function, show warnings if something fails

parent 6b2210dd
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment