diff options
Diffstat (limited to 'src/triplet.c')
-rw-r--r-- | src/triplet.c | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/src/triplet.c b/src/triplet.c index 8c81ad8..2ad4e1d 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -357,8 +357,8 @@ triplet_enqueue(struct wy_triplet *trp) struct spool *spool = trp->spool; if (!trp) return; - timer_start("spool"); - timer_start(spool->tag); + timer_start(WY_TIMER_SPOOL); + timer_start(spool->timer_id); if (spool_open_dictionaries(spool) == 0) { switch (check_triplet_state(trp)) { case triplet_directive: @@ -380,8 +380,8 @@ triplet_enqueue(struct wy_triplet *trp) remove_triplet(trp); } } - timer_stop(spool->tag); - timer_stop("spool"); + timer_stop(spool->timer_id); + timer_stop(WY_TIMER_SPOOL); } /* Unlink all parts of the triplet TRP */ @@ -429,14 +429,14 @@ remove_triplet(struct wy_triplet *trp) void triplet_commit(struct wy_triplet *trp) { - timer_start("spool"); + timer_start(WY_TIMER_SPOOL); if (spool_open_dictionaries(trp->spool) == 0) { - timer_start(trp->spool->tag); + timer_start(trp->spool->timer_id); wy_debug(1, (_("processing triplet `%s'"), trp->name)); process_directives(trp); - timer_stop(trp->spool->tag); + timer_stop(trp->spool->timer_id); } - timer_stop("spool"); + timer_stop(WY_TIMER_SPOOL); } void @@ -570,28 +570,14 @@ struct wy_varexp { int flags; struct wy_triplet *triplet; struct wy_vardef **def; - char **timers; struct dictionary *dict; void *handle; }; -static int -member(char **a, char const *s) -{ - if (!a) - return 1; - while (*a) { - if (strcmp(*a, s) == 0) - return 1; - ++a; - } - return 0; -} - static void wy_ws_error(const char *fmt, ...); static int -try_timer_var(char **retval, char const *var, size_t len, char **timers) +try_timer_var(char **retval, char const *var, size_t len) { struct wordsplit ws; int rc = WRDSE_UNDEF; @@ -608,23 +594,31 @@ try_timer_var(char **retval, char const *var, size_t len, char **timers) (int) len, (int) len, var); exit(EX_UNAVAILABLE); } - if (ws.ws_wordc == 3 && strcmp(ws.ws_wordv[0], "timer") == 0) { - wydawca_timer_t t = NULL; - - if (member(timers, ws.ws_wordv[1])) - t = timer_get(ws.ws_wordv[1]); - if (t) { + if (strcmp(ws.ws_wordv[0], "timer") == 0) { + int n = -1; + + if (ws.ws_wordc == 3) { + if (strcmp(ws.ws_wordv[1], "wydawca") == 0) + n = WY_TIMER_WYDAWCA; + else if (strcmp(ws.ws_wordv[1], "triplet") == 0) + n = WY_TIMER_TRIPLET; + else if (strcmp(ws.ws_wordv[1], "spool") == 0) + n = WY_TIMER_SPOOL; + } else if (ws.ws_wordc == 4 && strcmp(ws.ws_wordv[1], "spool") == 0) + n = spool_timer_id(ws.ws_wordv[1] + 6); + + if (n >= 0) { double (*tfn) (wydawca_timer_t) = NULL; - if (strcmp(ws.ws_wordv[2], "real") == 0) + if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "real") == 0) tfn = timer_get_real; - else if (strcmp(ws.ws_wordv[2], "user") == 0) + else if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "user") == 0) tfn = timer_get_user; - else if (strcmp(ws.ws_wordv[2], "system") == 0) + else if (strcmp(ws.ws_wordv[ws.ws_wordc-1], "system") == 0) tfn = timer_get_system; if (tfn) { - *retval = timer_format_time(tfn(t)); + *retval = timer_format_time(tfn(get_thread_timer(n))); rc = WRDSE_OK; } } @@ -672,7 +666,7 @@ wy_varexp_lookup(char **retval, const char *var, size_t len, void *clos) rc = wy_varexp_lookup_triplet(&res, var, len, exp->def, exp->triplet); if (rc != WRDSE_OK && (exp->flags & WY_EXP_TIMERS)) - rc = try_timer_var(&res, var, len, exp->timers); + rc = try_timer_var(&res, var, len); if (rc != WRDSE_OK && (exp->flags & WY_EXP_STATS)) rc = wy_stat_expansion(&res, var, len); if (rc == WRDSE_OK) { @@ -1087,12 +1081,10 @@ wy_triplet_expand_param(const char *tmpl, struct wy_triplet *trp, { struct wy_vardef *vd[] = { triplet_query_def, triplet_def, extra, NULL }; - static char *timers[] = { "wydawca", "triplet", "spool", NULL }; struct wy_varexp varexp = { .flags = WY_EXP_TIMERS, .triplet = trp, .def = vd, - .timers = timers }; return wy_expand_string(tmpl, &varexp); } |