File: linetimes.stp

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (58 lines) | stat: -rwxr-xr-x 1,613 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env stap
#
# Copyright (C) 2010-2015 Red Hat, Inc.
# Written by William Cohen <wcohen@redhat.com>
#
# The linetimes.stp script takes two arguments: where to find the function
# and the function name. linetimes.stp will instrument each line in the
# function. It will print out the number of times that the function is
# called, a table with the average and maximum time each line takes,
# and control flow information when the script exits.
#
# For example all the lines of the do_unlinkat function:
#
# stap linetimes.stp kernel do_unlinkat

global calls, times, last_pp, region, cfg

probe $1.function(@2).call { calls <<< 1 }
probe $1.function(@2).return {
  t = gettimeofday_us()
  s = times[tid()]
  if (s) {
    e = t - s
    region[last_pp[tid()]] <<< e
    cfg[last_pp[tid()], pp()] <<< 1
  }
  delete times[tid()]
  delete last_pp[tid()]
}

probe $1.statement(@2 "@*:*") {
  t = gettimeofday_us()
  s = times[tid()]
  if (s) {
    e = t - s
    region[last_pp[tid()]] <<< e
    cfg[last_pp[tid()], pp()] <<< 1
  }
  times[tid()] = t
  last_pp[tid()] = pp()
}

probe end {
  printf("\n%s %s call count: %d\n", @1, @2, @count(calls));
  printf("\n%-58s %10s %10s\n", "region", "avg(us)", "max(us)");
  foreach (p+ in region) {
    printf("%-58s %10d %10d\n", p, @avg(region[p]), @max(region[p]));
  }

  printf("\n\ncontrol flow graph information\n")
  printf("from\n\tto\n=======================\n")
  foreach ([src+] in region) {
     printf("%-s\n", src)
     foreach ([s,dest+] in cfg[src,*]) { # slice for all dest's
        printf("\t%-s %d\n", dest, @count(cfg[src,dest]));
     }
  }
}