libsysprof-analyze: index and list counters from capture

This commit is contained in:
Christian Hergert
2023-05-22 15:22:35 -07:00
parent aaf7530961
commit 8f98af9b12
4 changed files with 113 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "sysprof-document-bitset-index-private.h"
#include "sysprof-document-counter-private.h"
#include "sysprof-document-ctrdef.h"
#include "sysprof-document-file-chunk.h"
#include "sysprof-document-file-private.h"
#include "sysprof-document-frame-private.h"
@ -51,6 +52,7 @@ struct _SysprofDocument
GArray *frames;
GMappedFile *mapped_file;
const guint8 *base;
GListStore *counters;
SysprofStrings *strings;
@ -209,6 +211,7 @@ sysprof_document_finalize (GObject *object)
g_clear_pointer (&self->processes, gtk_bitset_unref);
g_clear_pointer (&self->traceables, gtk_bitset_unref);
g_clear_object (&self->counters);
g_clear_object (&self->mount_namespace);
g_clear_object (&self->symbols);
@ -231,6 +234,8 @@ sysprof_document_init (SysprofDocument *self)
self->frames = g_array_new (FALSE, FALSE, sizeof (SysprofDocumentFramePointer));
self->counters = g_list_store_new (SYSPROF_TYPE_DOCUMENT_COUNTER);
self->ctrdefs = gtk_bitset_new_empty ();
self->file_chunks = gtk_bitset_new_empty ();
self->jitmaps = gtk_bitset_new_empty ();
@ -431,18 +436,43 @@ sysprof_document_load_overlays (SysprofDocument *self)
static void
sysprof_document_load_counters (SysprofDocument *self)
{
g_autoptr(GPtrArray) counters = NULL;
GtkBitsetIter iter;
guint i;
g_assert (SYSPROF_IS_DOCUMENT (self));
counters = g_ptr_array_new_with_free_func (g_object_unref);
if (gtk_bitset_iter_init_first (&iter, self->ctrdefs, &i))
{
do
{
g_autoptr(SysprofDocumentCtrdef) ctrdef = g_list_model_get_item (G_LIST_MODEL (self), i);
guint n_counters = sysprof_document_ctrdef_get_n_counters (ctrdef);
for (guint j = 0; j < n_counters; j++)
{
const char *category;
const char *name;
const char *description;
guint id;
guint type;
sysprof_document_ctrdef_get_counter (ctrdef, j, &id, &type, &category, &name, &description);
g_ptr_array_add (counters,
_sysprof_document_counter_new (id,
type,
sysprof_strings_get (self->strings, category),
sysprof_strings_get (self->strings, name),
sysprof_strings_get (self->strings, description)));
}
}
while (gtk_bitset_iter_next (&iter, &i));
if (counters->len > 0)
g_list_store_splice (self->counters, 0, 0, counters->pdata, counters->len);
}
}
@ -927,3 +957,17 @@ sysprof_document_symbolize_traceable (SysprofDocument *self,
return n_addresses;
}
/**
* sysprof_document_list_counters:
* @self: a #SysprofDocument
*
* Returns: (transfer full): a #GListModel of #SysprofDocumentCounter
*/
GListModel *
sysprof_document_list_counters (SysprofDocument *self)
{
g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL);
return g_object_ref (G_LIST_MODEL (self->counters));
}

View File

@ -47,6 +47,8 @@ GListModel *sysprof_document_list_processes (SysprofDocument
SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_jitmaps (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL
GListModel *sysprof_document_list_counters (SysprofDocument *self);
SYSPROF_AVAILABLE_IN_ALL
guint sysprof_document_symbolize_traceable (SysprofDocument *self,
SysprofDocumentTraceable *traceable,
SysprofSymbol **symbols,

View File

@ -14,6 +14,7 @@ libsysprof_analyze_testsuite_c_args = [
libsysprof_analyze_testsuite = {
'test-capture-model' : {'skip': true},
'test-elf-loader' : {'skip': true},
'test-list-counters' : {'skip': true},
'test-list-files' : {'skip': true},
'test-list-jitmap' : {'skip': true},
'test-print-file' : {'skip': true},

View File

@ -0,0 +1,66 @@
/* test-list-counters.c
*
* 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
*/
#include <sysprof-analyze.h>
#include "sysprof-document-private.h"
int
main (int argc,
char *argv[])
{
g_autoptr(SysprofDocumentLoader) loader = NULL;
g_autoptr(SysprofDocument) document = NULL;
g_autoptr(GListModel) model = NULL;
g_autoptr(GError) error = NULL;
guint n_items;
if (argc < 2)
{
g_printerr ("usage: %s CAPTURE_FILE\n", argv[0]);
return 1;
}
loader = sysprof_document_loader_new (argv[1]);
sysprof_document_loader_set_symbolizer (loader, sysprof_no_symbolizer_get ());
if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
{
g_printerr ("Failed to open capture: %s\n", error->message);
return 1;
}
model = sysprof_document_list_counters (document);
n_items = g_list_model_get_n_items (model);
for (guint i = 0; i < n_items; i++)
{
g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (model, i);
g_print ("%d<%s> %s.%s: %s\n",
sysprof_document_counter_get_id (counter),
sysprof_document_counter_get_value_type (counter) == G_TYPE_INT64 ? "i64" : "f64",
sysprof_document_counter_get_category (counter),
sysprof_document_counter_get_name (counter),
sysprof_document_counter_get_description (counter));
}
return 0;
}