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_".
This commit is contained in:
Christian Hergert
2023-07-05 16:53:44 -07:00
parent 9263624fa0
commit 36aa121607
2 changed files with 35 additions and 0 deletions

View File

@ -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

View File

@ -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,