]> sourceware.org Git - systemtap.git/blame - stapex.3stap.in
Fix typo in mq_timedreceive probe point.
[systemtap.git] / stapex.3stap.in
CommitLineData
ba4a90fd 1.\" -*- nroff -*-
e97c0b29 2.TH STAPEX 3stap @DATE@ "Red Hat"
ba4a90fd
FCE
3.SH NAME
4stapex \- systemtap examples
5
6.\" macros
7.de SAMPLE
8.br
9.RS
10.nf
11.nh
12..
13.de ESAMPLE
14.hy
15.fi
16.RE
17..
18
19.SH LANGUAGE BASICS
20These examples give a feel for basic systemtap syntax and
21control structures.
22
23.SAMPLE
24global odds, evens
25
26probe begin {
27 # "no" and "ne" are local integers
28 for (i=0; i<10; i++) {
29 if (i % 2) odds [no++] = i
30 else evens [ne++] = i
31 }
32 delete odds[2]
33 delete evens[3]
34 exit ()
35}
36
37probe end {
93484556 38 foreach (x+ in odds) {
5b3452c9 39 printf ("odds[%d] = %d\n", x, odds[x])
ba4a90fd 40 }
13d2ecdb 41 foreach (x in evens\-) {
5b3452c9 42 printf ("evens[%d] = %d\n", x, evens[x])
ba4a90fd
FCE
43 }
44}
45.ESAMPLE
46This prints:
47.SAMPLE
48odds[1] = 1
49odds[3] = 5
50odds[4] = 7
51odds[5] = 9
ba4a90fd 52evens[5] = 8
93484556
FCE
53evens[4] = 6
54evens[2] = 2
5b3452c9 55evens[1] = 0
ba4a90fd 56.ESAMPLE
5b3452c9
FCE
57Note that all variables types are inferred, and that all locals
58and globals are automatically initialized.
ba4a90fd
FCE
59
60.PP
61This script prints the primes between 0 and 49.
62.SAMPLE
63function isprime (x) {
64 if (x < 2) return 0
65 for (i=2; i<x; i++) {
66 if (x % i == 0) return 0
67 if (i * i > x) break
68 }
69 return 1
70}
71probe begin {
72 for (i=0; i<50; i++)
5b3452c9 73 if (isprime (i)) printf("%d\n", i)
ba4a90fd
FCE
74 exit()
75}
76.ESAMPLE
77
78.PP
79This script demonstrates recursive functions.
80.SAMPLE
81function fibonacci(i) {
82 if (i < 1) error ("bad number")
83 if (i == 1) return 1
84 if (i == 2) return 2
13d2ecdb 85 return fibonacci (i\-1) + fibonacci (i\-2)
ba4a90fd
FCE
86}
87probe begin {
5b3452c9 88 printf ("11th fibonacci number: %d\n", fibonacci (11))
ba4a90fd
FCE
89 exit ()
90}
91.ESAMPLE
92Any larger number may exceed the MAXACTION or MAXNESTING
93limits, and result in an error.
94
95
96.SH PROBING
97
98To trace entry and exit from a function, use a pair of probes:
99.SAMPLE
163a52d9
MH
100probe kernel.function("sys_mkdir") { println ("enter") }
101probe kernel.function("sys_mkdir").return { println ("exit") }
ba4a90fd
FCE
102.ESAMPLE
103
16442b90 104To list the probeable functions in the kernel, use the listings mode.
ba4a90fd 105.SAMPLE
16442b90 106% stap \-l \[aq]kernel.function("*")\[aq]
ba4a90fd
FCE
107.ESAMPLE
108
d4e35ac8
WH
109To list the probeable functions and local variables in the kernel, use another listings mode.
110.SAMPLE
111% stap \-L \[aq]kernel.function("*")\[aq]
112.ESAMPLE
113
ff7b8b4a
MW
114.SH MORE EXAMPLES
115
116Larger examples, demos and samples can be found in
117@prefix@/doc/systemtap*/examples, each example comes with either a .txt
118or .meta file explaining what the example, sample or demo does and how
119it is ordinarily run.
120
ba4a90fd 121.SH SEE ALSO
5b3452c9 122.BR @prefix@/doc/systemtap*/examples
ba4a90fd 123.IR stap (1)
e97c0b29
WC
124.IR stapprobes (3stap)
125.IR stapfuncs (3stap)
ba4a90fd 126
This page took 0.070382 seconds and 5 git commands to generate.