X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=driver%2Ffirm_timing.c;h=b3466220af172487a03a49832b4865c3ee093d0e;hb=e3de7eaecb549e58c466d70b8f24d1f53aa9fc8a;hp=24994daef6e23cb5bddeea1b4adb0cc092ace0f4;hpb=d9f918c846087ee7fc1b97e83671181c1ecf2fff;p=cparser diff --git a/driver/firm_timing.c b/driver/firm_timing.c index 24994da..b346622 100644 --- a/driver/firm_timing.c +++ b/driver/firm_timing.c @@ -1,67 +1,91 @@ +/* + * This file is part of cparser. + * Copyright (C) 2012 Michael Beck + */ + /** - * @file firm_timing.c -- timing for the Firm compiler - * - * (C) 2006 Michael Beck beck@ipd.info.uni-karlsruhe.de - * - * $Id$ + * @file + * @brief timing for the Firm compiler */ -#include #include "firm_timing.h" -static const char *tv_names[] = { -#define DEFTIMEVAR(x, y, z) y, -#include "firm_timing.def" - NULL -#undef DEFTIMEVAR -}; - -static const char *tv_desc[] = { -#define DEFTIMEVAR(x, y, z) z, -#include "firm_timing.def" - NULL -#undef DEFTIMEVAR -}; - -static lc_timer_t *timers[TV_LAST]; +#include + static int timers_inited; -void timer_init(void) { - int i; +typedef struct timer_info_t { + struct timer_info_t *next; + char *description; + ir_timer_t *timer; +} timer_info_t; + +static timer_info_t *infos; +static timer_info_t *last_info; - for (i = 0; i < TV_LAST; ++i) { - timers[i] = lc_timer_register(tv_names[i], tv_desc[i]); +void timer_register(ir_timer_t *timer, const char *description) +{ + timer_info_t *info = XMALLOCZ(timer_info_t); + + info->description = xstrdup(description); + info->timer = timer; + + if (last_info != NULL) { + last_info->next = info; + } else { + infos = info; } + last_info = info; +} +void timer_init(void) +{ timers_inited = 1; } -void timer_term(FILE *f) { - int i; +void timer_term(FILE *f) +{ + timer_info_t *info; + timer_info_t *next; + + for (info = infos; info != NULL; info = next) { + ir_timer_t *timer = info->timer; + if (f != NULL) { + double val = (double)ir_timer_elapsed_usec(timer) / 1000.0; + const char *description = info->description; + fprintf(f, "%-60s %10.3f msec\n", description, val); + } - for (i = 0; i < TV_LAST; ++i) { - unsigned long val = lc_timer_elapsed_msec(timers[i]); - fprintf(f, "%-30s %8lu\n", tv_desc[i], val); + ir_timer_free(timer); + xfree(info->description); + next = info->next; + xfree(info); } + infos = NULL; + last_info = NULL; timers_inited = 0; } -void timer_push(int timer) { +void timer_push(ir_timer_t *timer) +{ if (timers_inited) - lc_timer_push(timers[timer]); + ir_timer_push(timer); } -void timer_pop(void) { +void timer_pop(ir_timer_t *timer) +{ if (timers_inited) - lc_timer_pop(); + ir_timer_pop(timer); } -void timer_start(int timer) { +void timer_start(ir_timer_t *timer) +{ if (timers_inited) - lc_timer_start(timers[timer]); + ir_timer_start(timer); } -void timer_stop(int timer) { +void timer_stop(ir_timer_t *timer) +{ if (timers_inited) - lc_timer_stop(timers[timer]); + ir_timer_stop(timer); }