mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
reset the collector after generating the profile.
2006-11-20 Soren Sandmann <sandmann@daimi.au.dk> * sysprof.c (ensure_profile): reset the collector after generating the profile. * stackstash.c (struct StackStash): Add cached_nodes and blocks. (stack_node_new): Allocate stack nodes in blocks.
This commit is contained in:
committed by
Søren Sandmann Pedersen
parent
cce917856b
commit
d1a082ffec
@ -1,3 +1,11 @@
|
|||||||
|
2006-11-20 Soren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
|
* sysprof.c (ensure_profile): reset the collector after generating
|
||||||
|
the profile.
|
||||||
|
|
||||||
|
* stackstash.c (struct StackStash): Add cached_nodes and blocks.
|
||||||
|
(stack_node_new): Allocate stack nodes in blocks.
|
||||||
|
|
||||||
2006-11-19 Soren Sandmann <sandmann@redhat.com>
|
2006-11-19 Soren Sandmann <sandmann@redhat.com>
|
||||||
|
|
||||||
* profile.c (profile_load): Use stack allocated variables to avoid
|
* profile.c (profile_load): Use stack allocated variables to avoid
|
||||||
|
|||||||
@ -398,7 +398,7 @@ collector_create_profile (Collector *collector)
|
|||||||
profile = profile_new (info.resolved_stash);
|
profile = profile_new (info.resolved_stash);
|
||||||
|
|
||||||
stack_stash_unref (info.resolved_stash);
|
stack_stash_unref (info.resolved_stash);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -205,7 +205,7 @@ profile_load (const char *filename, GError **err)
|
|||||||
n = sfile_begin_get_list (input, "nodes");
|
n = sfile_begin_get_list (input, "nodes");
|
||||||
for (i = 0; i < n; ++i)
|
for (i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
StackNode *node = stack_node_new ();
|
StackNode *node = stack_node_new (profile->stash);
|
||||||
gboolean toplevel;
|
gboolean toplevel;
|
||||||
gint32 size;
|
gint32 size;
|
||||||
gint32 total;
|
gint32 total;
|
||||||
|
|||||||
104
stackstash.c
104
stackstash.c
@ -25,12 +25,36 @@ struct StackStash
|
|||||||
StackNode * root;
|
StackNode * root;
|
||||||
GHashTable * nodes_by_data;
|
GHashTable * nodes_by_data;
|
||||||
GDestroyNotify destroy;
|
GDestroyNotify destroy;
|
||||||
|
|
||||||
|
StackNode * cached_nodes;
|
||||||
|
GPtrArray * blocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
StackNode *
|
StackNode *
|
||||||
stack_node_new (void)
|
stack_node_new (StackStash *stash)
|
||||||
{
|
{
|
||||||
StackNode *node = g_new (StackNode, 1);
|
StackNode *node;
|
||||||
|
|
||||||
|
if (!stash->cached_nodes)
|
||||||
|
{
|
||||||
|
#define BLOCK_SIZE 32768
|
||||||
|
#define N_NODES (BLOCK_SIZE / sizeof (StackNode))
|
||||||
|
|
||||||
|
StackNode *block = g_malloc (BLOCK_SIZE);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < N_NODES; ++i)
|
||||||
|
{
|
||||||
|
block[i].next = stash->cached_nodes;
|
||||||
|
stash->cached_nodes = &(block[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_add (stash->blocks, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
node = stash->cached_nodes;
|
||||||
|
stash->cached_nodes = node->next;
|
||||||
|
|
||||||
node->siblings = NULL;
|
node->siblings = NULL;
|
||||||
node->children = NULL;
|
node->children = NULL;
|
||||||
node->address = NULL;
|
node->address = NULL;
|
||||||
@ -38,6 +62,7 @@ stack_node_new (void)
|
|||||||
node->size = 0;
|
node->size = 0;
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
node->total = 0;
|
node->total = 0;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +76,9 @@ create_stack_stash (GDestroyNotify destroy)
|
|||||||
stash->nodes_by_data = g_hash_table_new (g_direct_hash, g_direct_equal);
|
stash->nodes_by_data = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||||
stash->ref_count = 1;
|
stash->ref_count = 1;
|
||||||
stash->destroy = destroy;
|
stash->destroy = destroy;
|
||||||
|
|
||||||
|
stash->cached_nodes = NULL;
|
||||||
|
stash->blocks = g_ptr_array_new ();
|
||||||
|
|
||||||
return stash;
|
return stash;
|
||||||
}
|
}
|
||||||
@ -62,6 +90,38 @@ stack_stash_new (GDestroyNotify destroy)
|
|||||||
return create_stack_stash (destroy);
|
return create_stack_stash (destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_key (gpointer key,
|
||||||
|
gpointer value,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GDestroyNotify destroy = data;
|
||||||
|
|
||||||
|
destroy (key);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stack_stash_free (StackStash *stash)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (stash->destroy)
|
||||||
|
{
|
||||||
|
g_hash_table_foreach (stash->nodes_by_data, free_key,
|
||||||
|
stash->destroy);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_hash_table_destroy (stash->nodes_by_data);
|
||||||
|
|
||||||
|
for (i = 0; i < stash->blocks->len; ++i)
|
||||||
|
g_free (stash->blocks->pdata[i]);
|
||||||
|
|
||||||
|
g_ptr_array_free (stash->blocks, TRUE);
|
||||||
|
|
||||||
|
g_free (stash);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
decorate_node (StackStash *stash,
|
decorate_node (StackStash *stash,
|
||||||
StackNode *node)
|
StackNode *node)
|
||||||
@ -118,7 +178,7 @@ stack_stash_add_trace (StackStash *stash,
|
|||||||
|
|
||||||
if (!match)
|
if (!match)
|
||||||
{
|
{
|
||||||
match = stack_node_new ();
|
match = stack_node_new (stash);
|
||||||
match->address = (gpointer)addrs[i];
|
match->address = (gpointer)addrs[i];
|
||||||
match->siblings = *location;
|
match->siblings = *location;
|
||||||
match->parent = parent;
|
match->parent = parent;
|
||||||
@ -186,44 +246,6 @@ stack_node_foreach_trace (StackNode *node,
|
|||||||
do_callback (node->children, &link, func, data);
|
do_callback (node->children, &link, func, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
stack_node_free (StackNode *node)
|
|
||||||
{
|
|
||||||
if (!node)
|
|
||||||
return;
|
|
||||||
|
|
||||||
stack_node_free (node->siblings);
|
|
||||||
stack_node_free (node->children);
|
|
||||||
|
|
||||||
g_free (node);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_key (gpointer key,
|
|
||||||
gpointer value,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GDestroyNotify destroy = data;
|
|
||||||
|
|
||||||
destroy (key);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
stack_stash_free (StackStash *stash)
|
|
||||||
{
|
|
||||||
stack_node_free (stash->root);
|
|
||||||
|
|
||||||
if (stash->destroy)
|
|
||||||
{
|
|
||||||
g_hash_table_foreach (stash->nodes_by_data, free_key,
|
|
||||||
stash->destroy);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_hash_table_destroy (stash->nodes_by_data);
|
|
||||||
|
|
||||||
g_free (stash);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
stack_stash_unref (StackStash *stash)
|
stack_stash_unref (StackStash *stash)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -49,7 +49,7 @@ typedef void (* StackNodeFunc) (StackNode *node,
|
|||||||
|
|
||||||
/* Stach */
|
/* Stach */
|
||||||
StackStash *stack_stash_new (GDestroyNotify destroy);
|
StackStash *stack_stash_new (GDestroyNotify destroy);
|
||||||
StackNode * stack_node_new (void);
|
StackNode * stack_node_new (StackStash *stash);
|
||||||
void stack_stash_add_trace (StackStash *stash,
|
void stack_stash_add_trace (StackStash *stash,
|
||||||
gulong *addrs,
|
gulong *addrs,
|
||||||
gint n_addrs,
|
gint n_addrs,
|
||||||
|
|||||||
@ -656,6 +656,7 @@ ensure_profile (Application *app)
|
|||||||
app->profile = collector_create_profile (app->collector);
|
app->profile = collector_create_profile (app->collector);
|
||||||
|
|
||||||
collector_stop (app->collector);
|
collector_stop (app->collector);
|
||||||
|
collector_reset (app->collector);
|
||||||
|
|
||||||
fill_lists (app);
|
fill_lists (app);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user