Debian Codegraph @

testsuite/systemtap.examples/general/graphs.stp

raw
1 #! /usr/bin/env stap
2
3 # ------------------------------------------------------------------------
4 # data collection
5
6 # disk I/O stats
7 probe begin { qnames["ioblock"] ++; qsq_start ("ioblock") }
8 probe ioblock.request { qs_wait ("ioblock") qs_run("ioblock") }
9 probe ioblock.end { qs_done ("ioblock") }
10
11 # CPU utilization
12 probe begin { qnames["cpu"] ++; qsq_start ("cpu") }
13 probe scheduler.cpu_on { if (!idle) {qs_wait ("cpu") qs_run ("cpu") }}
14 probe scheduler.cpu_off { if (!idle) qs_done ("cpu") }
15
16
17 # ------------------------------------------------------------------------
18 # utilization history tracking
19
20 global N
21 probe begin { N = 50 }
22
23 global qnames, util, histidx
24
25 function qsq_util_reset(q) {
26 u=qsq_utilization (q, 100)
27 qsq_start (q)
28 return u
29 }
30
31 probe timer.ms(100) { # collect utilization percentages frequently
32 histidx = (histidx + 1) % N # into circular buffer
33 foreach (q in qnames)
34 util[histidx,q] = qsq_util_reset(q)
35 }
36
37
38 # ------------------------------------------------------------------------
39 # general gnuplot graphical report generation
40
41 probe timer.ms(1000) {
42 # emit gnuplot command to display recent history
43
44 printf ("set yrange [0:100]\n")
45 printf ("plot ")
46 foreach (q in qnames+)
47 {
48 if (++nq >= 2) printf (", ")
49 printf ("'-' title \"%s\" with lines", q)
50 }
51 printf ("\n")
52
53 foreach (q in qnames+) {
54 for (i = (histidx + 1) % N; i != histidx; i = (i + 1) % N)
55 printf("%d\n", util[i,q])
56 printf ("e\n")
57 }
58
59 printf ("pause 1\n")
60 }