tools: use sysprof_tracefd_consumer_new

This just allows us to avoid some duplicated code.
This commit is contained in:
Christian Hergert
2023-07-27 15:49:34 -07:00
parent 048e366ea9
commit 3a74254f73
2 changed files with 22 additions and 26 deletions

View File

@ -599,6 +599,9 @@ main (int argc,
}
}
sysprof_profiler_add_instrument (profiler, sysprof_tracefd_consumer_new (g_steal_fd (&gjs_trace_fd)));
sysprof_profiler_add_instrument (profiler, sysprof_tracefd_consumer_new (g_steal_fd (&trace_fd)));
/* Now open the writer for our session */
if (!(writer = sysprof_capture_writer_new (capture_filename, BUFFER_SIZE)))
{
@ -625,28 +628,6 @@ main (int argc,
g_main_loop_run (main_loop);
if (gjs_trace_fd != -1)
{
SysprofCaptureReader *reader = NULL;
if ((reader = sysprof_capture_reader_new_from_fd (g_steal_fd (&gjs_trace_fd))))
{
sysprof_capture_writer_cat (writer, reader);
sysprof_capture_reader_unref (reader);
}
}
if (trace_fd != -1)
{
SysprofCaptureReader *reader = NULL;
if ((reader = sysprof_capture_reader_new_from_fd (g_steal_fd (&trace_fd))))
{
sysprof_capture_writer_cat (writer, reader);
sysprof_capture_reader_unref (reader);
}
}
sysprof_capture_writer_flush (writer);
sysprof_capture_writer_unref (writer);

View File

@ -236,6 +236,23 @@ sysprof_cli_record_cb (GObject *object,
g_set_object (&active_recording, recording);
}
static void
add_trace_fd (SysprofProfiler *profiler,
SysprofSpawnable *spawnable,
const char *name)
{
int trace_fd = -1;
g_assert (SYSPROF_IS_PROFILER (profiler));
g_assert (!spawnable || SYSPROF_IS_SPAWNABLE (spawnable));
if (spawnable == NULL)
return;
trace_fd = sysprof_spawnable_add_trace_fd (spawnable, name);
sysprof_profiler_add_instrument (profiler, sysprof_tracefd_consumer_new (g_steal_fd (&trace_fd)));
}
int
main (int argc,
char *argv[])
@ -272,8 +289,6 @@ main (int argc,
gboolean speedtrack = FALSE;
gboolean system_bus = FALSE;
gboolean session_bus = FALSE;
g_autofd int gjs_trace_fd = -1;
g_autofd int trace_fd = -1;
int pid = -1;
int fd;
int flags;
@ -473,10 +488,10 @@ Examples:\n\
sysprof_profiler_set_spawnable (profiler, spawnable);
if (gjs)
gjs_trace_fd = sysprof_spawnable_add_trace_fd (spawnable, "GJS_TRACE_FD");
add_trace_fd (profiler, spawnable, "GJS_TRACE_FD");
if (use_trace_fd)
trace_fd = sysprof_spawnable_add_trace_fd (spawnable, NULL);
add_trace_fd (profiler, spawnable, NULL);
if (memprof)
sysprof_spawnable_add_ld_preload (spawnable, PACKAGE_LIBDIR"/libsysprof-memory-"API_VERSION_S".so");