File: linetimes.stp

package info (click to toggle)
systemtap 2.6-0.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,220 kB
  • ctags: 10,944
  • sloc: cpp: 53,239; ansic: 50,615; exp: 33,694; sh: 9,906; xml: 7,665; perl: 2,089; python: 1,534; tcl: 1,236; makefile: 797; java: 148; lisp: 104; awk: 94; asm: 91; sed: 16
file content (76 lines) | stat: -rwxr-xr-x 2,009 bytes parent folder | download | duplicates (2)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/env stap
#
# Copyright (C) 2010 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()
  p = tid()
  s = times[p]
  if (s) {
    e = t - s
    region[last_pp[p]] <<< e
    cfg[last_pp[p], pp()] <<< 1
  }
  delete times[p]
  delete last_pp[p]
}

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

probe end {
  printf("\n%s called %d", @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("\ncontrol flow graph information\n")
  printf("from\n\tto\n=======================\n")
  foreach ([src+, dest] in cfg) {
    /* print elements */
    if (old_src != src) {
      if (count == 1) printf (" %d\n", old_count);
      printf ("%-s", src)
      count = 1
    } else {
      if (count == 1) {
        if (old_dest == src)
          printf ("\n\t%-s %d\n", old_dest, old_count);
        else
        printf ("\n\t%-s %d\n", old_dest, old_count);
      }
      ++count;
      printf ("\t%-s %d\n", dest, @count(cfg[src,dest]));
    }
    old_src = src
    old_dest = dest
    old_count = @count(cfg[src,dest])
  }
  /* print last element */
  if (old_src != "" && count == 1) printf (" %d\n", old_count)
}