mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof: record some system info from linux instrument
We might want a secondary instrument for this eventually, but for now we'll just attach it in the Linux instrument. This takes the output of eglinfo and glxinfo and adds it as a file in the capture syscap. Compressed of course to keep the size smaller.
This commit is contained in:
@ -268,6 +268,69 @@ 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);
|
||||
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)
|
||||
{
|
||||
@ -280,6 +343,10 @@ 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);
|
||||
|
||||
/* 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