| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# The declaration order should be irrelevant. Run the script twice, each with |
| 4 |
# a different counter declaration order, counting the insns and cycles. For |
| 5 |
# each run get the difference between cycles and insns and find the the largest |
| 6 |
# term, e.g. 53874->50000. Check that this term is equal for both runs. |
| 7 |
# Caveat: possible false negative, if one run yields e.g. 59975->50000 and the |
| 8 |
# other yields 600200>600000 |
| 9 |
|
| 10 |
STAP=$1 |
| 11 |
|
| 12 |
declare -A perfresult |
| 13 |
for i in "first" "second"; do |
| 14 |
perfresult[$i]=$($STAP -u -g -c "/bin/cat $0 >/dev/null" -e ' |
| 15 |
global insn |
| 16 |
|
| 17 |
%( @1 == "first" %? |
| 18 |
probe perf.hw.instructions.process("/bin/cat").counter("find_insns") {} |
| 19 |
probe perf.hw.cpu_cycles.process("/bin/cat").counter("find_cycles") {} |
| 20 |
%: |
| 21 |
probe perf.hw.cpu_cycles.process("/bin/cat").counter("find_cycles") {} |
| 22 |
probe perf.hw.instructions.process("/bin/cat").counter("find_insns") {} |
| 23 |
%) |
| 24 |
|
| 25 |
function poly (val) %{ /* unprivileged */ |
| 26 |
int i; |
| 27 |
int root = 1; |
| 28 |
int j = STAP_ARG_val; |
| 29 |
if (j < 0) |
| 30 |
j = -j; |
| 31 |
for (root = 1; root < __LONG_MAX__; root *= 10) |
| 32 |
if (root > j) |
| 33 |
{ |
| 34 |
STAP_RETURN ((root/10) * (j / (root/10))); |
| 35 |
} |
| 36 |
STAP_RETURN(0); |
| 37 |
%} |
| 38 |
|
| 39 |
probe process("/bin/cat").function("main") |
| 40 |
{ |
| 41 |
insn["find_insns"] = @perf("find_insns") |
| 42 |
insn["find_cycles"] = @perf("find_cycles") |
| 43 |
} |
| 44 |
|
| 45 |
# in lieu of .return |
| 46 |
probe process("/bin/cat").function("main").return |
| 47 |
{ |
| 48 |
insn["find_cycles"] = (@perf("find_cycles") - insn["find_cycles"]) |
| 49 |
insn["find_insns"] = (@perf("find_insns") - insn["find_insns"]) |
| 50 |
} |
| 51 |
|
| 52 |
probe end |
| 53 |
{ |
| 54 |
printf ("%d\n", poly(insn["find_cycles"]-insn["find_insns"])) |
| 55 |
}' $i ) |
| 56 |
done |
| 57 |
|
| 58 |
|
| 59 |
if [ "${perfresult['first']}" = "${perfresult['second']}" ] ; then |
| 60 |
echo PASS: ${perfresult["first"]} |
| 61 |
else |
| 62 |
echo UNRESOLVED: ${perfresult["first"]} ${perfresult["second"]} |
| 63 |
fi |