Avoid mallocs in process_sample()

This commit is contained in:
Søren Sandmann Pedersen
2009-09-08 03:24:46 -04:00
parent 6dabcefec5
commit 75c5a39c72
2 changed files with 10 additions and 3 deletions

2
TODO
View File

@ -23,6 +23,8 @@ Before 1.0.4:
Before 1.2: Before 1.2:
* Kernel binary when available, is better than kallsyms.
* Hack around gtk+ bug where it mispositions the window. * Hack around gtk+ bug where it mispositions the window.
* Counters must not be destroyed during tracker setup. They have to exist * Counters must not be destroyed during tracker setup. They have to exist

View File

@ -885,6 +885,7 @@ process_sample (state_t *state, StackStash *resolved, sample_t *sample)
{ {
const context_info_t *context = NULL; const context_info_t *context = NULL;
const char *cmdline; const char *cmdline;
uint64_t stack_addrs[256];
uint64_t *resolved_traces; uint64_t *resolved_traces;
process_t *process; process_t *process;
StackNode *n; StackNode *n;
@ -908,7 +909,10 @@ process_sample (state_t *state, StackStash *resolved, sample_t *sample)
for (n = sample->trace; n != NULL; n = n->parent) for (n = sample->trace; n != NULL; n = n->parent)
len++; len++;
resolved_traces = g_new (uint64_t, len); if (len > 256)
resolved_traces = g_new (uint64_t, len);
else
resolved_traces = stack_addrs;
len = 0; len = 0;
for (n = sample->trace; n != NULL; n = n->parent) for (n = sample->trace; n != NULL; n = n->parent)
@ -946,7 +950,8 @@ process_sample (state_t *state, StackStash *resolved, sample_t *sample)
stack_stash_add_trace (resolved, resolved_traces, len, 1); stack_stash_add_trace (resolved, resolved_traces, len, 1);
g_free (resolved_traces); if (resolved_traces != stack_addrs)
g_free (resolved_traces);
} }
Profile * Profile *