[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] trace: Add USDT probes generation support



commit 668fc70a20c602bb0e74bf0e19589a17bb45b7ae
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Tue Jan 14 14:58:09 2020 -0500

    trace: Add USDT probes generation support
    
    This commit adds both configure options and probe generation for tracepoints.
    
    Part of #32910
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 configure.ac                  | 21 ++++++++++++++++++++-
 src/lib/trace/events.h        | 13 +++++++++----
 src/lib/trace/include.am      |  4 ++++
 src/lib/trace/usdt/include.am |  3 +++
 src/lib/trace/usdt/usdt.h     | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 680111b10..170d8dc20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -258,6 +258,20 @@ AC_ARG_ENABLE(libscrypt,
 
 dnl --- Tracing Options. ---
 
+dnl USDT instrumentation option.
+AC_ARG_ENABLE(tracing-instrumentation-usdt,
+              AS_HELP_STRING([--enable-tracing-instrumentation-usdt],
+                             [build with tracing USDT instrumentation]))
+AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_USDT],
+               [test "x$enable_tracing_instrumentation_usdt" = "xyes"])
+
+if test "x$enable_tracing_instrumentation_usdt" = "xyes"; then
+  AC_CHECK_HEADERS([sys/sdt.h], [],
+                   [AC_MSG_ERROR([USDT instrumentation requires sys/sdt.h header.
+                                  On Debian, apt install systemtap-sdt-dev])], [])
+  AC_DEFINE([USE_TRACING_INSTRUMENTATION_USDT], [1], [Using USDT instrumentation])
+fi
+
 dnl Tracepoints event to debug logs.
 AC_ARG_ENABLE(tracing-instrumentation-log-debug,
      AS_HELP_STRING([--enable-tracing-instrumentation-log-debug],
@@ -267,9 +281,11 @@ AC_ARG_ENABLE(tracing-instrumentation-log-debug,
 AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
                [test "x$enable_tracing_instrumentation_log_debug" = "xyes"])
 
-dnl Define that tracing is supported.
+dnl Define that tracing is supported if any instrumentation is used.
 AM_COND_IF([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
            AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
+AM_COND_IF([USE_TRACING_INSTRUMENTATION_USDT],
+           AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
 
 dnl -- End Tracing Options. --
 
@@ -2731,6 +2747,9 @@ PPRINT_SUBTITLE([Tracing])
 test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
 PPRINT_PROP_BOOL([Tracepoints to log_debug() (--enable-tracing-instrumentation-log-debug)], $value)
 
+test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
+PPRINT_PROP_BOOL([USDT Instrumentation (--enable-tracing-instrumentation-usdt)], $value)
+
 AS_ECHO
 PPRINT_SUBTITLE([Install Directories])
 
diff --git a/src/lib/trace/events.h b/src/lib/trace/events.h
index b1b31fdc9..fcd31e24e 100644
--- a/src/lib/trace/events.h
+++ b/src/lib/trace/events.h
@@ -3,7 +3,7 @@
 
 /**
  * \file events.h
- * \brief Header file for Tor event tracing.
+ * \brief Header file for Tor tracing instrumentation definition.
  **/
 
 #ifndef TOR_LIB_TRACE_EVENTS_H
@@ -13,15 +13,20 @@
 
 #ifdef HAVE_TRACING
 
-#define tor_trace(subsystem, event_name, ...)           \
-  do {                                                  \
-    TOR_TRACE_LOG_DEBUG(tor_ ## subsystem, event_name); \
+#define tor_trace(subsystem, event_name, ...)                       \
+  do {                                                              \
+    TOR_TRACE_LOG_DEBUG(tor_ ## subsystem, event_name);             \
+    TOR_TRACE_USDT(tor_ ## subsystem, event_name, ## __VA_ARGS__);  \
   } while (0)
 
 /* This corresponds to the --enable-tracing-instrumentation-log-debug
  * configure option which maps all tracepoints to a log_debug() statement. */
 #include "lib/trace/debug.h"
 
+/* This corresponds to the --enable-tracing-instrumentation-usdt configure
+ * option which will generate USDT probes for each tracepoints. */
+#include "lib/trace/usdt/usdt.h"
+
 #else /* !defined(HAVE_TRACING) */
 
 /* Reaching this point, tracing is disabled thus we NOP every tracepoints
diff --git a/src/lib/trace/include.am b/src/lib/trace/include.am
index 312fd4e87..01ea0c8a1 100644
--- a/src/lib/trace/include.am
+++ b/src/lib/trace/include.am
@@ -18,6 +18,10 @@ TRACEHEADERS += \
 	src/lib/trace/debug.h
 endif
 
+if USE_TRACING_INSTRUMENTATION_USDT
+include src/lib/trace/usdt/include.am
+endif
+
 src_lib_libtor_trace_a_SOURCES = $(LIBTOR_TRACE_A_SOURCES)
 
 noinst_HEADERS+= $(TRACEHEADERS)
diff --git a/src/lib/trace/usdt/include.am b/src/lib/trace/usdt/include.am
new file mode 100644
index 000000000..4e7e04c32
--- /dev/null
+++ b/src/lib/trace/usdt/include.am
@@ -0,0 +1,3 @@
+# ADD_C_FILE: INSERT HEADERS HERE.
+TRACEHEADERS += \
+	src/lib/trace/usdt/usdt.h
diff --git a/src/lib/trace/usdt/usdt.h b/src/lib/trace/usdt/usdt.h
new file mode 100644
index 000000000..0b5fd6c44
--- /dev/null
+++ b/src/lib/trace/usdt/usdt.h
@@ -0,0 +1,33 @@
+/* Copyright (c) 2020, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file trace.h
+ * \brief Header for usdt.h
+ **/
+
+#ifndef TOR_TRACE_USDT_USDT_H
+#define TOR_TRACE_USDT_USDT_H
+
+#ifdef USE_TRACING_INSTRUMENTATION_USDT
+
+#ifdef HAVE_SYS_SDT_H
+#define SDT_USE_VARIADIC
+#include <sys/sdt.h>
+#define TOR_STAP_PROBEV STAP_PROBEV
+#else /* defined(HAVE_SYS_SDT_H) */
+#define TOR_STAP_PROBEV(...)
+#endif
+
+/* Map events to an USDT probe. */
+#define TOR_TRACE_USDT(subsystem, event_name, ...) \
+  TOR_STAP_PROBEV(subsystem, event_name, ## __VA_ARGS__);
+
+#else /* !defined(USE_TRACING_INSTRUMENTATION_USDT) */
+
+/* NOP event. */
+#define TOR_TRACE_USDT(subsystem, event_name, ...)
+
+#endif /* !defined(USE_TRACING_INSTRUMENTATION_USDT) */
+
+#endif /* !defined(TOR_TRACE_USDT_USDT_H) */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits