4 stapex \- systemtap examples
20 These examples give a feel for basic systemtap syntax and
27 # "no" and "ne" are local integers
28 for (i=0; i<10; i++) {
29 if (i % 2) odds [no++] = i
38 foreach (x+ in odds) {
39 printf ("odds[%d] = %d\n", x, odds[x])
41 foreach (x in evens\-) {
42 printf ("evens[%d] = %d\n", x, evens[x])
57 Note that all variables types are inferred, and that all locals
58 and globals are automatically initialized.
61 This script prints the primes between 0 and 49.
63 function isprime (x) {
66 if (x % i == 0) return 0
73 if (isprime (i)) printf("%d\n", i)
79 This script demonstrates recursive functions.
81 function fibonacci(i) {
82 if (i < 1) error ("bad number")
85 return fibonacci (i\-1) + fibonacci (i\-2)
88 printf ("11th fibonacci number: %d\n", fibonacci (11))
92 Any larger number may exceed the MAXACTION or MAXNESTING
93 limits, and result in an error.
98 To trace entry and exit from a function, use a pair of probes:
100 probe kernel.function("sys_mkdir") { println ("enter") }
101 probe kernel.function("sys_mkdir").return { println ("exit") }
104 To list the probeable functions in the kernel, use the listings mode.
106 % stap \-l \[aq]kernel.function("*")\[aq]
109 To list the probeable functions and local variables in the kernel, use another listings mode.
111 % stap \-L \[aq]kernel.function("*")\[aq]
116 The directory to find more examples can be found in the stappaths (7) manual page.
120 .IR stapprobes (3stap)
121 .IR stapfuncs (3stap)