From 731b6dd37916ba20215696ee62929174d2d806fa Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 23 Jan 2020 11:59:07 -0800 Subject: [PATCH] sysprof: allow passing program path to sysprof If the path provided to us is an executable program (instead of a syscap file) then we can setup the path as the binary to execute in the profiler assistant and save the user a couple clicks. --- src/libsysprof-ui/sysprof-display.c | 13 +++++++++++-- .../sysprof-profiler-assistant.c | 19 +++++++++++++++++++ .../sysprof-profiler-assistant.h | 4 +++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c index 2e2a1a3e..463364c8 100644 --- a/src/libsysprof-ui/sysprof-display.c +++ b/src/libsysprof-ui/sysprof-display.c @@ -1032,10 +1032,19 @@ sysprof_display_open (SysprofDisplay *self, g_return_if_fail (g_file_is_native (file)); g_return_if_fail (sysprof_display_is_empty (self)); - g_set_object (&priv->file, file); - path = g_file_get_path (file); + /* If the file is executable, just set the path to the binary + * in the profiler assistant. + */ + if (g_file_test (path, G_FILE_TEST_IS_EXECUTABLE)) + { + sysprof_profiler_assistant_set_executable (priv->assistant, path); + return; + } + + g_set_object (&priv->file, file); + if (!(reader = sysprof_capture_reader_new (path, &error))) g_warning ("Failed to open capture: %s", error->message); else diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.c b/src/libsysprof-ui/sysprof-profiler-assistant.c index c7fcf772..9ab76bc6 100644 --- a/src/libsysprof-ui/sysprof-profiler-assistant.c +++ b/src/libsysprof-ui/sysprof-profiler-assistant.c @@ -455,3 +455,22 @@ _sysprof_profiler_assistant_focus_record (SysprofProfilerAssistant *self) gtk_widget_grab_focus (GTK_WIDGET (self->record_button)); } + +void +sysprof_profiler_assistant_set_executable (SysprofProfilerAssistant *self, + const gchar *path) +{ + g_return_if_fail (SYSPROF_IS_PROFILER_ASSISTANT (self)); + + if (path == NULL || path[0] == 0) + { + gtk_entry_set_text (GTK_ENTRY (self->command_line), ""); + gtk_switch_set_active (self->launch_switch, FALSE); + } + else + { + gtk_entry_set_text (GTK_ENTRY (self->command_line), path); + gtk_switch_set_active (self->launch_switch, TRUE); + gtk_widget_grab_focus (GTK_WIDGET (self->command_line)); + } +} diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.h b/src/libsysprof-ui/sysprof-profiler-assistant.h index f57498a2..86e59e43 100644 --- a/src/libsysprof-ui/sysprof-profiler-assistant.h +++ b/src/libsysprof-ui/sysprof-profiler-assistant.h @@ -30,6 +30,8 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (SysprofProfilerAssistant, sysprof_profiler_assistant, SYSPROF, PROFILER_ASSISTANT, GtkBin) -GtkWidget *sysprof_profiler_assistant_new (void); +GtkWidget *sysprof_profiler_assistant_new (void); +void sysprof_profiler_assistant_set_executable (SysprofProfilerAssistant *self, + const gchar *path); G_END_DECLS