Turn this function into a StackFunction.

Sun Nov  6 17:06:52 2005  Soeren Sandmann  <sandmann@redhat.com>

        * profile.c (add_trace_to_tree): Turn this function into a
        StackFunction.

        * stackstash.c (stack_node_foreach_trace): Make this function take
        a StackFunction, and reimplement with do_callback().
This commit is contained in:
Soeren Sandmann
2005-11-06 22:10:30 +00:00
committed by Søren Sandmann Pedersen
parent c0aed2a4de
commit c1bfbbf9b8
5 changed files with 31 additions and 58 deletions

View File

@ -1,3 +1,11 @@
Sun Nov 6 17:06:52 2005 Soeren Sandmann <sandmann@redhat.com>
* profile.c (add_trace_to_tree): Turn this function into a
StackFunction.
* stackstash.c (stack_node_foreach_trace): Make this function take
a StackFunction, and reimplement with do_callback().
Sat Nov 5 18:06:40 2005 Soeren Sandmann <sandmann@redhat.com> Sat Nov 5 18:06:40 2005 Soeren Sandmann <sandmann@redhat.com>
* profile.c (profile_create_descendants): Use callbacks from * profile.c (profile_create_descendants): Use callbacks from

View File

@ -29,15 +29,6 @@
typedef struct Node Node; typedef struct Node Node;
static void
update()
{
#if 0
while (g_main_pending())
g_main_iteration (FALSE);
#endif
}
struct Profile struct Profile
{ {
StackStash * stash; StackStash * stash;
@ -243,27 +234,24 @@ profile_new (StackStash *stash)
} }
static void static void
add_trace_to_tree (GSList *trace, gpointer data) add_trace_to_tree (GSList *trace, gint size, gpointer data)
{ {
GSList *list; GSList *list;
GPtrArray *nodes_to_unmark = g_ptr_array_new (); GPtrArray *nodes_to_unmark = g_ptr_array_new ();
ProfileDescendant *parent = NULL; ProfileDescendant *parent = NULL;
int i, len; int i, len;
ProfileDescendant **tree = data; ProfileDescendant **tree = data;
guint size = ((StackNode *)trace->data)->size;
trace = g_slist_reverse (g_slist_copy (trace)); trace = g_slist_reverse (g_slist_copy (trace));
for (list = trace; list != NULL; list = list->next) for (list = trace; list != NULL; list = list->next)
{ {
StackNode *node = list->data; gpointer address = list->data;
ProfileDescendant *match = NULL; ProfileDescendant *match = NULL;
update();
for (match = *tree; match != NULL; match = match->siblings) for (match = *tree; match != NULL; match = match->siblings)
{ {
if (match->name == node->address) if (match->name == address)
break; break;
} }
@ -276,7 +264,7 @@ add_trace_to_tree (GSList *trace, gpointer data)
seen_tree_node = NULL; seen_tree_node = NULL;
for (n = parent; n != NULL; n = n->parent) for (n = parent; n != NULL; n = n->parent)
{ {
if (n->name == node->address) if (n->name == address)
seen_tree_node = n; seen_tree_node = n;
} }
@ -300,7 +288,7 @@ add_trace_to_tree (GSList *trace, gpointer data)
{ {
match = g_new (ProfileDescendant, 1); match = g_new (ProfileDescendant, 1);
match->name = node->address; match->name = address;
match->non_recursion = 0; match->non_recursion = 0;
match->self = 0; match->self = 0;
match->children = NULL; match->children = NULL;

View File

@ -61,7 +61,6 @@ decorate_node (StackStash *stash,
/* FIXME: we will probably want to do this lazily, /* FIXME: we will probably want to do this lazily,
* and more efficiently (only walk the tree once). * and more efficiently (only walk the tree once).
*/ */
for (n = node->parent; n != NULL; n = n->parent) for (n = node->parent; n != NULL; n = n->parent)
{ {
if (n->address == node->address) if (n->address == node->address)
@ -128,23 +127,23 @@ stack_stash_add_trace (StackStash *stash,
static void static void
do_callback (StackNode *node, do_callback (StackNode *node,
GSList *trace, const GSList *trace,
StackFunction stack_func, StackFunction func,
gpointer data) gpointer data)
{ {
GSList link; GSList link;
if (!node) if (!node)
return; return;
link.next = trace; link.next = (GSList *)trace;
link.data = node->address; link.data = node->address;
do_callback (node->siblings, trace, stack_func, data);
do_callback (node->children, &link, stack_func, data);
if (node->size) if (node->size)
stack_func (&link, node->size, data); func (&link, node->size, data);
do_callback (node->children, &link, func, data);
do_callback (node->siblings, trace, func, data);
} }
void void
@ -155,40 +154,20 @@ stack_stash_foreach (StackStash *stash,
do_callback (stash->root, NULL, stack_func, data); do_callback (stash->root, NULL, stack_func, data);
} }
static void
do_node_callback (StackNode *node, const GSList *trace,
StackTraceFunction func,
gpointer data)
{
GSList link;
if (!node)
return;
link.next = (GSList *)trace;
link.data = node;
if (node->size)
func (&link, data);
do_node_callback (node->children, &link, func, data);
do_node_callback (node->siblings, trace, func, data);
}
void void
stack_node_foreach_trace (StackNode *node, stack_node_foreach_trace (StackNode *node,
StackTraceFunction func, StackFunction func,
gpointer data) gpointer data)
{ {
GSList link; GSList link;
link.next = NULL; link.next = NULL;
link.data = node; link.data = node->address;
if (node->size) if (node->size)
func (&link, data); func (&link, node->size, data);
do_node_callback (node->children, &link, func, data); do_callback (node->children, &link, func, data);
} }
static void static void

View File

@ -54,16 +54,14 @@ void stack_stash_add_trace (StackStash *stash,
void stack_stash_foreach (StackStash *stash, void stack_stash_foreach (StackStash *stash,
StackFunction stack_func, StackFunction stack_func,
gpointer data); gpointer data);
void stack_node_foreach_trace (StackNode *node,
StackFunction stack_func,
gpointer data);
StackNode *stack_stash_find_node (StackStash *stash, StackNode *stack_stash_find_node (StackStash *stash,
gpointer address); gpointer address);
/* FIXME: should probably return a list */ /* FIXME: should probably return a list */
void stack_node_list_leaves (StackNode *node, void stack_node_list_leaves (StackNode *node,
GList **leaves); GList **leaves);
typedef void (* StackTraceFunction) (GSList *trace, gpointer data);
void stack_node_foreach_trace (StackNode *node,
StackTraceFunction func,
gpointer data);
typedef void (* StackNodeFunc) (StackNode *node, typedef void (* StackNodeFunc) (StackNode *node,
gpointer data); gpointer data);
void stack_stash_foreach_by_address (StackStash *stash, void stack_stash_foreach_by_address (StackStash *stash,

View File

@ -1003,7 +1003,7 @@ on_object_selection_changed (GtkTreeSelection *selection,
set_busy (app->main_window, TRUE); set_busy (app->main_window, TRUE);
gdk_window_process_all_updates (); gdk_window_process_all_updates (); /* Display updated selection */
fill_descendants_tree (app); fill_descendants_tree (app);
fill_callers_list (app); fill_callers_list (app);