libsysprof: simplify summary generation

This still doesn't actually do anything, just the scaffolding.
This commit is contained in:
Christian Hergert
2023-07-20 16:36:29 -07:00
parent 070b7f5907
commit a75429241e
3 changed files with 67 additions and 17 deletions

View File

@ -24,7 +24,7 @@
#include "sysprof-callgraph-private.h"
#include "sysprof-callgraph-frame-private.h"
#include "sysprof-category-summary.h"
#include "sysprof-category-summary-private.h"
#include "sysprof-enums.h"
#include "sysprof-symbol-private.h"
#include "sysprof-document-bitset-index-private.h"
@ -510,13 +510,17 @@ sysprof_callgraph_frame_get_category (SysprofCallgraphFrame *self)
return SYSPROF_CALLGRAPH_CATEGORY_UNCATEGORIZED;
}
typedef struct _Summary
{
guint64 count;
} Summary;
static void
summarize_node (const SysprofCallgraphNode *node,
GListStore *store,
GHashTable *category_to_summary)
Summary *summaries)
{
for (const SysprofCallgraphNode *iter = node->children; iter; iter = iter->next)
summarize_node (iter, store, category_to_summary);
summarize_node (iter, summaries);
}
static void
@ -526,17 +530,36 @@ sysprof_callgraph_frame_summarize (GTask *task,
GCancellable *cancellable)
{
SysprofCallgraphFrame *self = source_object;
g_autoptr(GHashTable) category_to_summary = NULL;
g_autofree Summary *summaries = NULL;
g_autoptr(GListStore) store = NULL;
guint64 total = 0;
g_assert (G_IS_TASK (task));
g_assert (SYSPROF_IS_CALLGRAPH_FRAME (self));
g_assert (SYSPROF_IS_CALLGRAPH (task_data));
store = g_list_store_new (G_TYPE_OBJECT);
category_to_summary = g_hash_table_new (NULL, NULL);
summaries = g_new0 (Summary, SYSPROF_CALLGRAPH_CATEGORY_LAST);
summarize_node (self->node, summaries);
summarize_node (self->node, store, category_to_summary);
store = g_list_store_new (G_TYPE_OBJECT);
for (guint i = 0; i < SYSPROF_CALLGRAPH_CATEGORY_LAST; i++)
total += summaries[i].count;
for (guint i = 0; i < SYSPROF_CALLGRAPH_CATEGORY_LAST; i++)
{
g_autoptr(SysprofCategorySummary) summary = NULL;
if (summaries[i].count == 0)
continue;
summary = g_object_new (SYSPROF_TYPE_CATEGORY_SUMMARY, NULL);
summary->category = i;
summary->total = total;
summary->count = summaries[i].count;
g_list_store_append (store, summary);
}
g_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
}

View File

@ -0,0 +1,35 @@
/* sysprof-category-summary-private.h
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include "sysprof-category-summary.h"
G_BEGIN_DECLS
struct _SysprofCategorySummary
{
GObject parent_instance;
SysprofCallgraphCategory category;
guint64 count;
guint64 total;
};
G_END_DECLS

View File

@ -20,17 +20,9 @@
#include "config.h"
#include "sysprof-category-summary.h"
#include "sysprof-category-summary-private.h"
#include "sysprof-enums.h"
struct _SysprofCategorySummary
{
GObject parent_instance;
SysprofCallgraphCategory category;
guint64 count;
guint64 total;
};
enum {
PROP_0,
PROP_CATEGORY,