From d31dab9f4fb655d04c227ab59e387cdf2113203f Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Fri, 27 Mar 2015 18:55:49 -0400 Subject: [PATCH] scripts/stap2perf: generate 'perf probe' command lines 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 | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 scripts/stap2perf diff --git a/scripts/stap2perf b/scripts/stap2perf new file mode 100755 index 000000000..8b116673c --- /dev/null +++ b/scripts/stap2perf @@ -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 -- 2.43.5