[sysprof] sysprof: allow passing program path to sysprof



commit 731b6dd37916ba20215696ee62929174d2d806fa
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 23 11:59:07 2020 -0800

    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 +++++++++++--
 src/libsysprof-ui/sysprof-profiler-assistant.c | 19 +++++++++++++++++++
 src/libsysprof-ui/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 2e2a1a3..463364c 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 c7fcf77..9ab76bc 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 f57498a..86e59e4 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]