]> sourceware.org Git - systemtap.git/commitdiff
scripts/stap2perf: generate 'perf probe' command lines
authorFrank Ch. Eigler <fche@redhat.com>
Fri, 27 Mar 2015 22:55:49 +0000 (18:55 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Fri, 27 Mar 2015 22:55:49 +0000 (18:55 -0400)
As a tool to help diagnose suspected kernel kprobes/uprobes
problems, this script may be helpful to generate "perf probe ..."
command lines from a stap script or probe pattern.

scripts/stap2perf [new file with mode: 0755]

diff --git a/scripts/stap2perf b/scripts/stap2perf
new file mode 100755 (executable)
index 0000000..8b11667
--- /dev/null
@@ -0,0 +1,60 @@
+#! /bin/sh
+
+
+# This little script tries to formulate a series of "perf probe"
+# commands that touch the same probe locations as the stap script
+# would.  This can be used to check stap's "alibi" against
+# kprobes/uprobes malfunctions.
+#
+# This is an imperfect mapping, requiring manual checking.
+#
+# Usage:
+
+#  (stap -l PATTERN [-c COMMAND]; ...) | stap2perf | sh
+#  (stap -p2 -e SCRIPT [-c COMMAND]; ...) | stap2perf | sh
+#  perf list | grep probe
+#  perf record -e 'probe*:*' COMMAND
+#  perf report
+#  perf probe -d 'probe*:*'
+
+
+function param1() {
+    # fish out the first literal-string parameter
+    echo "$1" | cut -f2 -d'"' | cut -f1 -d@ | cut -f1 -d'<'
+}
+
+function param2() {
+    # fish out the second literal-string parameter
+    echo "$1" | cut -f4 -d'"' | cut -f1 -d@ | cut -f1 -d'<'
+}
+
+
+while read pp; do
+    case "$pp" in
+        kernel.function*)
+            fn=`param1 "$pp"`
+            nr=`expr "$pp" : '.*\.return.*'`
+            if [ $nr -eq 0 ]; then
+                echo perf probe -a "kernel_$fn"
+            else
+                echo perf probe -a "kernel_${fn}_return=${fn}%return"
+            fi
+            ;;
+
+        process*function*)
+            proc=`param1 "$pp"`
+            procbn=`basename $proc`
+            fn=`param2 "$pp"`
+            nr=`expr "$pp" : '.*\.return.*'`
+            if [ $nr -eq 0 ]; then
+                echo perf probe -a "${procbn}_${fn}=$fn" -x "$proc"
+            else
+                echo perf probe -a "${procbn}_${fn}_return=${fn}%return" -x "$proc"
+            fi
+            ;;
+    esac
+done | sort | uniq
+
+echo
+echo
+echo perf list "|" grep probe
This page took 0.031185 seconds and 5 git commands to generate.