From d0c695bdf9b94670644867c3f0c801af2a57dfb4 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 30 Aug 2007 13:30:00 +0000 Subject: [PATCH] add support to print some events in a human readable format to stderr [r15627] --- ir/be/bemain.c | 16 +++++++-- ir/stat/statev.c | 84 +++++++++++++++++++++++++++++++++++++++++++----- ir/stat/statev.h | 3 +- 3 files changed, 91 insertions(+), 12 deletions(-) diff --git a/ir/be/bemain.c b/ir/be/bemain.c index c164ba45b..09099a282 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -94,6 +94,7 @@ static be_options_t be_options = { "i44pc52.info.uni-karlsruhe.de", /* ilp server */ "cplex", /* ilp solver */ 0, /* enable statistic event dumping */ + "", /* print stat events */ }; /* config file. */ @@ -154,7 +155,10 @@ static const lc_opt_table_entry_t be_main_options[] = { LC_OPT_ENT_BOOL ("time", "get backend timing statistics", &be_options.timing), LC_OPT_ENT_BOOL ("profile", "instrument the code for execution count profiling", &be_options.opt_profile), LC_OPT_ENT_ENUM_PTR ("sched", "select a scheduler", &sched_var), +#ifdef FIRM_STATISTICS LC_OPT_ENT_BOOL ("statev", "dump statistic events", &be_options.statev), + LC_OPT_ENT_STR ("printev", "print (some) statistic events", &be_options.printev, sizeof(be_options.printev)), +#endif #ifdef WITH_ILP LC_OPT_ENT_STR ("ilp.server", "the ilp server name", be_options.ilp_server, sizeof(be_options.ilp_server)), @@ -604,7 +608,7 @@ static void be_main_loop(FILE *file_handle, const char *cup_name) BE_TIMER_POP(t_verify); /* do some statistics */ - be_do_stat_reg_pressure(birg); + //be_do_stat_reg_pressure(birg); #ifdef FIRM_STATISTICS stat_ev_dbl("costs_before_ra", be_estimate_irg_costs(irg, env.arch_env, birg->exec_freq)); @@ -761,7 +765,8 @@ void be_main(FILE *file_handle, const char *cup_name) lc_timer_reset_and_start(t); } - if (be_options.statev) { +#ifdef FIRM_STATISTICS + if (be_options.statev || be_options.printev[0] != '\0') { const char *dot = strrchr(cup_name, '.'); const char *pos = dot ? dot : cup_name + strlen(cup_name); char *buf = alloca(pos - cup_name + 1); @@ -769,7 +774,12 @@ void be_main(FILE *file_handle, const char *cup_name) buf[pos - cup_name] = '\0'; stat_ev_begin(buf); + + if(be_options.printev[0] != '\0') { + stat_ev_print(be_options.printev); + } } +#endif /* never build code for pseudo irgs */ set_visit_pseudo_irgs(0); @@ -785,8 +795,10 @@ void be_main(FILE *file_handle, const char *cup_name) printf("%-20s: %lu msec\n", "BEMAINLOOP", lc_timer_elapsed_msec(t)); } +#ifdef FIRM_STATISTICS if (be_options.statev) stat_ev_end(); +#endif } /** The debug info retriever function. */ diff --git a/ir/stat/statev.c b/ir/stat/statev.c index 27edb5a93..0ce2ebbf9 100644 --- a/ir/stat/statev.c +++ b/ir/stat/statev.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -56,6 +57,14 @@ static lc_timer_t *timer = NULL; int stat_ev_enabled = 0; +typedef struct print_ev_t { + char filter[128]; + struct print_ev_t *next; +} print_ev_t; + +static print_ev_t *print_events = NULL; +static int ctx_switch_since_last_print = 0; + #define get_time() lc_timer_elapsed_usec(timer) void stat_ev_ctx_push(const char *key, const char *value) @@ -69,12 +78,14 @@ void stat_ev_ctx_push(const char *key, const char *value) if (ctx_sp >= 0) hash = HASH_COMBINE(hash, ctx_stack[ctx_sp].hash); - strncpy(ctx->key, key, array_size(ctx->key)); - strncpy(ctx->value, value, array_size(ctx->key)); + snprintf(ctx->key, array_size(ctx->key), "%s", key); + snprintf(ctx->value, array_size(ctx->value), "%s", value); ctx->hash = hash | 1; ++ctx_sp; - fprintf(file_ev, "P %10x %30s %30s\n", ctx->hash, key, value); + fprintf(file_ev, "P %10x %30s %30s\n", ctx->hash, ctx->key, ctx->value); + + ctx_switch_since_last_print = 1; time_in_ev += get_time() - start; } @@ -92,12 +103,30 @@ void stat_ev_ctx_push_fobj(const char *key, const void *firm_object) void stat_ev_ctx_pop(void) { if (ctx_sp >= 0) { - if (file_ev) + if (file_ev) { fprintf(file_ev, "O %10x\n", ctx_stack[ctx_sp].hash); + ctx_switch_since_last_print = 1; + } --ctx_sp; } } +static void maybe_print_context(void) +{ + int i; + + if(!ctx_switch_since_last_print) + return; + + for(i = 0; i <= ctx_sp; ++i) { + if(i > 0) + fputc(':', stderr); + fputs(ctx_stack[i].value, stderr); + } + fputc('\n', stderr); + ctx_switch_since_last_print = 0; +} + void stat_ev_emit(const char *name, double value) { if (file_ev) { @@ -105,6 +134,20 @@ void stat_ev_emit(const char *name, double value) unsigned id = ctx_sp >= 0 ? ctx_stack[ctx_sp].hash : 0; fprintf(file_ev, "E %10x %30s %30f %10ld %10ld\n", id, name, value, start, time_in_ev); + + if(print_events != NULL) { + print_ev_t *print_ev = print_events; + while(print_ev != NULL) { + /* maybe wanna use regexes instead of strcmp? */ + if(strstr(name, print_ev->filter) != NULL) { + maybe_print_context(); + fprintf(stderr, "\t%20s %30f\n", name, value); + } + + print_ev = print_ev->next; + } + } + time_in_ev += get_time() - start; } } @@ -116,10 +159,11 @@ void stat_ev_begin(const char *prefix) snprintf(buf, sizeof(buf), "%s.ev", prefix); stat_ev_enabled = 1; - ctx_sp = -1; - time_in_ev = 0; - file_ev = fopen(buf, "wt"); - timer = lc_timer_register("stat_ev", "firm stat event timer"); + ctx_sp = -1; + time_in_ev = 0; + print_events = NULL; + file_ev = fopen(buf, "wt"); + timer = lc_timer_register("stat_ev", "firm stat event timer"); lc_timer_start(timer); } @@ -130,6 +174,13 @@ void stat_ev_end(void) lc_timer_stop(timer); if (file_ev) fclose(file_ev); + + print_ev_t *print_ev = print_events; + while(print_ev != NULL) { + print_ev_t *next = print_ev->next; + free(print_ev); + print_ev = next; + } } void stat_ev_flush(void) @@ -139,3 +190,20 @@ void stat_ev_flush(void) fflush(file_ev); time_in_ev += get_time() - start; } + +void stat_ev_print(const char *filter) +{ + print_ev_t *print_ev = malloc(sizeof(print_ev[0])); + memset(print_ev, 0, sizeof(print_ev[0])); + + size_t len = strlen(filter) + 1; + if(len >= sizeof(print_ev->filter)) { + fprintf(stderr, "Warning: capping event filter (too long)"); + len = sizeof(print_ev->filter); + } + memcpy(print_ev->filter, filter, len); + print_ev->filter[len-1] = 0; + + print_ev->next = print_events; + print_events = print_ev; +} diff --git a/ir/stat/statev.h b/ir/stat/statev.h index cc498ab3b..b8988811d 100644 --- a/ir/stat/statev.h +++ b/ir/stat/statev.h @@ -41,8 +41,6 @@ #define stat_ev_ctx_push_fobj(key, firm_object) #define stat_ev_ctx_push(key, value) #define stat_ev_ctx_pop() -#define stat_ev_begin(prefix) -#define stat_ev_end() #define stat_ev_flush() #else @@ -66,6 +64,7 @@ void stat_ev_emit(const char *name, double val); void stat_ev_begin(const char *prefix); void stat_ev_end(void); void stat_ev_flush(void); +void stat_ev_print(const char *event_filter); #endif -- 2.20.1