diff options
Diffstat (limited to 'src/callgraph-store.c')
-rw-r--r-- | src/callgraph-store.c | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/src/callgraph-store.c b/src/callgraph-store.c index e777198..e91f48a 100644 --- a/src/callgraph-store.c +++ b/src/callgraph-store.c @@ -27,11 +27,17 @@ #include "odin.h" #include "callgraph.h" +#include "frames.h" #define _(x) x typedef gboolean (*TraverseFunc) (CallGraphStore *, CallGraphFrame *, gpointer); +static const Frame _Everything = { + .function = "Everything", + .function_srcloc = "Everything", +}; + enum { INSERTED = 1 << 0, @@ -291,11 +297,11 @@ _tree_foreach (TreeNode *node, } inline CallGraphFrame * -call_graph_store_lookup_by_ip (CallGraphStore *store, gulong ip) +call_graph_store_lookup_by_frame (CallGraphStore *store, const Frame *f) { - guint index = (ip ^ 6017773UL) % store->frames_by_ip.size; + guint index = (f->ip ^ 6017773UL) % store->frames_by_ip.size; CallGraphFrame *node = store->frames_by_ip.nodes[index]; - while (node != NULL && node->ip != ip) + while (node != NULL && node->frame != f) node = node->ht_next_by_ip; return node; } @@ -305,7 +311,7 @@ call_graph_store_lookup_by_fn (CallGraphStore *store, const gchar *function) { guint index = ((gulong) function ^ 6017773UL) % store->frames_by_fn.size; CallGraphFrame *node = store->frames_by_fn.nodes[index]; - while (node != NULL && node->function != function) + while (node != NULL && node->frame->function != function) node = node->ht_next_by_fn; return node; } @@ -355,16 +361,16 @@ _call_graph_frame_accumulate (CallGraphFrame *frame, const AllocatorTime *At, co static gint _call_graph_frame_node_cmp (gconstpointer A, gconstpointer B) { - CallGraphFrame *a = container_of (A, CallGraphFrame, node); - CallGraphFrame *b = container_of (B, CallGraphFrame, node); - return a->ip - b->ip; + const CallGraphFrame *a = container_of (A, CallGraphFrame, node); + const CallGraphFrame *b = container_of (B, CallGraphFrame, node); + return a->frame - b->frame; } static gint _call_graph_frame_key_cmp (gconstpointer A, gconstpointer B) { - CallGraphFrame *b = container_of (B, CallGraphFrame, node); - return (gulong) A - b->ip; + const CallGraphFrame *b = container_of (B, CallGraphFrame, node); + return (Frame *) A - b->frame; } static CallGraphFrame * @@ -386,9 +392,7 @@ _call_graph_frame_new (CallGraphStore *store, frame->depth = depth; g_assert (depth < A->n_frames); - frame->ip = A->ips[depth]; - frame->frame = A->functions_srcloc[depth]; - frame->function = A->functions[depth]; + frame->frame = A->frames[depth]; frame->parent = parent; @@ -409,9 +413,9 @@ _call_graph_frame_new (CallGraphStore *store, &frame->node, _call_graph_frame_node_cmp); - index = (frame->ip ^ 6017773UL) % store->frames_by_ip.size; + index = (frame->frame->ip ^ 6017773UL) % store->frames_by_ip.size; prev = &store->frames_by_ip.nodes[index]; - while ((node = *prev) != NULL && node->ip != frame->ip) + while ((node = *prev) != NULL && node->frame != frame->frame) prev = &node->ht_next_by_ip; if (node != NULL) { frame->next_by_ip = node; @@ -421,9 +425,9 @@ _call_graph_frame_new (CallGraphStore *store, frame->ht_next_by_ip = store->frames_by_ip.nodes[index]; store->frames_by_ip.nodes[index] = frame; - index = ((gulong) frame->function ^ 6017773UL) % store->frames_by_fn.size; + index = ((gulong) frame->frame->function ^ 6017773UL) % store->frames_by_fn.size; prev = &store->frames_by_fn.nodes[index]; - while ((node = *prev) != NULL && node->function != frame->function) + while ((node = *prev) != NULL && node->frame->function != frame->frame->function) prev = &node->ht_next_by_fn; if (node != NULL) { frame->next_by_fn = node; @@ -582,7 +586,7 @@ _call_graph_store_get_value (GtkTreeModel *tree_model, switch (column) { case CG_FRAME: g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, frame->frame); + g_value_set_string (value, frame->frame->function_srcloc); break; case CG_BYTES: @@ -737,7 +741,7 @@ simple_hash_table_init (SimpleHashTable *ht, guint size) static void call_graph_store_init (CallGraphStore *self) { - self->root.frame = self->root.function = "Everything"; + self->root.frame = (Frame *) &_Everything; self->root.depth = -1; self->frames = &self->root; @@ -930,7 +934,7 @@ call_graph_store_update (CallGraphStore *store, child = NULL; if (frame->children != NULL) child = _tree_lookup (frame->children, - (gpointer) A->ips[n], + A->frames[n], _call_graph_frame_key_cmp); if (child == NULL) { _call_graph_frame_new (store, A, n, frame); @@ -953,7 +957,7 @@ call_graph_store_update (CallGraphStore *store, n++; while (n < AA->n_frames && n < A->n_frames && - A->ips[n] == AA->ips[n]) + A->frames[n] == AA->frames[n]) { child = _call_graph_frame_new (store, AA, n, child); _call_graph_frame_accumulate (child, At, Ap); @@ -994,7 +998,7 @@ _call_graph_frame_is_alloc (CallGraphFrame *frame, App *app) { gboolean was_alloc_fn = frame->is_alloc_fn; - frame->is_alloc_fn = app_is_alloc_fn (app, frame->ip); + frame->is_alloc_fn = app_is_alloc_fn (app, frame->frame); /* XXX juggle tree model signals */ if (frame->is_alloc_fn) { @@ -1107,50 +1111,49 @@ call_graph_store_get_iter (CallGraphStore *store, CallGraphFrame *frame, GtkTree } GList * -call_graph_store_get_parents (CallGraphStore *store, gulong ip) +call_graph_store_get_parents (CallGraphStore *store, const Frame *frame) { GList *list = NULL; - CallGraphFrame *frame; + CallGraphFrame *f; - g_assert (ip != 0); - frame = call_graph_store_lookup_by_ip (store, ip); - while (frame != NULL) { - CallGraphFrame *parent = frame->filter_parent; + f = call_graph_store_lookup_by_frame (store, frame); + while (f != NULL) { + CallGraphFrame *parent = f->filter_parent; if (parent == NULL) continue; - parent= call_graph_store_lookup_by_fn (store, parent->function); + parent= call_graph_store_lookup_by_fn (store, parent->frame->function); while (parent != NULL) { list = g_list_prepend (list, parent); parent = parent->next_by_fn; } - frame = frame->next_by_ip; + f = f->next_by_ip; } return list; } GList * -call_graph_store_get_children (CallGraphStore *store, gulong ip) +call_graph_store_get_children (CallGraphStore *store, const Frame *frame) { GList *list = NULL; - CallGraphFrame *frame; + CallGraphFrame *f; guint n; - if (ip == 0) { - frame = &store->root; - for (n = 0; n < frame->n_filter; n++) - list = g_list_prepend (list, frame->filter[n]); + if (frame == &_Everything) { + f = &store->root; + for (n = 0; n < f->n_filter; n++) + list = g_list_prepend (list, f->filter[n]); } else { - frame = call_graph_store_lookup_by_ip (store, ip); - while (frame != NULL) { + f = call_graph_store_lookup_by_frame (store, frame); + while (f != NULL) { - for (n = 0; n < frame->n_filter; n++) - list = g_list_prepend (list, frame->filter[n]); + for (n = 0; n < f->n_filter; n++) + list = g_list_prepend (list, f->filter[n]); - frame = frame->next_by_ip; + f = f->next_by_ip; } } |