From 433005c87c88912358bfd02d4b0d997b52b04013 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 26 Sep 2020 11:51:32 +0200 Subject: initial support for static userspace probes via systemtap This adds a --enable-systemtap configure option, which will then add static tracepoints to the generated libosmocore binary. At this point, only two tracepoints are supported: log_start and log_done. They can be used to trace the amount of time a libosmocore-using application spends in potentiall blocking calls to log to stderr or to files. Related: OS#4311 Change-Id: I7e1ab664241deb524c9582cbd1bec31af46c747e --- src/Makefile.am | 12 ++++++++++++ src/logging.c | 13 +++++++++++++ src/probes.d | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 src/probes.d (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index dd31db88..a2566a33 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ libosmocore_la_SOURCES = context.c timer.c timer_gettimeofday.c timer_clockgetti use_count.c \ exec.c \ it_q.c \ + probes.d \ $(NULL) if HAVE_SSSE3 @@ -82,5 +83,16 @@ libosmocore_la_SOURCES += mnl.c libosmocore_la_LIBADD += $(LIBMNL_LIBS) endif +if ENABLE_SYSTEMTAP +probes.h: probes.d + $(DTRACE) -C -h -s $< -o $@ + +probes.lo: probes.d + $(LIBTOOL) --mode=compile $(AM_V_lt) --tag=CC env CFLAGS="$(CFLAGS)" $(DTRACE) -C -G -s $< -o $@ + +BUILT_SOURCES += probes.h probes.lo +libosmocore_la_LIBADD += probes.lo +endif + crc%gen.c: crcXXgen.c.tpl $(AM_V_GEN)sed -e's/XX/$*/g' $< > $@ diff --git a/src/logging.c b/src/logging.c index 60dba64c..a40008e9 100644 --- a/src/logging.c +++ b/src/logging.c @@ -44,6 +44,17 @@ #include #endif +#ifdef HAVE_SYSTEMTAP +/* include the generated probes header and put markers in code */ +#include "probes.h" +#define TRACE(probe) probe +#define TRACE_ENABLED(probe) probe ## _ENABLED() +#else +/* Wrap the probe to allow it to be removed when no systemtap available */ +#define TRACE(probe) +#define TRACE_ENABLED(probe) (0) +#endif /* HAVE_SYSTEMTAP */ + #include #include #include @@ -670,9 +681,11 @@ void logp2(int subsys, unsigned int level, const char *file, int line, int cont, { va_list ap; + TRACE(LIBOSMOCORE_LOG_START()); va_start(ap, format); osmo_vlogp(subsys, level, file, line, cont, format, ap); va_end(ap); + TRACE(LIBOSMOCORE_LOG_DONE()); } /*! Register a new log target with the logging core diff --git a/src/probes.d b/src/probes.d new file mode 100644 index 00000000..c16eb1ee --- /dev/null +++ b/src/probes.d @@ -0,0 +1,4 @@ +provider libosmocore { + probe log_start(); + probe log_done(); +}; -- cgit v1.2.3