Commit 668fc70a authored by David Goulet's avatar David Goulet 🔆
Browse files

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's avatarDavid Goulet <dgoulet@torproject.org>
parent 70f03152
......@@ -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])
......
......@@ -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
......
......@@ -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)
# ADD_C_FILE: INSERT HEADERS HERE.
TRACEHEADERS += \
src/lib/trace/usdt/usdt.h
/* 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) */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment