mtrack - faster with less snprintfing

This commit is contained in:
Carsten Haitzler 2016-11-10 17:57:14 +09:00
parent a840cc0a5d
commit bcaba6c605
1 changed files with 19 additions and 5 deletions

View File

@ -337,25 +337,39 @@ _mhook_trace_log(const char *str)
}
inside = 1;
tot = sizeof(buf);
n = backtrace(bt, 256);
strcpy(buf, str);
p = buf + strlen(str); tot -= p - buf;
n = backtrace(bt, 250);
strcpy(p, " =="); p += 3; tot -= 3;
if (n > 0)
{
skip = 3;
for (i = skip; i < n; i++)
{
int len = 0;
Dl_info info;
if (dladdr(bt[i], &info))
{
len = snprintf(p, tot, " %s", info.dli_sname);
if (info.dli_sname)
{
len = strlen(info.dli_sname);
p[0] = ' ';
strcpy(p + 1, info.dli_sname);
len = 1 + len;
}
else
{
strcpy(p, " #");
len = 2;
}
}
else
len = snprintf(p, tot, " ?");
{
strcpy(p, " ?");
len = 2;
}
p += len; tot -= len;
}
}