diff options
author | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2001-05-28 09:23:39 +0000 |
---|---|---|
committer | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2001-05-28 09:23:39 +0000 |
commit | 5fe19241552613eba49534a9749df84dbfeb4575 (patch) | |
tree | 692bceb0a4d46302a4b244d0d43540dfadec0861 /Src/Modules | |
parent | 96fd8a11d382319af89bfc8ed250003c4114da84 (diff) | |
download | zsh-5fe19241552613eba49534a9749df84dbfeb4575.tar.gz zsh-5fe19241552613eba49534a9749df84dbfeb4575.tar.xz zsh-5fe19241552613eba49534a9749df84dbfeb4575.zip |
make the zprof wrapper function be more careful, avoiding almost all of the code when the module is being unloaded (14504)
Diffstat (limited to 'Src/Modules')
-rw-r--r-- | Src/Modules/zprof.c | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/Src/Modules/zprof.c b/Src/Modules/zprof.c index c18dcc77c..4034f9273 100644 --- a/Src/Modules/zprof.c +++ b/Src/Modules/zprof.c @@ -68,6 +68,7 @@ static int ncalls; static Parc arcs; static int narcs; static Sfunc stack; +static Module zprof_module; static void freepfuncs(Pfunc f) @@ -216,6 +217,7 @@ bin_zprof(char *nam, char **args, char *ops, int func) static int zprof_wrapper(Eprog prog, FuncWrap w, char *name) { + int active = 0; struct sfunc sf, *sp; Pfunc f; Parc a = NULL; @@ -223,56 +225,64 @@ zprof_wrapper(Eprog prog, FuncWrap w, char *name) struct timezone dummy; double prev, now; - if (!(f = findpfunc(name))) { - f = (Pfunc) zalloc(sizeof(*f)); - f->name = ztrdup(name); - f->calls = 0; - f->time = f->self = 0.0; - f->next = calls; - calls = f; - ncalls++; + if (zprof_module && !(zprof_module->flags & MOD_UNLOAD)) { + active = 1; + if (!(f = findpfunc(name))) { + f = (Pfunc) zalloc(sizeof(*f)); + f->name = ztrdup(name); + f->calls = 0; + f->time = f->self = 0.0; + f->next = calls; + calls = f; + ncalls++; + } + if (stack) { + if (!(a = findparc(stack->p, f))) { + a = (Parc) zalloc(sizeof(*a)); + a->from = stack->p; + a->to = f; + a->calls = 0; + a->time = a->self = 0.0; + a->next = arcs; + arcs = a; + narcs++; + } + } + sf.prev = stack; + sf.p = f; + stack = &sf; + + f->calls++; + tv.tv_sec = tv.tv_usec = 0; + gettimeofday(&tv, &dummy); + sf.beg = prev = ((((double) tv.tv_sec) * 1000.0) + + (((double) tv.tv_usec) / 1000.0)); } - if (stack) { - if (!(a = findparc(stack->p, f))) { - a = (Parc) zalloc(sizeof(*a)); - a->from = stack->p; - a->to = f; - a->calls = 0; - a->time = a->self = 0.0; - a->next = arcs; - arcs = a; - narcs++; - } - } - sf.prev = stack; - sf.p = f; - stack = &sf; - - f->calls++; - tv.tv_sec = tv.tv_usec = 0; - gettimeofday(&tv, &dummy); - sf.beg = prev = ((((double) tv.tv_sec) * 1000.0) + - (((double) tv.tv_usec) / 1000.0)); runshfunc(prog, w, name); - tv.tv_sec = tv.tv_usec = 0; - gettimeofday(&tv, &dummy); - - now = ((((double) tv.tv_sec) * 1000.0) + - (((double) tv.tv_usec) / 1000.0)); - f->self += now - sf.beg; - for (sp = sf.prev; sp && sp->p != f; sp = sp->prev); - if (!sp) - f->time += now - prev; - if (a) { - a->calls++; - a->self += now - sf.beg; - } - stack = sf.prev; - - if (stack) { - stack->beg += now - prev; - if (a) - a->time += now - prev; + if (active) { + if (zprof_module && !(zprof_module->flags & MOD_UNLOAD)) { + tv.tv_sec = tv.tv_usec = 0; + gettimeofday(&tv, &dummy); + + now = ((((double) tv.tv_sec) * 1000.0) + + (((double) tv.tv_usec) / 1000.0)); + f->self += now - sf.beg; + for (sp = sf.prev; sp && sp->p != f; sp = sp->prev); + if (!sp) + f->time += now - prev; + if (a) { + a->calls++; + a->self += now - sf.beg; + } + stack = sf.prev; + + if (stack) { + stack->beg += now - prev; + if (a) + a->time += now - prev; + } + } else + stack = sf.prev; } return 0; } @@ -289,6 +299,7 @@ static struct funcwrap wrapper[] = { int setup_(Module m) { + zprof_module = m; return 0; } |