mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
sysprof: start on section abstraction
This commit is contained in:
@ -5,6 +5,8 @@ sysprof_sources = [
|
||||
'sysprof-greeter.c',
|
||||
'sysprof-recording-pad.c',
|
||||
'sysprof-metadata-dialog.c',
|
||||
'sysprof-samples-section.c',
|
||||
'sysprof-section.c',
|
||||
'sysprof-window.c',
|
||||
]
|
||||
|
||||
|
||||
64
src/sysprof/sysprof-samples-section.c
Normal file
64
src/sysprof/sysprof-samples-section.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* sysprof-samples-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-samples-section.h"
|
||||
|
||||
struct _SysprofSamplesSection
|
||||
{
|
||||
SysprofSection parent_instance;
|
||||
|
||||
SysprofWeightedCallgraphView *callgraph_view;
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (SysprofSamplesSection, sysprof_samples_section, SYSPROF_TYPE_SECTION)
|
||||
|
||||
static void
|
||||
sysprof_samples_section_dispose (GObject *object)
|
||||
{
|
||||
SysprofSamplesSection *self = (SysprofSamplesSection *)object;
|
||||
|
||||
gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_SAMPLES_SECTION);
|
||||
|
||||
G_OBJECT_CLASS (sysprof_samples_section_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_samples_section_class_init (SysprofSamplesSectionClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->dispose = sysprof_samples_section_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-samples-section.ui");
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofSamplesSection, callgraph_view);
|
||||
|
||||
g_type_ensure (SYSPROF_TYPE_WEIGHTED_CALLGRAPH_VIEW);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_samples_section_init (SysprofSamplesSection *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
31
src/sysprof/sysprof-samples-section.h
Normal file
31
src/sysprof/sysprof-samples-section.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* sysprof-samples-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_SAMPLES_SECTION (sysprof_samples_section_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (SysprofSamplesSection, sysprof_samples_section, SYSPROF, SAMPLES_SECTION, SysprofSection)
|
||||
|
||||
G_END_DECLS
|
||||
16
src/sysprof/sysprof-samples-section.ui
Normal file
16
src/sysprof/sysprof-samples-section.ui
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="SysprofSamplesSection" parent="SysprofSection">
|
||||
<property name="title" translatable="yes">Time Profiler</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="SysprofWeightedCallgraphView" id="callgraph_view">
|
||||
<property name="vexpand">true</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
182
src/sysprof/sysprof-section.c
Normal file
182
src/sysprof/sysprof-section.c
Normal file
@ -0,0 +1,182 @@
|
||||
/* sysprof-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-section.h"
|
||||
#include "sysprof-window.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *title;
|
||||
} SysprofSectionPrivate;
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SysprofSection, sysprof_section, GTK_TYPE_WIDGET)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_SESSION,
|
||||
PROP_TITLE,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
sysprof_section_root (GtkWidget *widget)
|
||||
{
|
||||
GTK_WIDGET_CLASS (sysprof_section_parent_class)->root (widget);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_SESSION]);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_section_unroot (GtkWidget *widget)
|
||||
{
|
||||
GTK_WIDGET_CLASS (sysprof_section_parent_class)->unroot (widget);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_SESSION]);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_section_dispose (GObject *object)
|
||||
{
|
||||
SysprofSection *self = (SysprofSection *)object;
|
||||
SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self);
|
||||
GtkWidget *child;
|
||||
|
||||
g_clear_pointer (&priv->title, g_free);
|
||||
|
||||
while ((child = gtk_widget_get_first_child (GTK_WIDGET (self))))
|
||||
gtk_widget_unparent (child);
|
||||
|
||||
G_OBJECT_CLASS (sysprof_section_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_section_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofSection *self = SYSPROF_SECTION (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SESSION:
|
||||
g_value_set_object (value, sysprof_section_get_session (self));
|
||||
break;
|
||||
|
||||
case PROP_TITLE:
|
||||
g_value_set_string (value, sysprof_section_get_title (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_section_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofSection *self = SYSPROF_SECTION (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TITLE:
|
||||
sysprof_section_set_title (self, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_section_class_init (SysprofSectionClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->dispose = sysprof_section_dispose;
|
||||
object_class->get_property = sysprof_section_get_property;
|
||||
object_class->set_property = sysprof_section_set_property;
|
||||
|
||||
widget_class->root = sysprof_section_root;
|
||||
widget_class->unroot = sysprof_section_unroot;
|
||||
|
||||
properties[PROP_SESSION] =
|
||||
g_param_spec_object ("session", NULL, NULL,
|
||||
SYSPROF_TYPE_SESSION,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties[PROP_TITLE] =
|
||||
g_param_spec_string ("title", NULL, NULL,
|
||||
NULL,
|
||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
|
||||
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_section_init (SysprofSection *self)
|
||||
{
|
||||
}
|
||||
|
||||
SysprofSession *
|
||||
sysprof_section_get_session (SysprofSection *self)
|
||||
{
|
||||
GtkRoot *root;
|
||||
|
||||
if ((root = gtk_widget_get_root (GTK_WIDGET (self))))
|
||||
{
|
||||
if (SYSPROF_IS_WINDOW (root))
|
||||
return sysprof_window_get_session (SYSPROF_WINDOW (root));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
sysprof_section_get_title (SysprofSection *self)
|
||||
{
|
||||
SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_SECTION (self), NULL);
|
||||
|
||||
return priv->title;
|
||||
}
|
||||
|
||||
void
|
||||
sysprof_section_set_title (SysprofSection *self,
|
||||
const char *title)
|
||||
{
|
||||
SysprofSectionPrivate *priv = sysprof_section_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SYSPROF_IS_SECTION (self));
|
||||
|
||||
if (g_set_str (&priv->title, title))
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
|
||||
}
|
||||
43
src/sysprof/sysprof-section.h
Normal file
43
src/sysprof/sysprof-section.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* sysprof-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 <gtk/gtk.h>
|
||||
|
||||
#include <sysprof-gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SYSPROF_TYPE_SECTION (sysprof_section_get_type())
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (SysprofSection, sysprof_section, SYSPROF, SECTION, GtkWidget)
|
||||
|
||||
struct _SysprofSectionClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
};
|
||||
|
||||
SysprofSession *sysprof_section_get_session (SysprofSection *self);
|
||||
const char *sysprof_section_get_title (SysprofSection *self);
|
||||
void sysprof_section_set_title (SysprofSection *self,
|
||||
const char *title);
|
||||
|
||||
G_END_DECLS
|
||||
@ -27,6 +27,7 @@
|
||||
#include "sysprof-files-dialog.h"
|
||||
#include "sysprof-greeter.h"
|
||||
#include "sysprof-metadata-dialog.h"
|
||||
#include "sysprof-samples-section.h"
|
||||
#include "sysprof-window.h"
|
||||
|
||||
struct _SysprofWindow
|
||||
@ -195,6 +196,7 @@ sysprof_window_class_init (SysprofWindowClass *klass)
|
||||
|
||||
g_type_ensure (SYSPROF_TYPE_DOCUMENT);
|
||||
g_type_ensure (SYSPROF_TYPE_SESSION);
|
||||
g_type_ensure (SYSPROF_TYPE_SAMPLES_SECTION);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -94,9 +94,12 @@
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<object class="GtkStack">
|
||||
<property name="vexpand">true</property>
|
||||
<child>
|
||||
<object class="SysprofSamplesSection">
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
<file preprocess="xml-stripblanks">sysprof-greeter.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-metadata-dialog.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-recording-pad.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-samples-section.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-window.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
Reference in New Issue
Block a user