From 01d196abe4452136b37e2f8dbda84adf710f196e Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 16 Mar 2020 12:26:05 -0700 Subject: [PATCH] libsysprof-collector: avoid formatting unless recording We can avoid the process of creating the log message altogether if we are not actively recording messages. --- src/libsysprof-capture/sysprof-collector.c | 38 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/libsysprof-capture/sysprof-collector.c b/src/libsysprof-capture/sysprof-collector.c index 5f06dd3a..3c96065f 100644 --- a/src/libsysprof-capture/sysprof-collector.c +++ b/src/libsysprof-capture/sysprof-collector.c @@ -461,12 +461,38 @@ sysprof_collector_log_printf (GLogLevelFlags severity, const gchar *format, ...) { - g_autofree gchar *formatted = NULL; - va_list args; + COLLECTOR_BEGIN { + g_autofree gchar *formatted = NULL; + SysprofCaptureLog *ev; + va_list args; + gsize len; + gsize sl; - va_start (args, format); - formatted = g_strdup_vprintf (format, args); - va_end (args); + va_start (args, format); + formatted = g_strdup_vprintf (format, args); + va_end (args); - sysprof_collector_log (severity, domain, formatted); + if (domain == NULL) + domain = ""; + + sl = strlen (formatted); + len = realign (sizeof *ev + sl + 1); + + if ((ev = mapped_ring_buffer_allocate (collector->buffer, len))) + { + ev->frame.len = len; + ev->frame.type = SYSPROF_CAPTURE_FRAME_LOG; + ev->frame.cpu = _do_getcpu (); + ev->frame.pid = collector->pid; + ev->frame.time = SYSPROF_CAPTURE_CURRENT_TIME; + ev->severity = severity & 0xFFFF; + ev->padding1 = 0; + ev->padding2 = 0; + g_strlcpy (ev->domain, domain, sizeof ev->domain); + memcpy (ev->message, formatted, sl); + ev->message[sl] = 0; + + mapped_ring_buffer_advance (collector->buffer, ev->frame.len); + } + } COLLECTOR_END; }