mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 07:00:53 +00:00
tools: add --use-trace-fd option
This commit is contained in:
@ -76,6 +76,7 @@ main (gint argc,
|
|||||||
gboolean no_cpu = FALSE;
|
gboolean no_cpu = FALSE;
|
||||||
gboolean version = FALSE;
|
gboolean version = FALSE;
|
||||||
gboolean force = FALSE;
|
gboolean force = FALSE;
|
||||||
|
gboolean use_trace_fd = FALSE;
|
||||||
int pid = -1;
|
int pid = -1;
|
||||||
int fd;
|
int fd;
|
||||||
int flags;
|
int flags;
|
||||||
@ -85,6 +86,7 @@ main (gint argc,
|
|||||||
{ "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Force overwrite the capture file") },
|
{ "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Force overwrite the capture file") },
|
||||||
{ "no-cpu", 0, 0, G_OPTION_ARG_NONE, &no_cpu, N_("Disable recording of CPU statistics") },
|
{ "no-cpu", 0, 0, G_OPTION_ARG_NONE, &no_cpu, N_("Disable recording of CPU statistics") },
|
||||||
{ "no-memory", 0, 0, G_OPTION_ARG_NONE, &no_memory, N_("Disable recording of memory statistics") },
|
{ "no-memory", 0, 0, G_OPTION_ARG_NONE, &no_memory, N_("Disable recording of memory statistics") },
|
||||||
|
{ "use-trace-fd", 0, 0, G_OPTION_ARG_NONE, &use_trace_fd, N_("Set SYSPROF_TRACE_FD environment for subprocess") },
|
||||||
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, N_("Print the sysprof-cli version and exit") },
|
{ "version", 0, 0, G_OPTION_ARG_NONE, &version, N_("Print the sysprof-cli version and exit") },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
@ -161,6 +163,7 @@ main (gint argc,
|
|||||||
if (command != NULL)
|
if (command != NULL)
|
||||||
{
|
{
|
||||||
g_auto(GStrv) child_argv = NULL;
|
g_auto(GStrv) child_argv = NULL;
|
||||||
|
g_auto(GStrv) env = g_get_environ ();
|
||||||
gint child_argc;
|
gint child_argc;
|
||||||
|
|
||||||
if (!g_shell_parse_argv (command, &child_argc, &child_argv, &error))
|
if (!g_shell_parse_argv (command, &child_argc, &child_argv, &error))
|
||||||
@ -169,23 +172,21 @@ main (gint argc,
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_spawn_async (NULL, child_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &error))
|
sysprof_profiler_set_spawn (profiler, TRUE);
|
||||||
{
|
sysprof_profiler_set_spawn_argv (profiler, (const gchar * const *)child_argv);
|
||||||
g_printerr ("Invalid command: %s\n", error->message);
|
sysprof_profiler_set_spawn_env (profiler, (const gchar * const *)env);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Stop the process until we are setup */
|
|
||||||
if (0 != kill (pid, SIGSTOP))
|
|
||||||
{
|
|
||||||
g_printerr ("Failed to pause inferior during setup\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writer = sysprof_capture_writer_new_from_fd (fd, 0);
|
writer = sysprof_capture_writer_new_from_fd (fd, 0);
|
||||||
sysprof_profiler_set_writer (profiler, writer);
|
sysprof_profiler_set_writer (profiler, writer);
|
||||||
|
|
||||||
|
if (use_trace_fd)
|
||||||
|
{
|
||||||
|
source = sysprof_proxy_source_new (G_BUS_TYPE_SESSION, "", "");
|
||||||
|
sysprof_profiler_add_source (profiler, source);
|
||||||
|
g_object_unref (source);
|
||||||
|
}
|
||||||
|
|
||||||
source = sysprof_proc_source_new ();
|
source = sysprof_proc_source_new ();
|
||||||
sysprof_profiler_add_source (profiler, source);
|
sysprof_profiler_add_source (profiler, source);
|
||||||
g_object_unref (source);
|
g_object_unref (source);
|
||||||
@ -216,10 +217,6 @@ main (gint argc,
|
|||||||
|
|
||||||
sysprof_profiler_start (profiler);
|
sysprof_profiler_start (profiler);
|
||||||
|
|
||||||
/* Restore the process if we stopped it */
|
|
||||||
if (command)
|
|
||||||
kill (pid, SIGCONT);
|
|
||||||
|
|
||||||
g_printerr ("Recording, press ^C to exit\n");
|
g_printerr ("Recording, press ^C to exit\n");
|
||||||
|
|
||||||
g_main_loop_run (main_loop);
|
g_main_loop_run (main_loop);
|
||||||
|
|||||||
Reference in New Issue
Block a user