mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 23:20:54 +00:00
sysprof: fix double accounting in recursion
We don't want to cost-account the same summary multiple times while walking up to the root. Otherwise, you can get items which come out to a percentage of > 100% which is not exactly what you're expecting to see as a normalized value.
This commit is contained in:
@ -24,6 +24,8 @@
|
|||||||
#include "sysprof-weighted-callgraph-view.h"
|
#include "sysprof-weighted-callgraph-view.h"
|
||||||
#include "sysprof-progress-cell-private.h"
|
#include "sysprof-progress-cell-private.h"
|
||||||
|
|
||||||
|
#include "sysprof-callgraph-private.h"
|
||||||
|
|
||||||
struct _SysprofWeightedCallgraphView
|
struct _SysprofWeightedCallgraphView
|
||||||
{
|
{
|
||||||
SysprofCallgraphView parent_instance;
|
SysprofCallgraphView parent_instance;
|
||||||
@ -57,6 +59,21 @@ typedef struct _AugmentWeight
|
|||||||
|
|
||||||
G_DEFINE_FINAL_TYPE (SysprofWeightedCallgraphView, sysprof_weighted_callgraph_view, SYSPROF_TYPE_CALLGRAPH_VIEW)
|
G_DEFINE_FINAL_TYPE (SysprofWeightedCallgraphView, sysprof_weighted_callgraph_view, SYSPROF_TYPE_CALLGRAPH_VIEW)
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
seen_symbol (const SysprofCallgraphNode *node,
|
||||||
|
const SysprofCallgraphNode *toplevel)
|
||||||
|
{
|
||||||
|
for (const SysprofCallgraphNode *iter = toplevel;
|
||||||
|
iter != node;
|
||||||
|
iter = iter->parent)
|
||||||
|
{
|
||||||
|
if (iter->summary == node->summary)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
augment_weight (SysprofCallgraph *callgraph,
|
augment_weight (SysprofCallgraph *callgraph,
|
||||||
SysprofCallgraphNode *node,
|
SysprofCallgraphNode *node,
|
||||||
@ -64,6 +81,7 @@ augment_weight (SysprofCallgraph *callgraph,
|
|||||||
gboolean summarize,
|
gboolean summarize,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
SysprofCallgraphNode *iter;
|
||||||
AugmentWeight *cur;
|
AugmentWeight *cur;
|
||||||
AugmentWeight *sum;
|
AugmentWeight *sum;
|
||||||
|
|
||||||
@ -83,16 +101,14 @@ augment_weight (SysprofCallgraph *callgraph,
|
|||||||
sum->total += 1;
|
sum->total += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (node = sysprof_callgraph_node_parent (node);
|
for (iter = node->parent; iter; iter = iter->parent)
|
||||||
node != NULL;
|
|
||||||
node = sysprof_callgraph_node_parent (node))
|
|
||||||
{
|
{
|
||||||
cur = sysprof_callgraph_get_augment (callgraph, node);
|
cur = sysprof_callgraph_get_augment (callgraph, iter);
|
||||||
cur->total += 1;
|
cur->total += 1;
|
||||||
|
|
||||||
if (summarize)
|
if (summarize && !seen_symbol (iter, node))
|
||||||
{
|
{
|
||||||
sum = sysprof_callgraph_get_summary_augment (callgraph, node);
|
sum = sysprof_callgraph_get_summary_augment (callgraph, iter);
|
||||||
sum->total += 1;
|
sum->total += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +186,7 @@ functions_get_total_fraction (GObject *item)
|
|||||||
{
|
{
|
||||||
SysprofCallgraph *callgraph = sysprof_callgraph_symbol_get_callgraph (sym);
|
SysprofCallgraph *callgraph = sysprof_callgraph_symbol_get_callgraph (sym);
|
||||||
AugmentWeight *sum = sysprof_callgraph_symbol_get_summary_augment (sym);
|
AugmentWeight *sum = sysprof_callgraph_symbol_get_summary_augment (sym);
|
||||||
AugmentWeight *root = sysprof_callgraph_get_augment (callgraph, NULL);
|
AugmentWeight *root = sysprof_callgraph_get_summary_augment (callgraph, NULL);
|
||||||
|
|
||||||
return sum->total / (double)root->total;
|
return sum->total / (double)root->total;
|
||||||
}
|
}
|
||||||
@ -189,7 +205,7 @@ functions_get_self_fraction (GObject *item)
|
|||||||
{
|
{
|
||||||
SysprofCallgraph *callgraph = sysprof_callgraph_symbol_get_callgraph (sym);
|
SysprofCallgraph *callgraph = sysprof_callgraph_symbol_get_callgraph (sym);
|
||||||
AugmentWeight *sum = sysprof_callgraph_symbol_get_summary_augment (sym);
|
AugmentWeight *sum = sysprof_callgraph_symbol_get_summary_augment (sym);
|
||||||
AugmentWeight *root = sysprof_callgraph_get_augment (callgraph, NULL);
|
AugmentWeight *root = sysprof_callgraph_get_summary_augment (callgraph, NULL);
|
||||||
|
|
||||||
return sum->size / (double)root->total;
|
return sum->size / (double)root->total;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user