sysprof: add simple utility for frame data

This commit is contained in:
Christian Hergert
2023-07-13 17:41:40 -07:00
parent 36414c8ec3
commit c34bc51f3f
5 changed files with 334 additions and 0 deletions

View File

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

View File

@ -0,0 +1,164 @@
/* sysprof-frame-utility.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-frame-utility.h"
struct _SysprofFrameUtility
{
GtkWidget parent_instance;
SysprofSession *session;
SysprofDocumentFrame *frame;
};
enum {
PROP_0,
PROP_SESSION,
PROP_FRAME,
N_PROPS
};
G_DEFINE_FINAL_TYPE (SysprofFrameUtility, sysprof_frame_utility, GTK_TYPE_WIDGET)
static GParamSpec *properties[N_PROPS];
static char *
format_time_offset (SysprofFrameUtility *self,
gint64 time_offset)
{
int hours;
int minutes;
int seconds;
double time;
g_assert (SYSPROF_IS_FRAME_UTILITY (self));
time = time_offset / (double)SYSPROF_NSEC_PER_SEC;
hours = time / (60 * 60);
time -= hours * (60 * 60);
minutes = time / 60;
time -= minutes * 60;
seconds = time / SYSPROF_NSEC_PER_SEC;
time -= seconds * SYSPROF_NSEC_PER_SEC;
return g_strdup_printf ("%02d:%02d:%02d.%04d", hours, minutes, seconds, (int)(time * 10000));
}
static void
sysprof_frame_utility_finalize (GObject *object)
{
SysprofFrameUtility *self = (SysprofFrameUtility *)object;
GtkWidget *child;
gtk_widget_dispose_template (GTK_WIDGET (self), SYSPROF_TYPE_FRAME_UTILITY);
while ((child = gtk_widget_get_first_child (GTK_WIDGET (object))))
gtk_widget_unparent (child);
g_clear_object (&self->session);
g_clear_object (&self->frame);
G_OBJECT_CLASS (sysprof_frame_utility_parent_class)->finalize (object);
}
static void
sysprof_frame_utility_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofFrameUtility *self = SYSPROF_FRAME_UTILITY (object);
switch (prop_id)
{
case PROP_SESSION:
g_value_set_object (value, self->session);
break;
case PROP_FRAME:
g_value_set_object (value, self->frame);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_frame_utility_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SysprofFrameUtility *self = SYSPROF_FRAME_UTILITY (object);
switch (prop_id)
{
case PROP_SESSION:
g_set_object (&self->session, g_value_get_object (value));
break;
case PROP_FRAME:
g_set_object (&self->frame, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_frame_utility_class_init (SysprofFrameUtilityClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = sysprof_frame_utility_finalize;
object_class->get_property = sysprof_frame_utility_get_property;
object_class->set_property = sysprof_frame_utility_set_property;
properties[PROP_SESSION] =
g_param_spec_object ("session", NULL, NULL,
SYSPROF_TYPE_SESSION,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
properties[PROP_FRAME] =
g_param_spec_object ("frame", NULL, NULL,
SYSPROF_TYPE_DOCUMENT_FRAME,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-frame-utility.ui");
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_bind_template_callback (widget_class, format_time_offset);
}
static void
sysprof_frame_utility_init (SysprofFrameUtility *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}

View File

@ -0,0 +1,31 @@
/* sysprof-frame-utility.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>
G_BEGIN_DECLS
#define SYSPROF_TYPE_FRAME_UTILITY (sysprof_frame_utility_get_type())
G_DECLARE_FINAL_TYPE (SysprofFrameUtility, sysprof_frame_utility, SYSPROF, FRAME_UTILITY, GtkWidget)
G_END_DECLS

View File

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="SysprofFrameUtility" parent="GtkWidget">
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid">
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="column-spacing">12</property>
<property name="row-spacing">6</property>
<child>
<object class="GtkLabel">
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
<property name="label" translatable="yes">Type</property>
<layout>
<property name="row">0</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="hexpand">true</property>
<binding name="label">
<lookup name="type-name" type="SysprofDocumentFrame">
<lookup name="frame">SysprofFrameUtility</lookup>
</lookup>
</binding>
<layout>
<property name="row">0</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
<property name="label" translatable="yes">Time</property>
<layout>
<property name="row">1</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="hexpand">true</property>
<binding name="label">
<closure type="gchararray" function="format_time_offset" swapped="true">
<lookup name="time-offset" type="SysprofDocumentFrame">
<lookup name="frame">SysprofFrameUtility</lookup>
</lookup>
</closure>
</binding>
<layout>
<property name="row">1</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
<property name="label" translatable="yes">CPU</property>
<layout>
<property name="row">2</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="hexpand">true</property>
<binding name="label">
<lookup name="cpu" type="SysprofDocumentFrame">
<lookup name="frame">SysprofFrameUtility</lookup>
</lookup>
</binding>
<layout>
<property name="row">2</property>
<property name="column">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">1</property>
<style>
<class name="dim-label"/>
</style>
<property name="label" translatable="yes">PID</property>
<layout>
<property name="row">3</property>
<property name="column">0</property>
</layout>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="xalign">0</property>
<property name="hexpand">true</property>
<binding name="label">
<lookup name="pid" type="SysprofDocumentFrame">
<lookup name="frame">SysprofFrameUtility</lookup>
</lookup>
</binding>
<layout>
<property name="row">3</property>
<property name="column">1</property>
</layout>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">sysprof-cpu-info-dialog.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>
<file preprocess="xml-stripblanks">sysprof-logs-section.ui</file>
<file preprocess="xml-stripblanks">sysprof-marks-section.ui</file>