From 86f5fc6338156132c11494ca34e861836c24461d Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 20 Jun 2023 11:50:05 -0700 Subject: [PATCH] libsysprof-gtk: create depth chart for samples --- src/libsysprof-gtk/tests/test-charts.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libsysprof-gtk/tests/test-charts.c b/src/libsysprof-gtk/tests/test-charts.c index 4b01a4ff..ac41fc78 100644 --- a/src/libsysprof-gtk/tests/test-charts.c +++ b/src/libsysprof-gtk/tests/test-charts.c @@ -22,6 +22,7 @@ #include #include + #include #include @@ -39,11 +40,15 @@ main (int argc, g_autoptr(SysprofDocumentLoader) loader = NULL; g_autoptr(SysprofDocument) document = NULL; g_autoptr(SysprofSession) session = NULL; + g_autoptr(SysprofXYSeries) samples_series = NULL; + g_autoptr(GListModel) samples = NULL; g_autoptr(GError) error = NULL; + const SysprofTimeSpan *time_span; GtkWidget *chart; GtkWidget *layer; GtkWindow *window; GtkWidget *box; + guint n_samples; sysprof_clock_init (); @@ -74,6 +79,20 @@ main (int argc, g_error ("Failed to load document: %s", error->message); session = sysprof_session_new (document); + time_span = sysprof_document_get_time_span (document); + + /* Generate an XY Series using the stacktraces depth for Y */ + samples = sysprof_document_list_samples (document); + n_samples = g_list_model_get_n_items (samples); + samples_series = sysprof_xy_series_new (samples, time_span->begin_nsec, 0, time_span->end_nsec, 128); + for (guint i = 0; i < n_samples; i++) + { + g_autoptr(SysprofDocumentTraceable) sample = g_list_model_get_item (samples, i); + gint64 time = sysprof_document_frame_get_time (SYSPROF_DOCUMENT_FRAME (sample)); + guint depth = sysprof_document_traceable_get_stack_depth (sample); + + sysprof_xy_series_add (samples_series, time, depth, i); + } window = g_object_new (GTK_TYPE_WINDOW, "default-width", 800, @@ -92,8 +111,10 @@ main (int argc, chart = g_object_new (SYSPROF_TYPE_CHART, "session", session, "title", "Stack Traces", + "height-request", 128, NULL); layer = g_object_new (SYSPROF_TYPE_DEPTH_LAYER, + "series", samples_series, NULL); sysprof_chart_add_layer (SYSPROF_CHART (chart), SYSPROF_CHART_LAYER (layer));