libsysprof-analyze: add sysprof_document_find_counter()

This allows finding a specific counter without having to traverse them
all from consumer code.
This commit is contained in:
Christian Hergert
2023-06-29 10:36:40 -07:00
parent 436a03a0f5
commit 756e647e21
2 changed files with 43 additions and 0 deletions

View File

@ -1738,3 +1738,40 @@ sysprof_document_get_time_span (SysprofDocument *self)
return &self->time_span;
}
/**
* sysprof_document_find_counter:
* @self: a #SysprofDocument
* @category: the category of the counter
* @name: the name of the counter
*
* Finds the first counter matching @category and @name.
*
* Returns: (transfer full) (nullable): a #SysprofDocumentCounter or %NULL
*/
SysprofDocumentCounter *
sysprof_document_find_counter (SysprofDocument *self,
const char *category,
const char *name)
{
g_autoptr(GListModel) counters = NULL;
guint n_items;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL);
g_return_val_if_fail (category != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
counters = sysprof_document_list_counters (self);
n_items = g_list_model_get_n_items (counters);
for (guint i = 0; i < n_items; i++)
{
g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (counters, i);
if (g_strcmp0 (category, sysprof_document_counter_get_category (counter)) == 0 &&
g_strcmp0 (name, sysprof_document_counter_get_name (counter)) == 0)
return g_steal_pointer (&counter);
}
return NULL;
}

View File

@ -25,6 +25,7 @@
#include <sysprof-capture.h>
#include "sysprof-callgraph.h"
#include "sysprof-document-counter.h"
#include "sysprof-document-file.h"
#include "sysprof-document-traceable.h"
#include "sysprof-mark-catalog.h"
@ -62,6 +63,11 @@ GListModel *sysprof_document_list_marks (SysprofDocume
SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_catalog_marks (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL
SysprofDocumentCounter
*sysprof_document_find_counter (SysprofDocument *self,
const char *category,
const char *name);
SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_symbols_in_traceable (SysprofDocument *self,
SysprofDocumentTraceable *traceable);
SYSPROF_AVAILABLE_IN_ALL