sysprof: start on CPU section

This commit is contained in:
Christian Hergert
2023-07-14 17:09:49 -07:00
parent fa7a4d5c75
commit b5eec21fbc
7 changed files with 239 additions and 1 deletions

View File

@ -3,6 +3,7 @@ sysprof_sources = [
'sysprof-application.c',
'sysprof-counters-section.c',
'sysprof-cpu-info-dialog.c',
'sysprof-cpu-section.c',
'sysprof-files-section.c',
'sysprof-frame-utility.c',
'sysprof-greeter.c',

View File

@ -0,0 +1,141 @@
/* sysprof-cpu-section.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 "config.h"
#include <sysprof-gtk.h>
#include "sysprof-cpu-section.h"
#include "sysprof-time-filter-model.h"
#include "sysprof-time-scrubber.h"
#include "sysprof-value-axis.h"
struct _SysprofCpuSection
{
SysprofSection parent_instance;
SysprofTimeScrubber *scrubber;
};
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_counter = 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_counter = 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_counter));
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_counter, x_axis));
}
}
static void
sysprof_cpu_section_dispose (GObject *object)
{
SysprofCpuSection *self = (SysprofCpuSection *)object;
gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_CPU_SECTION);
G_OBJECT_CLASS (sysprof_cpu_section_parent_class)->dispose (object);
}
static void
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, scrubber);
g_type_ensure (SYSPROF_TYPE_CHART);
g_type_ensure (SYSPROF_TYPE_DOCUMENT_MARK);
g_type_ensure (SYSPROF_TYPE_DOCUMENT_COUNTER);
g_type_ensure (SYSPROF_TYPE_DOCUMENT_COUNTER_VALUE);
g_type_ensure (SYSPROF_TYPE_LINE_LAYER);
g_type_ensure (SYSPROF_TYPE_TIME_SERIES);
g_type_ensure (SYSPROF_TYPE_TIME_SPAN_LAYER);
g_type_ensure (SYSPROF_TYPE_XY_SERIES);
}
static void
sysprof_cpu_section_init (SysprofCpuSection *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}

View File

@ -0,0 +1,31 @@
/* sysprof-cpu-section.h
*
* 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
*/
#pragma once
#include "sysprof-section.h"
G_BEGIN_DECLS
#define SYSPROF_TYPE_CPU_SECTION (sysprof_cpu_section_get_type())
G_DECLARE_FINAL_TYPE (SysprofCpuSection, sysprof_cpu_section, SYSPROF, CPU_SECTION, SysprofSection)
G_END_DECLS

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="SysprofCpuSection" parent="SysprofSection">
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="SysprofTimeScrubber" id="scrubber">
<binding name="session">
<lookup name="session">SysprofCpuSection</lookup>
</binding>
</object>
</child>
<child>
<object class="GtkSeparator"/>
</child>
<child>
<object class="AdwViewStack" id="stack">
<property name="vexpand">true</property>
<child>
<object class="AdwViewStackPage">
<property name="title" translatable="yes">Counters Chart</property>
<property name="icon-name">mark-chart-symbolic</property>
<property name="child">
<object class="GtkScrolledWindow">
<child>
<object class="GtkListView">
</object>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="AdwViewStackPage">
<property name="title" translatable="yes">Counters Table</property>
<property name="icon-name">mark-table-symbolic</property>
<property name="child">
<object class="GtkScrolledWindow">
<child>
<object class="GtkColumnView">
</object>
</child>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwViewSwitcherBar" id="switcher">
<property name="reveal">true</property>
<property name="stack">stack</property>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -26,6 +26,7 @@
#include "sysprof-counters-section.h"
#include "sysprof-cpu-info-dialog.h"
#include "sysprof-cpu-section.h"
#include "sysprof-files-section.h"
#include "sysprof-greeter.h"
#include "sysprof-logs-section.h"
@ -414,6 +415,7 @@ sysprof_window_class_init (SysprofWindowClass *klass)
gtk_widget_class_add_binding_action (widget_class, GDK_KEY_bracketright, GDK_CONTROL_MASK, "session.seek-forward", NULL);
g_type_ensure (SYSPROF_TYPE_COUNTERS_SECTION);
g_type_ensure (SYSPROF_TYPE_CPU_SECTION);
g_type_ensure (SYSPROF_TYPE_DOCUMENT);
g_type_ensure (SYSPROF_TYPE_FILES_SECTION);
g_type_ensure (SYSPROF_TYPE_LOGS_SECTION);

View File

@ -144,7 +144,7 @@
</object>
</child>
<child>
<object class="SysprofCountersSection">
<object class="SysprofCpuSection">
<property name="title" translatable="yes">CPU Usage</property>
<property name="category">counters</property>
<property name="icon-name">system-run-symbolic</property>

View File

@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">sysprof-counters-section.ui</file>
<file preprocess="xml-stripblanks">sysprof-cpu-info-dialog.ui</file>
<file preprocess="xml-stripblanks">sysprof-cpu-section.ui</file>
<file preprocess="xml-stripblanks">sysprof-files-section.ui</file>
<file preprocess="xml-stripblanks">sysprof-frame-utility.ui</file>
<file preprocess="xml-stripblanks">sysprof-greeter.ui</file>