From 2e0f046390cf180022c11e318fe43a72fc2a7651 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 5 Jul 2023 16:07:07 -0700 Subject: [PATCH] libsysprof-analyze: add aggregate marks by group This is handy so that we can show aggregate results in other places without using a FlattenListModel which can mess up event ordering. --- src/libsysprof-analyze/sysprof-document.c | 39 ++++++++++++++++++++++- src/libsysprof-analyze/sysprof-document.h | 3 ++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index 512647dd..3702232a 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -1311,7 +1311,7 @@ sysprof_document_list_traceables (SysprofDocument *self) * Gets a #GListModel containing #SysprofDocumentMark found within * the #SysprofDocument. * - * Returns: (transfer full): a #GListModel of #SysprofDocumentAllocation + * Returns: (transfer full): a #GListModel of #SysprofDocumentMark */ GListModel * sysprof_document_list_marks (SysprofDocument *self) @@ -1321,6 +1321,43 @@ sysprof_document_list_marks (SysprofDocument *self) return _sysprof_document_bitset_index_new (G_LIST_MODEL (self), self->marks); } +/** + * sysprof_document_list_marks_by_group: + * @self: a #SysprofDocument + * @group: the name of the group + * + * Gets a #GListModel containing #SysprofDocumentMark found within + * the #SysprofDocument which are part of @group. + * + * Returns: (transfer full): a #GListModel of #SysprofDocumentMark + */ +GListModel * +sysprof_document_list_marks_by_group (SysprofDocument *self, + const char *group) +{ + g_autoptr(EggBitset) bitset = NULL; + GHashTable *names; + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL); + g_return_val_if_fail (group != NULL, NULL); + + bitset = egg_bitset_new_empty (); + + if ((names = g_hash_table_lookup (self->mark_groups, group))) + { + GHashTableIter iter; + const char *name; + EggBitset *indices; + + g_hash_table_iter_init (&iter, names); + + while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&indices)) + egg_bitset_union (bitset, indices); + } + + return _sysprof_document_bitset_index_new (G_LIST_MODEL (self), bitset); +} + /** * sysprof_document_list_allocations: * @self: a #SysprofDocument diff --git a/src/libsysprof-analyze/sysprof-document.h b/src/libsysprof-analyze/sysprof-document.h index 10e46815..b7ca962e 100644 --- a/src/libsysprof-analyze/sysprof-document.h +++ b/src/libsysprof-analyze/sysprof-document.h @@ -63,6 +63,9 @@ GListModel *sysprof_document_list_counters (SysprofDocume SYSPROF_AVAILABLE_IN_ALL GListModel *sysprof_document_list_marks (SysprofDocument *self); SYSPROF_AVAILABLE_IN_ALL +GListModel *sysprof_document_list_marks_by_group (SysprofDocument *self, + const char *group); +SYSPROF_AVAILABLE_IN_ALL GListModel *sysprof_document_catalog_marks (SysprofDocument *self); SYSPROF_AVAILABLE_IN_ALL SysprofDocumentCounter