| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
|
| 4 |
# This little script tries to formulate a series of "perf probe" |
| 5 |
# commands that touch the same probe locations as the stap script |
| 6 |
# would. This can be used to check stap's "alibi" against |
| 7 |
# kprobes/uprobes malfunctions. |
| 8 |
# |
| 9 |
# This is an imperfect mapping, requiring manual checking. |
| 10 |
# |
| 11 |
# Usage: |
| 12 |
|
| 13 |
# (stap -l PATTERN [-c COMMAND]; ...) | stap2perf | sh |
| 14 |
# (stap -p2 -e SCRIPT [-c COMMAND]; ...) | stap2perf | sh |
| 15 |
# perf list | grep probe |
| 16 |
# perf record -e 'probe*:*' COMMAND |
| 17 |
# perf report |
| 18 |
# perf probe -d 'probe*:*' |
| 19 |
|
| 20 |
|
| 21 |
function param1() { |
| 22 |
# fish out the first literal-string parameter |
| 23 |
echo "$1" | cut -f2 -d'"' | cut -f1 -d@ | cut -f1 -d'<' |
| 24 |
} |
| 25 |
|
| 26 |
function param2() { |
| 27 |
# fish out the second literal-string parameter |
| 28 |
echo "$1" | cut -f4 -d'"' | cut -f1 -d@ | cut -f1 -d'<' |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
while read pp; do |
| 33 |
case "$pp" in |
| 34 |
kernel.function*) |
| 35 |
fn=`param1 "$pp"` |
| 36 |
nr=`expr "$pp" : '.*\.return.*'` |
| 37 |
if [ $nr -eq 0 ]; then |
| 38 |
echo perf probe -a "kernel_$fn" |
| 39 |
else |
| 40 |
echo perf probe -a "kernel_${fn}_return=${fn}%return" |
| 41 |
fi |
| 42 |
;; |
| 43 |
|
| 44 |
process*function*) |
| 45 |
proc=`param1 "$pp"` |
| 46 |
procbn=`basename $proc` |
| 47 |
fn=`param2 "$pp"` |
| 48 |
nr=`expr "$pp" : '.*\.return.*'` |
| 49 |
if [ $nr -eq 0 ]; then |
| 50 |
echo perf probe -x "$proc"-a "${procbn}_${fn}=$fn" |
| 51 |
else |
| 52 |
echo perf probe -x "$proc"-a "${procbn}_${fn}_return=${fn}%return" |
| 53 |
fi |
| 54 |
;; |
| 55 |
esac |
| 56 |
done | sort | uniq |
| 57 |
|
| 58 |
echo |
| 59 |
echo |
| 60 |
echo perf list "|" grep probe |