From 140e34f057462d5ff7818ab4af368f055eaad4e3 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 28 Sep 2013 13:50:19 +0200 Subject: [PATCH] systemtap: provide an appropriate tapset It should be possible to get something sensible with: stap -e 'probe lldpd.* { print($$vars) }' --- configure.ac | 1 + m4/systemtap.m4 | 1 + src/daemon/Makefile.am | 6 ++++++ src/daemon/dtrace2systemtap.awk | 25 +++++++++++++++++++++++++ src/daemon/probes.d | 23 +++++++++++------------ 5 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 src/daemon/dtrace2systemtap.awk diff --git a/configure.ac b/configure.ac index dab40293..1982ed68 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ AM_PROG_CC_C_O AC_PROG_LIBTOOL AC_PROG_LN_S AC_PROG_EGREP +AC_PROG_AWK # Doxygen DX_HTML_FEATURE(ON) diff --git a/m4/systemtap.m4 b/m4/systemtap.m4 index daa6c34b..0564e3da 100644 --- a/m4/systemtap.m4 +++ b/m4/systemtap.m4 @@ -4,6 +4,7 @@ # Check for DTrace/Systemtap support AC_DEFUN([lldp_SYSTEMTAP], [ + # Enable systemtap support lldp_ARG_ENABLE([dtrace], [systemtap/DTrace trace support], [no]) AM_CONDITIONAL([ENABLE_SYSTEMTAP], [test x"$enable_dtrace" = x"yes"]) if test x"$enable_dtrace" = x"yes"; then diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am index 80fa5e7e..a0c5bc85 100644 --- a/src/daemon/Makefile.am +++ b/src/daemon/Makefile.am @@ -96,6 +96,7 @@ lldpd_SOURCES = main.c lldpd_LDADD = liblldpd.la @LIBEVENT_LDFLAGS@ ## Systemtap/DTrace +EXTRA_DIST = dtrace2systemtap.awk if ENABLE_SYSTEMTAP BUILT_SOURCES += probes.h probes.h: probes.d @@ -105,6 +106,11 @@ probes.o: probes.d $(AM_V_GEN) $(AM_V_at)$(DTRACE) -C -G -s $< -o $@ lldpd_LDADD += probes.o + +lldpd.stp: probes.d $(srcdir)/dtrace2systemtap.awk $(top_builddir)/config.status + $(AM_V_GEN)$(AWK) -f $(srcdir)/dtrace2systemtap.awk -v sbindir=$(sbindir) $< > $@ || ( rm -f $@ ; exit 1 ) +tapsetdir = $(datadir)/systemtap/tapset +tapset_DATA = lldpd.stp endif ## libevent diff --git a/src/daemon/dtrace2systemtap.awk b/src/daemon/dtrace2systemtap.awk new file mode 100644 index 00000000..37610085 --- /dev/null +++ b/src/daemon/dtrace2systemtap.awk @@ -0,0 +1,25 @@ +#!/usr/bin/awk -f + +# Convert a simple dtrace probe files into a tapset. Heavily inspired +# by dtrace2systemtap.pl from libvirt + +($1 == "provider") { + provider = $2 +} + +($1 == "probe") { + name = substr($2, 0, index($2, "(") - 1) + split(substr($0, index($0, "(") + 1, index($0, ")") - index($0, "(") - 1), + args, /, /) + printf "probe %s.%s = process(\"%s/%s\").provider(\"%s\").mark(\"%s\") {\n", provider, name, sbindir, provider, provider, name + for (arg in args) { + match(args[arg], /^(.+[^a-z_])([a-z_]+)$/, aarg) + type = aarg[1] + argname = aarg[2] + if (type == "char *") + printf " %s = user_string($arg%d);\n", argname, arg + else + printf " %s = $arg%d;\n", argname, arg + } + printf "}\n\n" +} diff --git a/src/daemon/probes.d b/src/daemon/probes.d index 7528f962..a4d77854 100644 --- a/src/daemon/probes.d +++ b/src/daemon/probes.d @@ -22,7 +22,7 @@ provider lldpd { * @param frame the received frame * @param len the len of the received frame */ - probe frame_received(const char *ifname, void *frame, size_t len); + probe frame_received(char *ifname, void *frame, size_t len); /** * Fired when a frame is decoded. @@ -31,15 +31,14 @@ provider lldpd { * @param chassis_name the name of chassis (may be NULL) * @param port_descr the description of the port (may be NULL) */ - probe frame_decoded(const char *ifname, const char *protocol, - const char *chassis_name, const char *port_descr); + probe frame_decoded(char *ifname, char *protocol, char *chassis_name, char *port_descr); /** * Fired when a frame is sent. * @param ifname the name of the interface * @param protocol the name of the protocol */ - probe frame_send(const char *ifname, const char *protocol); + probe frame_send(char *ifname, char *protocol); /** * Fired when a neighbor is added. @@ -48,7 +47,7 @@ provider lldpd { * @param port_descr the description of the port (may be NULL) * @param count the total number of neighbors known */ - probe neighbor_new(const char *ifname, const char *chassis_name, const char *port_descr, int count); + probe neighbor_new(char *ifname, char *chassis_name, char *port_descr, int count); /** * Fired when a neighbor is updated. @@ -57,7 +56,7 @@ provider lldpd { * @param port_descr the description of the port (may be NULL) * @param count the total number of neighbors known */ - probe neighbor_update(const char *ifname, const char *chassis_name, const char *port_descr, int count); + probe neighbor_update(char *ifname, char *chassis_name, char *port_descr, int count); /** * Fired when a neighbor is deleted. @@ -66,13 +65,13 @@ provider lldpd { * @param port_descr the description of the port (may be NULL) * @param count the total number of neighbors known */ - probe neighbor_delete(const char *ifname, const char *chassis_name, const char *port_descr); + probe neighbor_delete(char *ifname, char *chassis_name, char *port_descr); /** * Fired before handling a client request. * @param name the name of the request */ - probe client_request(const char *name); + probe client_request(char *name); /** * Fired for each iteration of the event loop. @@ -83,14 +82,14 @@ provider lldpd { * Fired when initializing a new interface in privileged mode. * @param name the name of the interface */ - probe priv_interface_init(const char *name); + probe priv_interface_init(char *name); /** * Fired when setting description of an interface. * @param name the name of the interface * @param desc the description of the interface */ - probe priv_interface_description(const char *name, const char *description); + probe priv_interface_description(char *name, char *description); /** * Fired when doing an interface updates. @@ -106,11 +105,11 @@ provider lldpd { * Fired when an interface is removed. * @param name the name of the interface */ - probe interfaces_delete(const char *name); + probe interfaces_delete(char *name); /** * Fired when an interface is added. * @param name the name of the interface */ - probe interfaces_new(const char *name); + probe interfaces_new(char *name); }; -- 2.39.5