From c3a5771da00357151e1382c78bbbee9d55935141 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 22 May 2023 15:32:31 -0700 Subject: [PATCH] libsysprof-analyze: create arrays for counter values And assign them to the SysprofDocumentCounter so that they can pick them up once we index/add them during counter loading of ctrset. --- .../sysprof-document-counter-private.h | 3 ++- src/libsysprof-analyze/sysprof-document-counter.c | 6 +++++- src/libsysprof-analyze/sysprof-document.c | 14 +++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-document-counter-private.h b/src/libsysprof-analyze/sysprof-document-counter-private.h index ac925d37..821d2bbc 100644 --- a/src/libsysprof-analyze/sysprof-document-counter-private.h +++ b/src/libsysprof-analyze/sysprof-document-counter-private.h @@ -28,6 +28,7 @@ SysprofDocumentCounter *_sysprof_document_counter_new (guint id, guint type, GRefString *category, GRefString *name, - GRefString *description); + GRefString *description, + GArray *values); G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-document-counter.c b/src/libsysprof-analyze/sysprof-document-counter.c index aeea429b..7cdb838b 100644 --- a/src/libsysprof-analyze/sysprof-document-counter.c +++ b/src/libsysprof-analyze/sysprof-document-counter.c @@ -28,6 +28,7 @@ struct _SysprofDocumentCounter GRefString *category; GRefString *description; GRefString *name; + GArray *values; guint id; guint type; }; @@ -53,6 +54,7 @@ sysprof_document_counter_finalize (GObject *object) g_clear_pointer (&self->category, g_ref_string_release); g_clear_pointer (&self->description, g_ref_string_release); g_clear_pointer (&self->name, g_ref_string_release); + g_clear_pointer (&self->values, g_array_unref); G_OBJECT_CLASS (sysprof_document_counter_parent_class)->finalize (object); } @@ -129,7 +131,8 @@ _sysprof_document_counter_new (guint id, guint type, GRefString *category, GRefString *name, - GRefString *description) + GRefString *description, + GArray *values) { SysprofDocumentCounter *self; @@ -139,6 +142,7 @@ _sysprof_document_counter_new (guint id, self->category = category; self->name = name; self->description = description; + self->values = values; return self; } diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index 6e2adc30..9679044d 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -52,7 +52,9 @@ struct _SysprofDocument GArray *frames; GMappedFile *mapped_file; const guint8 *base; + GListStore *counters; + GHashTable *counter_id_to_values; SysprofStrings *strings; @@ -212,6 +214,8 @@ sysprof_document_finalize (GObject *object) g_clear_pointer (&self->traceables, gtk_bitset_unref); g_clear_object (&self->counters); + g_clear_pointer (&self->counter_id_to_values, g_hash_table_unref); + g_clear_object (&self->mount_namespace); g_clear_object (&self->symbols); @@ -235,6 +239,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->counter_id_to_values = g_hash_table_new_full (NULL, NULL, NULL, + (GDestroyNotify)g_array_unref); self->ctrdefs = gtk_bitset_new_empty (); self->file_chunks = gtk_bitset_new_empty (); @@ -453,6 +459,7 @@ sysprof_document_load_counters (SysprofDocument *self) for (guint j = 0; j < n_counters; j++) { + g_autoptr(GArray) values = g_array_new (FALSE, FALSE, 8); const char *category; const char *name; const char *description; @@ -461,12 +468,17 @@ sysprof_document_load_counters (SysprofDocument *self) sysprof_document_ctrdef_get_counter (ctrdef, j, &id, &type, &category, &name, &description); + g_hash_table_insert (self->counter_id_to_values, + GUINT_TO_POINTER (id), + g_array_ref (values)); + 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))); + sysprof_strings_get (self->strings, description), + g_steal_pointer (&values))); } } while (gtk_bitset_iter_next (&iter, &i));