[gnome-builder] plugins/sysprof: support sysprof-agent too



commit 60bbae03e46aafc61e077a91906a4b4bb77bc0cd
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 21 18:39:51 2022 -0700

    plugins/sysprof: support sysprof-agent too

 src/plugins/sysprof/gbp-sysprof-tool.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/src/plugins/sysprof/gbp-sysprof-tool.c b/src/plugins/sysprof/gbp-sysprof-tool.c
index 98583d7b1..26127fd33 100644
--- a/src/plugins/sysprof/gbp-sysprof-tool.c
+++ b/src/plugins/sysprof/gbp-sysprof-tool.c
@@ -50,6 +50,9 @@ struct _GbpSysprofTool
 
   /* IPC service on @connection */
   IpcSysprof *sysprof;
+
+  /* If we found sysprof-agent in the runtime */
+  guint has_agent : 1;
 };
 
 G_DEFINE_FINAL_TYPE (GbpSysprofTool, gbp_sysprof_tool, IDE_TYPE_RUN_TOOL)
@@ -99,8 +102,11 @@ gbp_sysprof_tool_handler (IdeRunContext       *run_context,
   if (settings == NULL)
     settings = g_settings_new ("org.gnome.builder.sysprof");
 
-  /* Run gnome-builder-sysprof from $prefix/libexec/ */
-  ide_run_context_append_argv (run_context, PACKAGE_LIBEXECDIR"/gnome-builder-sysprof");
+  /* Run sysprof-agent/gnome-builder-sysprof */
+  if (self->has_agent)
+    ide_run_context_append_argv (run_context, "sysprof-agent");
+  else
+    ide_run_context_append_argv (run_context, PACKAGE_LIBEXECDIR"/gnome-builder-sysprof");
 
   /* Pass along FDs after stderr to next process */
   n_fds = ide_unix_fd_map_get_length (unix_fd_map);
@@ -185,18 +191,32 @@ gbp_sysprof_tool_prepare_to_run (IdeRunTool    *run_tool,
                                  IdeRunCommand *run_command,
                                  IdeRunContext *run_context)
 {
+  GbpSysprofTool *self = (GbpSysprofTool *)run_tool;
+
   IDE_ENTRY;
 
   g_assert (IDE_IS_MAIN_THREAD ());
-  g_assert (GBP_IS_SYSPROF_TOOL (run_tool));
+  g_assert (GBP_IS_SYSPROF_TOOL (self));
   g_assert (IDE_IS_PIPELINE (pipeline));
   g_assert (IDE_IS_RUN_COMMAND (run_command));
   g_assert (IDE_IS_RUN_CONTEXT (run_context));
 
-  ide_run_context_push_at_base (run_context,
-                                gbp_sysprof_tool_handler,
-                                g_object_ref (run_tool),
-                                g_object_unref);
+  /* If we have sysprof-agent in the runtime, then use that since we get
+   * a chance to make things like LD_PRELOAD work. Otherwise, fallback to
+   * using our own wrapper in our context which is more restrictive.
+   */
+  self->has_agent = ide_pipeline_contains_program_in_path (pipeline, "sysprof-agent", NULL);
+
+  if (self->has_agent)
+    ide_run_context_push (run_context,
+                          gbp_sysprof_tool_handler,
+                          g_object_ref (run_tool),
+                          g_object_unref);
+  else
+    ide_run_context_push_at_base (run_context,
+                                  gbp_sysprof_tool_handler,
+                                  g_object_ref (run_tool),
+                                  g_object_unref);
 
   IDE_EXIT;
 }


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