]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: generate trace events for log messages
authorQuentin Young <qlyoung@nvidia.com>
Mon, 14 Sep 2020 22:05:47 +0000 (18:05 -0400)
committerQuentin Young <qlyoung@nvidia.com>
Fri, 23 Oct 2020 19:13:51 +0000 (15:13 -0400)
LTTng supports tracef() and tracelog() macros, which work like printf,
and are used to ease transition between logging and tracing. Messages
printed using these macros end up as trace events. For our uses we are
not interested in dropping logging, but it is nice to get log messages
in trace output, so I've added a call to tracelog() in zlog that dumps
our zlog messages as trace events.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
lib/trace.h
lib/zlog.c

index dd6fb73ae40dc74b028773531f1f3448d964f094..d605cad0c4b9ccf32685bfe18cd4d5b0ef93d2b4 100644 (file)
@@ -107,6 +107,7 @@ THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_call)
 /* clang-format on */
 
 #include <lttng/tracepoint-event.h>
+#include <lttng/tracelog.h>
 
 #else /* HAVE_LTTNG */
 
index 8dfd20371b8263425d4a21feee9f9f498a96075e..f28ff08617599380a60c761a25e48fee52a7ee3f 100644 (file)
@@ -52,6 +52,7 @@
 #include "printfrr.h"
 #include "frrcu.h"
 #include "zlog.h"
+#include "trace.h"
 
 DEFINE_MTYPE_STATIC(LIB, LOG_MESSAGE,  "log message")
 DEFINE_MTYPE_STATIC(LIB, LOG_TLSBUF,   "log thread-local buffer")
@@ -450,6 +451,34 @@ void vzlog(int prio, const char *fmt, va_list ap)
 {
        struct zlog_tls *zlog_tls = zlog_tls_get();
 
+#ifdef HAVE_LTTNG
+       va_list copy;
+       va_copy(copy, ap);
+       char *msg = vasprintfrr(MTYPE_LOG_MESSAGE, fmt, copy);
+
+       switch (prio) {
+       case LOG_ERR:
+               tracelog(TRACE_ERR, msg);
+               break;
+       case LOG_WARNING:
+               tracelog(TRACE_WARNING, msg);
+               break;
+       case LOG_DEBUG:
+               tracelog(TRACE_DEBUG, msg);
+               break;
+       case LOG_NOTICE:
+               tracelog(TRACE_DEBUG, msg);
+               break;
+       case LOG_INFO:
+       default:
+               tracelog(TRACE_INFO, msg);
+               break;
+       }
+
+       va_end(copy);
+       XFREE(MTYPE_LOG_MESSAGE, msg);
+#endif
+
        if (zlog_tls)
                vzlog_tls(zlog_tls, prio, fmt, ap);
        else