From f0ca95b38beb5e6d89f6e8a33792113f3de27a0a Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 21 Jul 2023 15:53:09 -0700 Subject: [PATCH] sysprof: use layer factories to create charts --- src/sysprof/sysprof-cpu-section.c | 67 -------------- src/sysprof/sysprof-cpu-section.ui | 144 +++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 67 deletions(-) diff --git a/src/sysprof/sysprof-cpu-section.c b/src/sysprof/sysprof-cpu-section.c index a8cb099a..5aa85bd8 100644 --- a/src/sysprof/sysprof-cpu-section.c +++ b/src/sysprof/sysprof-cpu-section.c @@ -41,70 +41,6 @@ struct _SysprofCpuSection G_DEFINE_FINAL_TYPE (SysprofCpuSection, sysprof_cpu_section, SYSPROF_TYPE_SECTION) -static GtkWidget * -create_counter_chart (SysprofDocumentCounter *counter, - SysprofAxis *x_axis) -{ - g_autoptr(SysprofValueAxis) y_axis = NULL; - g_autoptr(SysprofSeries) series = NULL; - SysprofChartLayer *layer; - SysprofChart *chart; - - g_assert (SYSPROF_IS_DOCUMENT_COUNTER (counter)); - - series = sysprof_xy_series_new (NULL, - g_object_ref (G_LIST_MODEL (counter)), - gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_COUNTER_VALUE, NULL, "time"), - gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_COUNTER_VALUE, NULL, "value-double")); - y_axis = g_object_new (SYSPROF_TYPE_VALUE_AXIS, - "min-value", 0., - "max-value", 100., - NULL); - layer = g_object_new (SYSPROF_TYPE_LINE_LAYER, - "fill", TRUE, - "series", series, - "x-axis", x_axis, - "y-axis", y_axis, - "spline", TRUE, - NULL); - chart = g_object_new (SYSPROF_TYPE_CHART, - "height-request", 20, - NULL); - sysprof_chart_add_layer (chart, layer); - - return GTK_WIDGET (chart); -} - -static void -sysprof_cpu_section_session_set (SysprofSection *section, - SysprofSession *session) -{ - SysprofCpuSection *self = (SysprofCpuSection *)section; - g_autoptr(SysprofDocumentCounter) combined_cpu_usage = NULL; - SysprofDocument *document; - SysprofAxis *x_axis; - - g_assert (SYSPROF_IS_CPU_SECTION (self)); - g_assert (!session || SYSPROF_IS_SESSION (session)); - - if (!session) - return; - - document = sysprof_session_get_document (session); - x_axis = sysprof_session_get_visible_time_axis (session); - - if ((combined_cpu_usage = sysprof_document_find_counter (document, "CPU Percent", "Combined"))) - { - g_autoptr(SysprofTimeFilterModel) filter = sysprof_time_filter_model_new (NULL, NULL); - - sysprof_time_filter_model_set_model (filter, G_LIST_MODEL (combined_cpu_usage)); - g_object_bind_property (session, "visible-time", filter, "time-span", G_BINDING_SYNC_CREATE); - - sysprof_time_scrubber_add_chart (self->scrubber, - create_counter_chart (combined_cpu_usage, x_axis)); - } -} - static void sysprof_cpu_section_dispose (GObject *object) { @@ -120,12 +56,9 @@ sysprof_cpu_section_class_init (SysprofCpuSectionClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofSectionClass *section_class = SYSPROF_SECTION_CLASS (klass); object_class->dispose = sysprof_cpu_section_dispose; - section_class->session_set = sysprof_cpu_section_session_set; - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-cpu-section.ui"); gtk_widget_class_bind_template_child (widget_class, SysprofCpuSection, column_view); gtk_widget_class_bind_template_child (widget_class, SysprofCpuSection, scrubber); diff --git a/src/sysprof/sysprof-cpu-section.ui b/src/sysprof/sysprof-cpu-section.ui index 1a5c1c6d..08cadf6a 100644 --- a/src/sysprof/sysprof-cpu-section.ui +++ b/src/sysprof/sysprof-cpu-section.ui @@ -9,6 +9,150 @@ SysprofCpuSection + + + + SysprofCpuSection + + 32 + + + + + + SysprofCpuSection + + + + + + exact + CPU Percent/Combined + + + + + + + + + + + + + +]]> + + + + + + + + + SysprofCpuSection + + 32 + + + + + + SysprofCpuSection + + + + + + exact + CPU Frequency + + + + + + + + + + + + + +]]> + + + + +