[sysprof] Avoid mallocs in process_sample()



commit 75c5a39c72603d8fb6040dd5acbe74daa4b35cca
Author: Søren Sandmann Pedersen <ssp redhat com>
Date:   Tue Sep 8 03:24:46 2009 -0400

    Avoid mallocs in process_sample()

 TODO      |    2 ++
 tracker.c |   11 ++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/TODO b/TODO
index 4733b9d..90c6ee4 100644
--- a/TODO
+++ b/TODO
@@ -23,6 +23,8 @@ Before 1.0.4:
 
 Before 1.2:
 
+* Kernel binary when available, is better than kallsyms.
+
 * Hack around gtk+ bug where it mispositions the window.
 
 * Counters must not be destroyed during tracker setup. They have to exist
diff --git a/tracker.c b/tracker.c
index 7f59f3e..92f2ab2 100644
--- a/tracker.c
+++ b/tracker.c
@@ -885,6 +885,7 @@ process_sample (state_t *state, StackStash *resolved, sample_t *sample)
 {
     const context_info_t *context = NULL;
     const char *cmdline;
+    uint64_t stack_addrs[256];
     uint64_t *resolved_traces;
     process_t *process;
     StackNode *n;
@@ -907,8 +908,11 @@ process_sample (state_t *state, StackStash *resolved, sample_t *sample)
     len = 4;
     for (n = sample->trace; n != NULL; n = n->parent)
 	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;
     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);
 
-    g_free (resolved_traces);
+    if (resolved_traces != stack_addrs)
+	g_free (resolved_traces);
 }
 
 Profile *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]