]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
systemtap: provide an appropriate tapset
authorVincent Bernat <bernat@luffy.cx>
Sat, 28 Sep 2013 11:50:19 +0000 (13:50 +0200)
committerVincent Bernat <bernat@luffy.cx>
Sat, 28 Sep 2013 11:50:19 +0000 (13:50 +0200)
It should be possible to get something sensible with:

    stap -e 'probe lldpd.* { print($$vars) }'

configure.ac
m4/systemtap.m4
src/daemon/Makefile.am
src/daemon/dtrace2systemtap.awk [new file with mode: 0644]
src/daemon/probes.d

index dab40293c67786a033a846f104b706831abe9a39..1982ed68590589a85e408f7541429e29c2adc7c2 100644 (file)
@@ -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)
index daa6c34b53d595cf03967843a045e96a51e5e738..0564e3da8784e3aeb78d855b3946e30081e32752 100644 (file)
@@ -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
index 80fa5e7e3f9c6ce3f84789156a52829f459a6226..a0c5bc85f3107ee93b1e7fd753cbc12047bf9634 100644 (file)
@@ -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 (file)
index 0000000..3761008
--- /dev/null
@@ -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"
+}
index 7528f9624e2ffc0a6a1eb967d2f010f9d3aebd4f..a4d778549c2c55c15a8f24376ec1670403562ae7 100644 (file)
@@ -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);
 };