diff options
Diffstat (limited to 'man/stapex.3stap.html')
| -rw-r--r-- | man/stapex.3stap.html | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/man/stapex.3stap.html b/man/stapex.3stap.html new file mode 100644 index 00000000..492b878b --- /dev/null +++ b/man/stapex.3stap.html | |||
| @@ -0,0 +1,246 @@ | |||
| 1 | |||
| 2 | <HTML><HEAD><TITLE>Manpage of STAPEX</TITLE> | ||
| 3 | </HEAD><BODY> | ||
| 4 | <H1>STAPEX</H1> | ||
| 5 | Section: Misc. Reference Manual Pages (3stap)<BR><A HREF="#index">Index</A> | ||
| 6 | <A HREF="index.html">Return to Main Contents</A><HR> | ||
| 7 | |||
| 8 | <A NAME="lbAB"> </A> | ||
| 9 | <H2>NAME</H2> | ||
| 10 | |||
| 11 | stapex - systemtap examples | ||
| 12 | <P> | ||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | <P> | ||
| 17 | <A NAME="lbAC"> </A> | ||
| 18 | <H2>LANGUAGE BASICS</H2> | ||
| 19 | |||
| 20 | These examples give a feel for basic systemtap syntax and | ||
| 21 | control structures. | ||
| 22 | <P> | ||
| 23 | |||
| 24 | <P> | ||
| 25 | |||
| 26 | <BR> | ||
| 27 | |||
| 28 | <DL COMPACT><DT><DD> | ||
| 29 | <PRE> | ||
| 30 | global odds, evens | ||
| 31 | |||
| 32 | probe begin { | ||
| 33 | # "no" and "ne" are local integers | ||
| 34 | for (i=0; i<10; i++) { | ||
| 35 | if (i % 2) odds [no++] = i | ||
| 36 | else evens [ne++] = i | ||
| 37 | } | ||
| 38 | delete odds[2] | ||
| 39 | delete evens[3] | ||
| 40 | exit () | ||
| 41 | } | ||
| 42 | |||
| 43 | probe end { | ||
| 44 | foreach (x+ in odds) { | ||
| 45 | printf ("odds[%d] = %d, x, odds[x]) | ||
| 46 | } | ||
| 47 | foreach (x in evens-) { | ||
| 48 | printf ("evens[%d] = %d, x, evens[x]) | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | </PRE> | ||
| 53 | |||
| 54 | </DL> | ||
| 55 | |||
| 56 | |||
| 57 | <P> | ||
| 58 | |||
| 59 | This prints: | ||
| 60 | |||
| 61 | <P> | ||
| 62 | |||
| 63 | <BR> | ||
| 64 | |||
| 65 | <DL COMPACT><DT><DD> | ||
| 66 | <PRE> | ||
| 67 | odds[1] = 1 | ||
| 68 | odds[3] = 5 | ||
| 69 | odds[4] = 7 | ||
| 70 | odds[5] = 9 | ||
| 71 | evens[5] = 8 | ||
| 72 | evens[4] = 6 | ||
| 73 | evens[2] = 2 | ||
| 74 | evens[1] = 0 | ||
| 75 | |||
| 76 | </PRE> | ||
| 77 | |||
| 78 | </DL> | ||
| 79 | |||
| 80 | |||
| 81 | <P> | ||
| 82 | |||
| 83 | Note that all variables types are inferred, and that all locals | ||
| 84 | and globals are automatically initialized. | ||
| 85 | <P> | ||
| 86 | <P> | ||
| 87 | |||
| 88 | This script prints the primes between 0 and 49. | ||
| 89 | |||
| 90 | <P> | ||
| 91 | |||
| 92 | <BR> | ||
| 93 | |||
| 94 | <DL COMPACT><DT><DD> | ||
| 95 | <PRE> | ||
| 96 | function isprime (x) { | ||
| 97 | if (x < 2) return 0 | ||
| 98 | for (i=2; i<x; i++) { | ||
| 99 | if (x % i == 0) return 0 | ||
| 100 | if (i * i > x) break | ||
| 101 | } | ||
| 102 | return 1 | ||
| 103 | } | ||
| 104 | probe begin { | ||
| 105 | for (i=0; i<50; i++) | ||
| 106 | if (isprime (i)) printf("%d, i) | ||
| 107 | exit() | ||
| 108 | } | ||
| 109 | |||
| 110 | </PRE> | ||
| 111 | |||
| 112 | </DL> | ||
| 113 | |||
| 114 | |||
| 115 | <P> | ||
| 116 | |||
| 117 | <P> | ||
| 118 | <P> | ||
| 119 | |||
| 120 | This script demonstrates recursive functions. | ||
| 121 | |||
| 122 | <P> | ||
| 123 | |||
| 124 | <BR> | ||
| 125 | |||
| 126 | <DL COMPACT><DT><DD> | ||
| 127 | <PRE> | ||
| 128 | function fibonacci(i) { | ||
| 129 | if (i < 1) error ("bad number") | ||
| 130 | if (i == 1) return 1 | ||
| 131 | if (i == 2) return 2 | ||
| 132 | return fibonacci (i-1) + fibonacci (i-2) | ||
| 133 | } | ||
| 134 | probe begin { | ||
| 135 | printf ("11th fibonacci number: %d, fibonacci (11)) | ||
| 136 | exit () | ||
| 137 | } | ||
| 138 | |||
| 139 | </PRE> | ||
| 140 | |||
| 141 | </DL> | ||
| 142 | |||
| 143 | |||
| 144 | <P> | ||
| 145 | |||
| 146 | Any larger number may exceed the MAXACTION or MAXNESTING | ||
| 147 | limits, and result in an error. | ||
| 148 | <P> | ||
| 149 | <P> | ||
| 150 | <A NAME="lbAD"> </A> | ||
| 151 | <H2>PROBING</H2> | ||
| 152 | |||
| 153 | <P> | ||
| 154 | To trace entry and exit from a function, use a pair of probes: | ||
| 155 | |||
| 156 | <P> | ||
| 157 | |||
| 158 | <BR> | ||
| 159 | |||
| 160 | <DL COMPACT><DT><DD> | ||
| 161 | <PRE> | ||
| 162 | probe kernel.function("sys_mkdir") { println ("enter") } | ||
| 163 | probe kernel.function("sys_mkdir").return { println ("exit") } | ||
| 164 | |||
| 165 | </PRE> | ||
| 166 | |||
| 167 | </DL> | ||
| 168 | |||
| 169 | |||
| 170 | <P> | ||
| 171 | |||
| 172 | <P> | ||
| 173 | To list the probeable functions in the kernel, use the listings mode. | ||
| 174 | |||
| 175 | <P> | ||
| 176 | |||
| 177 | <BR> | ||
| 178 | |||
| 179 | <DL COMPACT><DT><DD> | ||
| 180 | <PRE> | ||
| 181 | % stap -l 'kernel.function("*")' | ||
| 182 | |||
| 183 | </PRE> | ||
| 184 | |||
| 185 | </DL> | ||
| 186 | |||
| 187 | |||
| 188 | <P> | ||
| 189 | |||
| 190 | <P> | ||
| 191 | To list the probeable functions and local variables in the kernel, use another listings mode. | ||
| 192 | |||
| 193 | <P> | ||
| 194 | |||
| 195 | <BR> | ||
| 196 | |||
| 197 | <DL COMPACT><DT><DD> | ||
| 198 | <PRE> | ||
| 199 | % stap -L 'kernel.function("*")' | ||
| 200 | |||
| 201 | </PRE> | ||
| 202 | |||
| 203 | </DL> | ||
| 204 | |||
| 205 | |||
| 206 | <P> | ||
| 207 | |||
| 208 | <P> | ||
| 209 | <A NAME="lbAE"> </A> | ||
| 210 | <H2>MORE EXAMPLES</H2> | ||
| 211 | |||
| 212 | <P> | ||
| 213 | The directory to find more examples can be found in the stappaths (7) manual page, | ||
| 214 | and online at | ||
| 215 | |||
| 216 | <B><A HREF="http://sourceware.org/systemtap/examples/">http://sourceware.org/systemtap/examples/</A></B> | ||
| 217 | |||
| 218 | |||
| 219 | <P> | ||
| 220 | <A NAME="lbAF"> </A> | ||
| 221 | <H2>SEE ALSO</H2> | ||
| 222 | |||
| 223 | |||
| 224 | <PRE> | ||
| 225 | <I><A HREF="stap.1.html">stap</A></I>(1) | ||
| 226 | <I><A HREF="stapprobes.3stap.html">stapprobes</A></I>(3stap) | ||
| 227 | <I><A HREF="stappaths.7.html">stappaths</A></I>(7) | ||
| 228 | |||
| 229 | |||
| 230 | </PRE> | ||
| 231 | <HR> | ||
| 232 | <A NAME="index"> </A><H2>Index</H2> | ||
| 233 | <DL> | ||
| 234 | <DT><A HREF="#lbAB">NAME</A><DD> | ||
| 235 | <DT><A HREF="#lbAC">LANGUAGE BASICS</A><DD> | ||
| 236 | <DT><A HREF="#lbAD">PROBING</A><DD> | ||
| 237 | <DT><A HREF="#lbAE">MORE EXAMPLES</A><DD> | ||
| 238 | <DT><A HREF="#lbAF">SEE ALSO</A><DD> | ||
| 239 | </DL> | ||
| 240 | <HR> | ||
| 241 | This document was created by | ||
| 242 | <A HREFhttp://www.kapiti.co.nz/michael/vhman2html.html">man2html</A>, | ||
| 243 | using the manual pages.<BR> | ||
| 244 | Time: 17:59:59 GMT, May 16, 2014 | ||
| 245 | </BODY> | ||
| 246 | </HTML> | ||
