mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-17 11:41:07 +01:00
45923 (with memory leak fixed, cf. 45924): zprof: Don't tally all anonymous functions as though they were a single function named "(anon)".
Before:
% zmodload zsh/zprof
% () :
% () :
% zprof
num calls time self name
-----------------------------------------------------------------------------------
1) 2 0.08 0.04 100.00% 0.08 0.04 100.00% (anon)
After:
% zmodload zsh/zprof
% () :
% () :
% zprof
num calls time self name
-----------------------------------------------------------------------------------
1) 1 0.04 0.04 50.45% 0.04 0.04 50.45% (anon) [:3]
2) 1 0.04 0.04 49.55% 0.04 0.04 49.55% (anon) [:2]
This commit is contained in:
parent
40723b3991
commit
fb1aa3fe1e
3 changed files with 52 additions and 5 deletions
|
|
@ -213,7 +213,25 @@ bin_zprof(UNUSED(char *nam), UNUSED(char **args), Options ops, UNUSED(int func))
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**/
|
||||
static char *
|
||||
name_for_anonymous_function(char *name)
|
||||
{
|
||||
char lineno[DIGBUFSIZE];
|
||||
char *parts[7];
|
||||
|
||||
convbase(lineno, funcstack[0].flineno, 10);
|
||||
|
||||
parts[0] = name;
|
||||
parts[1] = " [";
|
||||
parts[2] = funcstack[0].filename ? funcstack[0].filename : "";
|
||||
parts[3] = ":";
|
||||
parts[4] = lineno;
|
||||
parts[5] = "]";
|
||||
parts[6] = NULL;
|
||||
|
||||
return sepjoin(parts, "", 1);
|
||||
}
|
||||
|
||||
static int
|
||||
zprof_wrapper(Eprog prog, FuncWrap w, char *name)
|
||||
{
|
||||
|
|
@ -224,12 +242,19 @@ zprof_wrapper(Eprog prog, FuncWrap w, char *name)
|
|||
struct timeval tv;
|
||||
struct timezone dummy;
|
||||
double prev = 0, now;
|
||||
char *name_for_lookups;
|
||||
|
||||
if (is_anonymous_function_name(name)) {
|
||||
name_for_lookups = name_for_anonymous_function(name);
|
||||
} else {
|
||||
name_for_lookups = name;
|
||||
}
|
||||
|
||||
if (zprof_module && !(zprof_module->node.flags & MOD_UNLOAD)) {
|
||||
active = 1;
|
||||
if (!(f = findpfunc(name))) {
|
||||
if (!(f = findpfunc(name_for_lookups))) {
|
||||
f = (Pfunc) zalloc(sizeof(*f));
|
||||
f->name = ztrdup(name);
|
||||
f->name = ztrdup(name_for_lookups);
|
||||
f->calls = 0;
|
||||
f->time = f->self = 0.0;
|
||||
f->next = calls;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue