From 36aa12160794aa5ec1a5a22d852e652829c0b389 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 5 Jul 2023 16:53:44 -0700 Subject: [PATCH] libsysprof-analyze: helper to list traceables by string search This will let you take a callgraph and create a new GListModel containing the original traceables but filtered with something like "_sysprof_*" to get all traceables containing functions starting with "_sysprof_". --- src/libsysprof-analyze/sysprof-callgraph.c | 32 ++++++++++++++++++++++ src/libsysprof-analyze/sysprof-callgraph.h | 3 ++ 2 files changed, 35 insertions(+) diff --git a/src/libsysprof-analyze/sysprof-callgraph.c b/src/libsysprof-analyze/sysprof-callgraph.c index 555345c6..b6461dad 100644 --- a/src/libsysprof-analyze/sysprof-callgraph.c +++ b/src/libsysprof-analyze/sysprof-callgraph.c @@ -532,6 +532,38 @@ sysprof_callgraph_list_traceables_for_symbol (SysprofCallgraph *self, return G_LIST_MODEL (g_list_store_new (SYSPROF_TYPE_DOCUMENT_TRACEABLE)); } +GListModel * +sysprof_callgraph_list_traceables_for_symbols_matching (SysprofCallgraph *self, + const char *pattern) +{ + g_autoptr(GPatternSpec) pspec = NULL; + g_autoptr(EggBitset) bitset = NULL; + + g_return_val_if_fail (SYSPROF_IS_CALLGRAPH (self), NULL); + + if (pattern == NULL || pattern[0] == 0) + return g_object_ref (self->traceables); + + pspec = g_pattern_spec_new (pattern); + bitset = egg_bitset_new_empty (); + + for (guint i = 0; i < self->symbols->len; i++) + { + SysprofSymbol *symbol = g_ptr_array_index (self->symbols, i); + const char *name = sysprof_symbol_get_name (symbol); + + if (g_pattern_spec_match (pspec, strlen (name), name, NULL)) + { + SysprofCallgraphSummary *summary = g_hash_table_lookup (self->symbol_to_summary, symbol); + + if (summary != NULL) + egg_bitset_union (bitset, summary->traceables); + } + } + + return _sysprof_document_bitset_index_new (self->traceables, bitset); +} + /** * sysprof_callgraph_list_symbols: * @self: a #SysprofCallgraph diff --git a/src/libsysprof-analyze/sysprof-callgraph.h b/src/libsysprof-analyze/sysprof-callgraph.h index 2873effa..4f476d31 100644 --- a/src/libsysprof-analyze/sysprof-callgraph.h +++ b/src/libsysprof-analyze/sysprof-callgraph.h @@ -79,6 +79,9 @@ SYSPROF_AVAILABLE_IN_ALL GListModel *sysprof_callgraph_list_traceables_for_symbol (SysprofCallgraph *self, SysprofSymbol *symbol); SYSPROF_AVAILABLE_IN_ALL +GListModel *sysprof_callgraph_list_traceables_for_symbols_matching (SysprofCallgraph *self, + const char *pattern); +SYSPROF_AVAILABLE_IN_ALL void sysprof_callgraph_descendants_async (SysprofCallgraph *self, SysprofSymbol *symbol, GCancellable *cancellable,