Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/optim_stats.stp

raw
1 #! /usr/bin/env stap
2
3 # this many complete test iterations
4 @define ITERCNT %( 10 %)
5 # this many <<< operations per batch, before checking time
6 @define BATCH %( 65536 %)
7 # this many microseconds total to run batches for
8 @define BATCHTIME %( 50000 %)
9
10 @define time
11 %(
12 %( runtime == "dyninst" %?
13 gettimeofday_us()
14 %:
15 cpu_clock_us(cpu())
16 %)
17 %)
18
19 @define feed(agg, nagg)
20 %(
21 t1 = @time
22 cnt = 0
23 while (1)
24 {
25 cnt++
26 if (cnt % @BATCH == 0) # ensure we don't call time functions so frequently that they outweigh the payload
27 if (@time > (t1 + @BATCHTIME)) break
28 @agg <<< cnt # This is the operation whose runtime we actually want to measure!
29 }
30 @nagg = @nagg + cnt
31 %)
32
33 global a, na = 0
34 global b, nb = 0
35 global c, nc = 0
36 global d, nd = 0
37
38 probe begin
39 {
40 for (i=0; i<@ITERCNT; i++)
41 {
42 @feed(a, na)
43 @feed(b, nb)
44 @feed(c[1], nc)
45 @feed(d[1], nd)
46 }
47 exit()
48 }
49
50 probe end
51 {
52 println("REM na=", na)
53 println("REM @count(a)=", @count(a))
54 println("REM nb=", nb)
55 println("REM @variance(b)=", @variance(b))
56 println("REM nc=", nc)
57 println("REM @count(c[1])=", @count(c[1]))
58 println("REM nd=", nd)
59 println("REM @variance(d[1])=", @variance(d[1]))
60 if ((na > nb) && (nc > nd))
61 println("TEST_PASS")
62 else
63 println("TEST_FAIL")
64 }