diff --git a/src/sysprof/main.c b/src/sysprof/main.c index f99cff34..93554fef 100644 --- a/src/sysprof/main.c +++ b/src/sysprof/main.c @@ -21,6 +21,7 @@ #include "config.h" #include +#include #include #include @@ -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); diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index aaac94a8..dee2c4f1 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -2,6 +2,7 @@ sysprof_sources = [ 'main.c', 'sysprof-application.c', 'sysprof-greeter.c', + 'sysprof-recording-pad.c', 'sysprof-window.c', ] diff --git a/src/sysprof/sysprof-greeter.c b/src/sysprof/sysprof-greeter.c index 47c2d37c..3c64e684 100644 --- a/src/sysprof/sysprof-greeter.c +++ b/src/sysprof/sysprof-greeter.c @@ -20,7 +20,15 @@ #include "config.h" +#include + +#include +#include + #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 diff --git a/src/sysprof/sysprof-greeter.ui b/src/sysprof/sysprof-greeter.ui index 2fdedab6..037be9ef 100644 --- a/src/sysprof/sysprof-greeter.ui +++ b/src/sysprof/sysprof-greeter.ui @@ -267,6 +267,7 @@ _Record to Memory + win.record-to-memory true true + + + + + + + + Stop Recording + window.close + end + + + + + + + + + + + diff --git a/src/sysprof/sysprof.gresource.xml b/src/sysprof/sysprof.gresource.xml index 141202a9..1243ffcb 100644 --- a/src/sysprof/sysprof.gresource.xml +++ b/src/sysprof/sysprof.gresource.xml @@ -4,6 +4,7 @@ gtk/help-overlay.ui gtk/menus.ui sysprof-greeter.ui + sysprof-recording-pad.ui sysprof-window.ui