mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
sysprof: start on recording pad while recording is active
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <locale.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
@ -38,12 +39,17 @@ main (int argc,
|
||||
|
||||
sysprof_clock_init ();
|
||||
|
||||
/* Ignore SIGPIPE */
|
||||
signal (SIGPIPE, SIG_IGN);
|
||||
|
||||
/* Set up gettext translations */
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain (GETTEXT_PACKAGE);
|
||||
|
||||
g_set_prgname ("sysprof");
|
||||
|
||||
app = sysprof_application_new ();
|
||||
ret = g_application_run (G_APPLICATION (app), argc, argv);
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ sysprof_sources = [
|
||||
'main.c',
|
||||
'sysprof-application.c',
|
||||
'sysprof-greeter.c',
|
||||
'sysprof-recording-pad.c',
|
||||
'sysprof-window.c',
|
||||
]
|
||||
|
||||
|
||||
@ -20,7 +20,15 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include <sysprof-capture.h>
|
||||
#include <sysprof-profiler.h>
|
||||
|
||||
#include "sysprof-greeter.h"
|
||||
#include "sysprof-recording-pad.h"
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureWriter, sysprof_capture_writer_unref)
|
||||
|
||||
struct _SysprofGreeter
|
||||
{
|
||||
@ -28,6 +36,9 @@ struct _SysprofGreeter
|
||||
|
||||
GtkBox *toolbar;
|
||||
AdwPreferencesPage *record_page;
|
||||
GtkSwitch *sample_native_stacks;
|
||||
GtkSwitch *record_disk_usage;
|
||||
GtkSwitch *record_network_usage;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -51,6 +62,81 @@ sysprof_greeter_view_stack_notify_visible_child (SysprofGreeter *self,
|
||||
GTK_WIDGET (self->record_page) == adw_view_stack_get_visible_child (stack));
|
||||
}
|
||||
|
||||
static SysprofProfiler *
|
||||
sysprof_greeter_create_profiler (SysprofGreeter *self)
|
||||
{
|
||||
g_autoptr(SysprofProfiler) profiler = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_GREETER (self));
|
||||
|
||||
profiler = sysprof_profiler_new ();
|
||||
|
||||
if (gtk_switch_get_active (self->sample_native_stacks))
|
||||
sysprof_profiler_add_instrument (profiler, sysprof_sampler_new ());
|
||||
|
||||
if (gtk_switch_get_active (self->record_disk_usage))
|
||||
sysprof_profiler_add_instrument (profiler, sysprof_disk_usage_new ());
|
||||
|
||||
if (gtk_switch_get_active (self->record_network_usage))
|
||||
sysprof_profiler_add_instrument (profiler, sysprof_network_usage_new ());
|
||||
|
||||
return g_steal_pointer (&profiler);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_greeter_record_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
SysprofProfiler *profiler = (SysprofProfiler *)object;
|
||||
g_autoptr(SysprofRecording) recording = NULL;
|
||||
g_autoptr(SysprofGreeter) self = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_PROFILER (profiler));
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
g_assert (SYSPROF_IS_GREETER (self));
|
||||
|
||||
if (!(recording = sysprof_profiler_record_finish (profiler, result, &error)))
|
||||
{
|
||||
/* TODO: error message */
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget *pad = sysprof_recording_pad_new (recording);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (pad));
|
||||
}
|
||||
|
||||
gtk_window_destroy (GTK_WINDOW (self));
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_greeter_record_to_memory_action (GtkWidget *widget,
|
||||
const char *action_name,
|
||||
GVariant *param)
|
||||
{
|
||||
SysprofGreeter *self = (SysprofGreeter *)widget;
|
||||
g_autoptr(SysprofCaptureWriter) writer = NULL;
|
||||
g_autoptr(SysprofProfiler) profiler = NULL;
|
||||
g_autofd int fd = -1;
|
||||
|
||||
g_assert (SYSPROF_IS_GREETER (self));
|
||||
|
||||
fd = sysprof_memfd_create ("[sysprof-profile]");
|
||||
|
||||
profiler = sysprof_greeter_create_profiler (self);
|
||||
writer = sysprof_capture_writer_new_from_fd (g_steal_fd (&fd), 0);
|
||||
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
|
||||
|
||||
sysprof_profiler_record_async (profiler,
|
||||
writer,
|
||||
NULL,
|
||||
sysprof_greeter_record_cb,
|
||||
g_object_ref (self));
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_greeter_dispose (GObject *object)
|
||||
{
|
||||
@ -104,7 +190,12 @@ sysprof_greeter_class_init (SysprofGreeterClass *klass)
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-greeter.ui");
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, toolbar);
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, record_page);
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, record_disk_usage);
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, record_network_usage);
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofGreeter, sample_native_stacks);
|
||||
gtk_widget_class_bind_template_callback (widget_class, sysprof_greeter_view_stack_notify_visible_child);
|
||||
|
||||
gtk_widget_class_install_action (widget_class, "win.record-to-memory", NULL, sysprof_greeter_record_to_memory_action);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -267,6 +267,7 @@
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">_Record to Memory</property>
|
||||
<property name="action-name">win.record-to-memory</property>
|
||||
<property name="use-underline">true</property>
|
||||
<property name="hexpand">true</property>
|
||||
<style>
|
||||
|
||||
146
src/sysprof/sysprof-recording-pad.c
Normal file
146
src/sysprof/sysprof-recording-pad.c
Normal file
@ -0,0 +1,146 @@
|
||||
/* sysprof-recording-pad.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-application.h"
|
||||
#include "sysprof-recording-pad.h"
|
||||
|
||||
struct _SysprofRecordingPad
|
||||
{
|
||||
AdwWindow parent_instance;
|
||||
|
||||
SysprofRecording *recording;
|
||||
|
||||
GtkButton *stop_button;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_RECORDING,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (SysprofRecordingPad, sysprof_recording_pad, ADW_TYPE_WINDOW)
|
||||
|
||||
static GParamSpec *properties[N_PROPS];
|
||||
|
||||
static gboolean
|
||||
sysprof_recording_pad_close_request (GtkWindow *window)
|
||||
{
|
||||
SysprofRecordingPad *self = (SysprofRecordingPad *)window;
|
||||
|
||||
g_assert (SYSPROF_IS_RECORDING_PAD (self));
|
||||
g_assert (self->recording != NULL);
|
||||
|
||||
sysprof_recording_stop_async (self->recording, NULL, NULL, NULL);
|
||||
|
||||
/* TODO: Open SysprofWindow with finalized recording */
|
||||
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_recording_pad_dispose (GObject *object)
|
||||
{
|
||||
SysprofRecordingPad *self = (SysprofRecordingPad *)object;
|
||||
|
||||
g_clear_object (&self->recording);
|
||||
|
||||
G_OBJECT_CLASS (sysprof_recording_pad_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_recording_pad_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofRecordingPad *self = SYSPROF_RECORDING_PAD (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_RECORDING:
|
||||
g_value_set_object (value, self->recording);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_recording_pad_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofRecordingPad *self = SYSPROF_RECORDING_PAD (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_RECORDING:
|
||||
self->recording = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_recording_pad_class_init (SysprofRecordingPadClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->dispose = sysprof_recording_pad_dispose;
|
||||
object_class->get_property = sysprof_recording_pad_get_property;
|
||||
object_class->set_property = sysprof_recording_pad_set_property;
|
||||
|
||||
properties [PROP_RECORDING] =
|
||||
g_param_spec_object ("recording", NULL, NULL,
|
||||
SYSPROF_TYPE_RECORDING,
|
||||
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | 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-recording-pad.ui");
|
||||
gtk_widget_class_bind_template_child (widget_class, SysprofRecordingPad, stop_button);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_recording_pad_init (SysprofRecordingPad *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
gtk_widget_grab_focus (GTK_WIDGET (self->stop_button));
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
sysprof_recording_pad_new (SysprofRecording *recording)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_RECORDING (recording), NULL);
|
||||
|
||||
return g_object_new (SYSPROF_TYPE_RECORDING_PAD,
|
||||
"application", SYSPROF_APPLICATION_DEFAULT,
|
||||
"recording", recording,
|
||||
NULL);
|
||||
}
|
||||
35
src/sysprof/sysprof-recording-pad.h
Normal file
35
src/sysprof/sysprof-recording-pad.h
Normal file
@ -0,0 +1,35 @@
|
||||
/* sysprof-recording-pad.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 <adwaita.h>
|
||||
|
||||
#include <sysprof-profile.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SYSPROF_TYPE_RECORDING_PAD (sysprof_recording_pad_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (SysprofRecordingPad, sysprof_recording_pad, SYSPROF, RECORDING_PAD, AdwWindow)
|
||||
|
||||
GtkWidget *sysprof_recording_pad_new (SysprofRecording *recording);
|
||||
|
||||
G_END_DECLS
|
||||
69
src/sysprof/sysprof-recording-pad.ui
Normal file
69
src/sysprof/sysprof-recording-pad.ui
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="SysprofRecordingPad" parent="AdwWindow">
|
||||
<property name="content">
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar">
|
||||
<property name="show-start-title-buttons">false</property>
|
||||
<property name="show-end-title-buttons">false</property>
|
||||
<property name="title-widget">
|
||||
<object class="AdwWindowTitle">
|
||||
<property name="title" translatable="yes">Sysprof</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkCenterBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child type="center">
|
||||
<object class="GtkLabel">
|
||||
<property name="label">00:00</property>
|
||||
<property name="margin-top">18</property>
|
||||
<property name="margin-start">18</property>
|
||||
<property name="margin-end">18</property>
|
||||
<property name="margin-bottom">18</property>
|
||||
<attributes>
|
||||
<attribute name="scale" value="4"/>
|
||||
<attribute name="font-features" value="'tnum'"/>
|
||||
</attributes>
|
||||
</object>
|
||||
</child>
|
||||
<child type="end">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="vexpand">true</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="label">1234 events</property>
|
||||
<property name="margin-top">12</property>
|
||||
<property name="margin-bottom">18</property>
|
||||
<property name="valign">start</property>
|
||||
<property name="vexpand">true</property>
|
||||
<style>
|
||||
<class name="caption"/>
|
||||
</style>
|
||||
<attributes>
|
||||
<attribute name="font-features" value="'tnum'"/>
|
||||
</attributes>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="stop_button">
|
||||
<property name="label" translatable="yes">Stop Recording</property>
|
||||
<property name="action-name">window.close</property>
|
||||
<property name="valign">end</property>
|
||||
<style>
|
||||
<class name="destructive-action"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</template>
|
||||
</interface>
|
||||
@ -4,6 +4,7 @@
|
||||
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-greeter.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-recording-pad.ui</file>
|
||||
<file preprocess="xml-stripblanks">sysprof-window.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
Reference in New Issue
Block a user