| 1 |
#! /usr/bin/env stap |
| 2 |
global cycles_per_insn |
| 3 |
global branch_per_insn |
| 4 |
global cacheref_per_insn |
| 5 |
global insns |
| 6 |
global cycles |
| 7 |
global branches |
| 8 |
global cacherefs |
| 9 |
global insn |
| 10 |
|
| 11 |
probe perf.hw.instructions.process("/usr/bin/find").counter("find_insns") {} |
| 12 |
probe perf.hw.cpu_cycles.process("/usr/bin/find").counter("find_cycles") {} |
| 13 |
probe perf.hw.branch_instructions.process("/usr/bin/find").counter("find_branches") {} |
| 14 |
probe perf.hw.cache_references.process("/usr/bin/find").counter("find_cache_refs") {} |
| 15 |
|
| 16 |
probe process("/usr/bin/find").function("visit") # generally .inline'd, thus the need for debuginfo |
| 17 |
{ |
| 18 |
insn["find_insns"] = @perf("find_insns") |
| 19 |
insns <<< (insn["find_insns"]) |
| 20 |
insn["find_cycles"] = @perf("find_cycles") |
| 21 |
cycles <<< insn["find_cycles"] |
| 22 |
insn["find_branches"] = @perf("find_branches") |
| 23 |
branches <<< insn["find_branches"] |
| 24 |
insn["find_cache_refs"] = @perf("find_cache_refs") |
| 25 |
cacherefs <<< insn["find_cache_refs"] |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
probe process("/usr/bin/find").function("visit").return !, |
| 30 |
process("/usr/bin/find").statement("[email protected]+13").nearest # in lieu of .inline.return |
| 31 |
{ |
| 32 |
dividend = (@perf("find_cycles") - insn["find_cycles"]) |
| 33 |
divisor = (@perf("find_insns") - insn["find_insns"]) |
| 34 |
q = (divisor > 0 ? dividend / divisor : 0) |
| 35 |
if (q > 0) |
| 36 |
cycles_per_insn <<< q |
| 37 |
|
| 38 |
dividend = (@perf("find_branches") - insn["find_branches"]) |
| 39 |
q = (divisor > 0 ? dividend / divisor : 0) |
| 40 |
if (q > 0) |
| 41 |
branch_per_insn <<< q |
| 42 |
|
| 43 |
dividend = (@perf("find_cycles") - insn["find_cycles"]) |
| 44 |
q = (divisor > 0 ? dividend / divisor : 0) |
| 45 |
if (q > 0) |
| 46 |
cacheref_per_insn <<< q |
| 47 |
} |
| 48 |
|
| 49 |
probe end |
| 50 |
{ |
| 51 |
if (@count(cycles_per_insn)) { |
| 52 |
printf ("Cycles per Insn\n\n") |
| 53 |
print (@hist_log(cycles_per_insn)) |
| 54 |
} |
| 55 |
if (@count(branch_per_insn)) { |
| 56 |
printf ("\nBranches per Insn\n\n") |
| 57 |
print (@hist_log(branch_per_insn)) |
| 58 |
} |
| 59 |
if (@count(cacheref_per_insn)) { |
| 60 |
printf ("Cache Refs per Insn\n\n") |
| 61 |
print (@hist_log(cacheref_per_insn)) |
| 62 |
} |
| 63 |
} |
| 64 |
|