mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof: get various process info during prepare
That way it doesn't show up on the profiles themselves.
This commit is contained in:
@ -49,6 +49,69 @@ sysprof_linux_instrument_list_required_policy (SysprofInstrument *instrument)
|
||||
return g_strdupv ((char **)policy);
|
||||
}
|
||||
|
||||
static void
|
||||
add_process_output_as_file_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(DexPromise) promise = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autofree char *stdout_buf = NULL;
|
||||
|
||||
g_assert (G_IS_SUBPROCESS (object));
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
g_assert (DEX_IS_PROMISE (promise));
|
||||
|
||||
if (g_subprocess_communicate_utf8_finish (G_SUBPROCESS (object), result, &stdout_buf, NULL, &error))
|
||||
dex_promise_resolve_string (promise, g_steal_pointer (&stdout_buf));
|
||||
else
|
||||
dex_promise_reject (promise, g_steal_pointer (&error));
|
||||
}
|
||||
|
||||
static void
|
||||
add_process_output_as_file (SysprofRecording *recording,
|
||||
const char *command_line,
|
||||
const char *filename,
|
||||
gboolean compress)
|
||||
{
|
||||
g_autoptr(GSubprocessLauncher) launcher = NULL;
|
||||
g_autoptr(GSubprocess) subprocess = NULL;
|
||||
g_autoptr(DexPromise) promise = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_auto(GStrv) argv = NULL;
|
||||
g_autofree char *string = NULL;
|
||||
int argc;
|
||||
|
||||
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||
|
||||
if (!g_shell_parse_argv (command_line, &argc, &argv, &error))
|
||||
goto error;
|
||||
|
||||
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_SILENCE);
|
||||
if (!(subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *)argv, &error)))
|
||||
goto error;
|
||||
|
||||
promise = dex_promise_new ();
|
||||
g_subprocess_communicate_utf8_async (subprocess,
|
||||
NULL,
|
||||
dex_promise_get_cancellable (promise),
|
||||
add_process_output_as_file_cb,
|
||||
dex_ref (promise));
|
||||
|
||||
if (!(string = dex_await_string (dex_ref (promise), &error)))
|
||||
goto error;
|
||||
|
||||
_sysprof_recording_add_file_data (recording, filename, string, -1, compress);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
_sysprof_recording_diagnostic (recording,
|
||||
"Linux",
|
||||
"Failed to get output for '%s': %s",
|
||||
command_line, error->message);
|
||||
}
|
||||
|
||||
static void
|
||||
add_mmaps (SysprofRecording *recording,
|
||||
GPid pid,
|
||||
@ -252,6 +315,11 @@ sysprof_linux_instrument_prepare_fiber (gpointer user_data)
|
||||
&error))
|
||||
return dex_future_new_for_error (g_steal_pointer (&error));
|
||||
|
||||
/* Try to get some info into our capture for decoding */
|
||||
add_process_output_as_file (recording, "eglinfo", "eglinfo", TRUE);
|
||||
add_process_output_as_file (recording, "glxinfo", "glxinfo", TRUE);
|
||||
add_process_output_as_file (recording, "lsusb -v", "lsusb", TRUE);
|
||||
|
||||
return dex_future_new_for_boolean (TRUE);
|
||||
}
|
||||
|
||||
@ -268,69 +336,6 @@ sysprof_linux_instrument_prepare (SysprofInstrument *instrument,
|
||||
g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
add_process_output_as_file_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_autoptr(DexPromise) promise = user_data;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autofree char *stdout_buf = NULL;
|
||||
|
||||
g_assert (G_IS_SUBPROCESS (object));
|
||||
g_assert (G_IS_ASYNC_RESULT (result));
|
||||
g_assert (DEX_IS_PROMISE (promise));
|
||||
|
||||
if (g_subprocess_communicate_utf8_finish (G_SUBPROCESS (object), result, &stdout_buf, NULL, &error))
|
||||
dex_promise_resolve_string (promise, g_steal_pointer (&stdout_buf));
|
||||
else
|
||||
dex_promise_reject (promise, g_steal_pointer (&error));
|
||||
}
|
||||
|
||||
static void
|
||||
add_process_output_as_file (SysprofRecording *recording,
|
||||
const char *command_line,
|
||||
const char *filename,
|
||||
gboolean compress)
|
||||
{
|
||||
g_autoptr(GSubprocessLauncher) launcher = NULL;
|
||||
g_autoptr(GSubprocess) subprocess = NULL;
|
||||
g_autoptr(DexPromise) promise = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_auto(GStrv) argv = NULL;
|
||||
g_autofree char *string = NULL;
|
||||
int argc;
|
||||
|
||||
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||
|
||||
if (!g_shell_parse_argv (command_line, &argc, &argv, &error))
|
||||
goto error;
|
||||
|
||||
launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_SILENCE);
|
||||
if (!(subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *)argv, &error)))
|
||||
goto error;
|
||||
|
||||
promise = dex_promise_new ();
|
||||
g_subprocess_communicate_utf8_async (subprocess,
|
||||
NULL,
|
||||
dex_promise_get_cancellable (promise),
|
||||
add_process_output_as_file_cb,
|
||||
dex_ref (promise));
|
||||
|
||||
if (!(string = dex_await_string (dex_ref (promise), &error)))
|
||||
goto error;
|
||||
|
||||
_sysprof_recording_add_file_data (recording, filename, string, -1, compress);
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
_sysprof_recording_diagnostic (recording,
|
||||
"Linux",
|
||||
"Failed to get output for '%s': %s",
|
||||
command_line, error->message);
|
||||
}
|
||||
|
||||
static DexFuture *
|
||||
sysprof_linux_instrument_record_fiber (gpointer user_data)
|
||||
{
|
||||
@ -343,11 +348,6 @@ sysprof_linux_instrument_record_fiber (gpointer user_data)
|
||||
|
||||
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||
|
||||
/* Try to get some info into our capture for decoding */
|
||||
add_process_output_as_file (recording, "eglinfo", "eglinfo", TRUE);
|
||||
add_process_output_as_file (recording, "glxinfo", "glxinfo", TRUE);
|
||||
add_process_output_as_file (recording, "lsusb -v", "lsusb", TRUE);
|
||||
|
||||
/* We need access to the bus to call various sysprofd API directly */
|
||||
if (!(bus = dex_await_object (dex_bus_get (G_BUS_TYPE_SYSTEM), &error)))
|
||||
return dex_future_new_for_error (g_steal_pointer (&error));
|
||||
|
||||
Reference in New Issue
Block a user