1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-30 15:02:18 +01:00

make the zprof wrapper function be more careful, avoiding almost all of the code when the module is being unloaded (14504)

This commit is contained in:
Sven Wischnowsky 2001-05-28 09:23:39 +00:00
parent 96fd8a11d3
commit 5fe1924155
2 changed files with 61 additions and 46 deletions

View file

@ -1,5 +1,9 @@
2001-05-28 Sven Wischnowsky <wischnow@zsh.org> 2001-05-28 Sven Wischnowsky <wischnow@zsh.org>
* 14504: Src/Modules/zprof.c: make the zprof wrapper function
be more careful, avoiding almost all of the code when the
module is being unloaded
* 14503: Src/exec.c: another attempt at fixing the job problem * 14503: Src/exec.c: another attempt at fixing the job problem
from 14327; make execpline() reset list_pipe_job to zero if it from 14327; make execpline() reset list_pipe_job to zero if it
would be set for a job started in the background would be set for a job started in the background

View file

@ -68,6 +68,7 @@ static int ncalls;
static Parc arcs; static Parc arcs;
static int narcs; static int narcs;
static Sfunc stack; static Sfunc stack;
static Module zprof_module;
static void static void
freepfuncs(Pfunc f) freepfuncs(Pfunc f)
@ -216,6 +217,7 @@ bin_zprof(char *nam, char **args, char *ops, int func)
static int static int
zprof_wrapper(Eprog prog, FuncWrap w, char *name) zprof_wrapper(Eprog prog, FuncWrap w, char *name)
{ {
int active = 0;
struct sfunc sf, *sp; struct sfunc sf, *sp;
Pfunc f; Pfunc f;
Parc a = NULL; Parc a = NULL;
@ -223,56 +225,64 @@ zprof_wrapper(Eprog prog, FuncWrap w, char *name)
struct timezone dummy; struct timezone dummy;
double prev, now; double prev, now;
if (!(f = findpfunc(name))) { if (zprof_module && !(zprof_module->flags & MOD_UNLOAD)) {
f = (Pfunc) zalloc(sizeof(*f)); active = 1;
f->name = ztrdup(name); if (!(f = findpfunc(name))) {
f->calls = 0; f = (Pfunc) zalloc(sizeof(*f));
f->time = f->self = 0.0; f->name = ztrdup(name);
f->next = calls; f->calls = 0;
calls = f; f->time = f->self = 0.0;
ncalls++; f->next = calls;
} calls = f;
if (stack) { ncalls++;
if (!(a = findparc(stack->p, f))) { }
a = (Parc) zalloc(sizeof(*a)); if (stack) {
a->from = stack->p; if (!(a = findparc(stack->p, f))) {
a->to = f; a = (Parc) zalloc(sizeof(*a));
a->calls = 0; a->from = stack->p;
a->time = a->self = 0.0; a->to = f;
a->next = arcs; a->calls = 0;
arcs = a; a->time = a->self = 0.0;
narcs++; a->next = arcs;
} arcs = a;
} narcs++;
sf.prev = stack; }
sf.p = f; }
stack = &sf; sf.prev = stack;
sf.p = f;
stack = &sf;
f->calls++; f->calls++;
tv.tv_sec = tv.tv_usec = 0; tv.tv_sec = tv.tv_usec = 0;
gettimeofday(&tv, &dummy); gettimeofday(&tv, &dummy);
sf.beg = prev = ((((double) tv.tv_sec) * 1000.0) + sf.beg = prev = ((((double) tv.tv_sec) * 1000.0) +
(((double) tv.tv_usec) / 1000.0)); (((double) tv.tv_usec) / 1000.0));
}
runshfunc(prog, w, name); runshfunc(prog, w, name);
tv.tv_sec = tv.tv_usec = 0; if (active) {
gettimeofday(&tv, &dummy); 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) + now = ((((double) tv.tv_sec) * 1000.0) +
(((double) tv.tv_usec) / 1000.0)); (((double) tv.tv_usec) / 1000.0));
f->self += now - sf.beg; f->self += now - sf.beg;
for (sp = sf.prev; sp && sp->p != f; sp = sp->prev); for (sp = sf.prev; sp && sp->p != f; sp = sp->prev);
if (!sp) if (!sp)
f->time += now - prev; f->time += now - prev;
if (a) { if (a) {
a->calls++; a->calls++;
a->self += now - sf.beg; a->self += now - sf.beg;
} }
stack = sf.prev; stack = sf.prev;
if (stack) { if (stack) {
stack->beg += now - prev; stack->beg += now - prev;
if (a) if (a)
a->time += now - prev; a->time += now - prev;
}
} else
stack = sf.prev;
} }
return 0; return 0;
} }
@ -289,6 +299,7 @@ static struct funcwrap wrapper[] = {
int int
setup_(Module m) setup_(Module m)
{ {
zprof_module = m;
return 0; return 0;
} }