libsysprof: Add debuginfod toggle for sysprof-cli inside libsysprof

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
2025-02-06 00:59:34 +05:30
parent 202129e3b5
commit 91c8bc7105
4 changed files with 53 additions and 15 deletions

View File

@ -36,6 +36,13 @@
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureReader, sysprof_capture_reader_unref)
/*This global variable is probably not multithreading safe,
*but this is the only way I can currently think of to make this work as intended.
*Although, it's written to only before any threads are spawned, so it should be fine.
*/
static gboolean enable_debuginfod;
struct _SysprofSymbolsBundle
{
SysprofInstrument parent_instance;
@ -53,6 +60,7 @@ sysprof_symbols_bundle_augment_fiber (gpointer user_data)
{
g_autoptr(SysprofDocumentLoader) loader = NULL;
g_autoptr(SysprofSymbolizer) elf = NULL;
g_autoptr(SysprofMultiSymbolizer) multi = NULL;
g_autoptr(SysprofDocument) document = NULL;
g_autoptr(GBytes) bytes = NULL;
SysprofRecording *recording = user_data;
@ -69,11 +77,24 @@ sysprof_symbols_bundle_augment_fiber (gpointer user_data)
return dex_future_new_for_error (g_steal_pointer (&error));
g_assert (SYSPROF_IS_DOCUMENT_LOADER (loader));
/* Only symbolize ELF symbols as the rest can be symbolized
* by the application without having to resort to decoding.
*/
multi = sysprof_multi_symbolizer_new ();
elf = sysprof_elf_symbolizer_new ();
sysprof_document_loader_set_symbolizer (loader, elf);
sysprof_multi_symbolizer_take (multi, SYSPROF_SYMBOLIZER (g_steal_pointer (&elf)));
#if HAVE_DEBUGINFOD
if (enable_debuginfod)
{
g_autoptr(SysprofSymbolizer) debuginfod = NULL;
g_autoptr(GError) debuginfod_error = NULL;
if (!(debuginfod = sysprof_debuginfod_symbolizer_new (&debuginfod_error)))
g_warning ("Failed to create debuginfod symbolizer: %s", debuginfod_error->message);
else
sysprof_multi_symbolizer_take (multi, g_steal_pointer (&debuginfod));
}
#endif
sysprof_document_loader_set_symbolizer (loader, SYSPROF_SYMBOLIZER (multi));
if (!(document = dex_await_object (_sysprof_document_loader_load (loader), &error)))
return dex_future_new_for_error (g_steal_pointer (&error));
@ -129,5 +150,13 @@ sysprof_symbols_bundle_init (SysprofSymbolsBundle *self)
SysprofInstrument *
sysprof_symbols_bundle_new (void)
{
enable_debuginfod = TRUE;
return g_object_new (SYSPROF_TYPE_SYMBOLS_BUNDLE, NULL);
}
SysprofInstrument *
sysprof_symbols_bundle_new_without_debuginfod (void)
{
enable_debuginfod = FALSE;
return g_object_new (SYSPROF_TYPE_SYMBOLS_BUNDLE, NULL);
}

View File

@ -36,6 +36,8 @@ SYSPROF_AVAILABLE_IN_ALL
GType sysprof_symbols_bundle_get_type (void) G_GNUC_CONST;
SYSPROF_AVAILABLE_IN_ALL
SysprofInstrument *sysprof_symbols_bundle_new (void);
SYSPROF_AVAILABLE_IN_ALL
SysprofInstrument *sysprof_symbols_bundle_new_without_debuginfod (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofSymbolsBundle, g_object_unref)

View File

@ -46,6 +46,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureReader, sysprof_capture_reader_unre
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofCaptureWriter, sysprof_capture_writer_unref)
static gboolean no_decode;
static gboolean enable_debuginfod;
static GMainLoop *main_loop;
static SysprofRecording *active_recording;
@ -337,6 +338,7 @@ main (int argc,
{ "buffer-size", 0, 0, G_OPTION_ARG_INT, &n_buffer_pages, N_("The size of the buffer in pages (1 = 1 page)") },
{ "monitor-bus", 0, 0, G_OPTION_ARG_STRING_ARRAY, &monitor_bus, N_("Additional D-Bus address to monitor") },
{ "stack-size", 0, 0, G_OPTION_ARG_INT, &stack_size, N_("Stack size to copy for unwinding in user-space") },
{ "no-debuginfod", 0, 0, G_OPTION_ARG_NONE, &enable_debuginfod, N_("Do not use debuginfod to resolve symbols") },
{ NULL }
};
@ -550,7 +552,12 @@ Examples:\n\
sysprof_profiler_add_instrument (profiler, sysprof_disk_usage_new ());
if (!no_decode)
sysprof_profiler_add_instrument (profiler, sysprof_symbols_bundle_new ());
{
if(enable_debuginfod)
sysprof_profiler_add_instrument (profiler, sysprof_symbols_bundle_new_without_debuginfod ());
else
sysprof_profiler_add_instrument (profiler, sysprof_symbols_bundle_new ());
}
if (!no_cpu)
sysprof_profiler_add_instrument (profiler, sysprof_cpu_usage_new ());

View File

@ -795,16 +795,16 @@ sysprof_recording_template_create_loader (SysprofRecordingTemplate *self,
sysprof_document_loader_set_symbolizer (loader, SYSPROF_SYMBOLIZER (multi));
#if HAVE_DEBUGINFOD
if (self->debuginfod)
{
g_autoptr(SysprofSymbolizer) debuginfod = NULL;
g_autoptr(GError) debuginfod_error = NULL;
if (!(debuginfod = sysprof_debuginfod_symbolizer_new (&debuginfod_error)))
g_warning ("Failed to create debuginfod symbolizer: %s", debuginfod_error->message);
else
sysprof_multi_symbolizer_take (multi, g_steal_pointer (&debuginfod));
}
if (self->debuginfod)
{
g_autoptr(SysprofSymbolizer) debuginfod = NULL;
g_autoptr(GError) debuginfod_error = NULL;
if (!(debuginfod = sysprof_debuginfod_symbolizer_new (&debuginfod_error)))
g_warning ("Failed to create debuginfod symbolizer: %s", debuginfod_error->message);
else
sysprof_multi_symbolizer_take (multi, g_steal_pointer (&debuginfod));
}
#endif
return g_steal_pointer (&loader);