summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.samples/iotask2.stp
blob: cc4707b753860156d46dc07924767bfb8c8a2c1a (plain)
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
global names, opens, reads, writes

probe begin { println("starting probe") }

probe timer.ms(10000) {
  println("stopping probe after 10 seconds") 
  exit()
}

probe kernel.function("sys_open") {
  e=execname(); names[e]=1
  opens[e] ++  # simple integer array
}

probe kernel.function("sys_read") {
  e=execname(); names[e]=1
  reads[e] <<< $count # statistics array
}

probe kernel.function("sys_write") {
  e=execname(); names[e]=1
  writes[e] <<< $count # statistics array
}


probe end {
  foreach (name+ in names) { # sort by name
    printf("process: %s\n", name)
    if (opens[name])
      printf("opens n=%d\n", opens[name])
    if (@count(reads[name]))
      printf("reads n=%d, sum=%d, avg=%d\n",
         @count(reads[name]), # extracting stat results
         @sum(reads[name]),
         @avg(reads[name]))
    if (@count(writes[name]))
      printf("writes n=%d, sum=%d, avg=%d\n",
         @count(writes[name]), # extracting stat results
         @sum(writes[name]),
         @avg(writes[name]))
  }
}