Change in libosmocore[master]: initial support for static userspace probes via systemtap

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Thu Oct 8 16:41:03 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20491 )


Change subject: initial support for static userspace probes via systemtap
......................................................................

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: stderr_start
and stderr_done.  They can be used to trace the amount of time
a libosmocore-using application spends in blocking calls to log
to stderr.

Change-Id: I7e1ab664241deb524c9582cbd1bec31af46c747e
---
M Makefile.am
M configure.ac
M src/Makefile.am
M src/logging.c
A src/probes.d
A tapset/Makefile.am
A tapset/libosmocore.stp
7 files changed, 103 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/91/20491/1

diff --git a/Makefile.am b/Makefile.am
index f2a05a9..ab2aad9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 ACLOCAL_AMFLAGS = -I m4
 
 AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include
-SUBDIRS = include src src/vty src/codec src/gsm src/coding src/gb src/ctrl src/sim src/pseudotalloc src/usb utils tests
+SUBDIRS = include src src/vty src/codec src/gsm src/coding src/gb src/ctrl src/sim src/pseudotalloc src/usb utils tapset tests
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libosmocore.pc libosmocodec.pc libosmovty.pc libosmogsm.pc \
diff --git a/configure.ac b/configure.ac
index b07a3bd..e26d8a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -392,6 +392,38 @@
 AC_MSG_RESULT([$neon])
 AM_CONDITIONAL(HAVE_NEON, [test "x$neon" != "xno"])
 
+#
+# SystemTap support
+#
+AC_MSG_CHECKING([whether to include systemtap tracing support])
+AC_ARG_ENABLE([systemtap],
+	      [AS_HELP_STRING([--enable-systemtap],
+			      [Enable inclusion of systemtap trace support])],
+	      [ENABLE_SYSTEMTAP="${enableval}"], [ENABLE_SYSTEMTAP='no'])
+AM_CONDITIONAL([ENABLE_SYSTEMTAP], [test x$ENABLE_SYSTEMTAP = xyes])
+AC_MSG_RESULT(${ENABLE_SYSTEMTAP})
+
+if test "x${ENABLE_SYSTEMTAP}" = xyes; then
+  # Additional configuration for --enable-systemtap is HERE
+  AC_CHECK_PROGS(DTRACE, dtrace)
+  if test -z "$DTRACE"; then
+    AC_MSG_ERROR([dtrace not found])
+  fi
+  AC_CHECK_HEADER([sys/sdt.h], [SDT_H_FOUND='yes'],
+                [SDT_H_FOUND='no';
+                   AC_MSG_ERROR([systemtap support needs sys/sdt.h header])])
+  AC_DEFINE([HAVE_SYSTEMTAP], [1], [Define to 1 if using SystemTap probes.])
+  AC_ARG_WITH([tapset-install-dir],
+	      [AS_HELP_STRING([--with-tapset-install-dir],
+	         [The absolute path where the tapset dir will be installed])],
+	      [if test "x${withval}" = x; then
+		 ABS_TAPSET_DIR="\$(datadir)/systemtap/tapset"
+	       else
+		 ABS_TAPSET_DIR="${withval}"
+	       fi], [ABS_TAPSET_DIR="\$(datadir)/systemtap/tapset"])
+  AC_SUBST(ABS_TAPSET_DIR)
+fi
+
 
 OSMO_AC_CODE_COVERAGE
 
@@ -446,6 +478,7 @@
 	src/gb/Makefile
 	src/ctrl/Makefile
 	src/pseudotalloc/Makefile
+	tapset/Makefile
 	tests/Makefile
 	tests/atlocal
 	utils/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 891b4a6..f03ce55 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,7 @@
 			 sockaddr_str.c \
 			 use_count.c \
 			 exec.c \
+			 probes.d \
 			 $(NULL)
 
 if HAVE_SSSE3
@@ -71,5 +72,16 @@
 libosmocore_la_SOURCES += serial.c
 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 b20b031..f3833f1 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -45,6 +45,17 @@
 #include <syslog.h>
 #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 <time.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -703,9 +714,11 @@
 {
 	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 0000000..c16eb1e
--- /dev/null
+++ b/src/probes.d
@@ -0,0 +1,4 @@
+provider libosmocore {
+	probe log_start();
+	probe log_done();
+};
diff --git a/tapset/Makefile.am b/tapset/Makefile.am
new file mode 100644
index 0000000..a07a3b1
--- /dev/null
+++ b/tapset/Makefile.am
@@ -0,0 +1,22 @@
+.PHONY: clean-local install-data-hook uninstall-local
+
+EXTRA_DIST = libosmocore.stp
+TAPSET_FILES = $(EXTRA_DIST)
+TAPSET_INSTALL_DIR = $(DESTDIR)@ABS_TAPSET_DIR@
+
+if ENABLE_SYSTEMTAP
+all-local: $(TAPSET_FILES)
+
+clean-local:
+
+install-data-hook:
+	$(MKDIR_P) $(TAPSET_INSTALL_DIR)
+	$(INSTALL_DATA) $(TAPSET_FILES) $(TAPSET_INSTALL_DIR)
+
+uninstall-local:
+	@list='$(TAPSET_FILES)'; for p in $$list; do \
+	  echo " rm -f '$(TAPSET_INSTALL_DIR)/$$p'"; \
+	  rm -f "$(TAPSET_INSTALL_DIR)/$$p"; \
+	done
+
+endif
diff --git a/tapset/libosmocore.stp b/tapset/libosmocore.stp
new file mode 100644
index 0000000..10fa7b2
--- /dev/null
+++ b/tapset/libosmocore.stp
@@ -0,0 +1,18 @@
+/* libosmocore tapset
+ *
+ * This file is part of libosmocore.
+ *
+ * Each probe defines the probe name and a full probestr which consist of the probe name and between
+ * brackets all argument names and values.
+ */
+
+probe libosmocore_stderr_start = process("libosmocore").mark("stderr_start")
+{
+ count = $arg1;
+ probestr = sprintf("%s(count=%d), $$name, count);
+}
+
+probe libosmocore_stderr_done = process("libosmocore").mark("stderr_done")
+{
+ probestr = sprintf("%s", $$name);
+}

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20491
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I7e1ab664241deb524c9582cbd1bec31af46c747e
Gerrit-Change-Number: 20491
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201008/400bf74d/attachment.htm>


More information about the gerrit-log mailing list