| 1 |
#! /usr/bin/env stap |
| 2 |
# |
| 3 |
# Copyright (C) 2010-2015 Red Hat, Inc. |
| 4 |
# Written by William Cohen <[email protected]> |
| 5 |
# |
| 6 |
# The linetimes.stp script takes two arguments: where to find the function |
| 7 |
# and the function name. linetimes.stp will instrument each line in the |
| 8 |
# function. It will print out the number of times that the function is |
| 9 |
# called, a table with the average and maximum time each line takes, |
| 10 |
# and control flow information when the script exits. |
| 11 |
# |
| 12 |
# For example all the lines of the do_unlinkat function: |
| 13 |
# |
| 14 |
# stap linetimes.stp kernel do_unlinkat |
| 15 |
|
| 16 |
global calls, times, last_pp, region, cfg |
| 17 |
|
| 18 |
probe $1.function(@2).call { calls <<< 1 } |
| 19 |
probe $1.function(@2).return { |
| 20 |
t = gettimeofday_us() |
| 21 |
s = times[tid()] |
| 22 |
if (s) { |
| 23 |
e = t - s |
| 24 |
region[last_pp[tid()]] <<< e |
| 25 |
cfg[last_pp[tid()], pp()] <<< 1 |
| 26 |
} |
| 27 |
delete times[tid()] |
| 28 |
delete last_pp[tid()] |
| 29 |
} |
| 30 |
|
| 31 |
probe $1.statement(@2 "@*:*") { |
| 32 |
t = gettimeofday_us() |
| 33 |
s = times[tid()] |
| 34 |
if (s) { |
| 35 |
e = t - s |
| 36 |
region[last_pp[tid()]] <<< e |
| 37 |
cfg[last_pp[tid()], pp()] <<< 1 |
| 38 |
} |
| 39 |
times[tid()] = t |
| 40 |
last_pp[tid()] = pp() |
| 41 |
} |
| 42 |
|
| 43 |
probe end { |
| 44 |
printf("\n%s %s call count: %d\n", @1, @2, @count(calls)); |
| 45 |
printf("\n%-58s %10s %10s\n", "region", "avg(us)", "max(us)"); |
| 46 |
foreach (p+ in region) { |
| 47 |
printf("%-58s %10d %10d\n", p, @avg(region[p]), @max(region[p])); |
| 48 |
} |
| 49 |
|
| 50 |
printf("\n\ncontrol flow graph information\n") |
| 51 |
printf("from\n\tto\n=======================\n") |
| 52 |
foreach ([src+] in region) { |
| 53 |
printf("%-s\n", src) |
| 54 |
foreach ([s,dest+] in cfg[src,*]) { # slice for all dest's |
| 55 |
printf("\t%-s %d\n", dest, @count(cfg[src,dest])); |
| 56 |
} |
| 57 |
} |
| 58 |
} |