Flashnux

GNU/Linux man pages

Livre :
Expressions régulières,
Syntaxe et mise en oeuvre :

ISBN : 978-2-7460-9712-4
EAN : 9782746097124
(Editions ENI)

GNU/Linux

CentOS 5.3

stapex(5)


STAPEX

STAPEX

NAME
LANGUAGE BASICS
PROBING
MORE EXAMPLES
SEE ALSO

NAME

stapex − systemtap examples

LANGUAGE BASICS

These examples give a feel for basic systemtap syntax and control structures.

global odds, evens

probe begin {
# "no" and "ne" are local integers
for (i=0; i<10; i++) {
if (i % 2) odds [no++] = i
else evens [ne++] = i
}
delete odds[2]
delete evens[3]
exit ()
}

probe end {
foreach (x+ in odds) {
printf ("odds[%d] = %d0, x, odds[x])
}
foreach (x in evens−) {
printf ("evens[%d] = %d0, x, evens[x])
}
}

This prints:

odds[1] = 1
odds[3] = 5
odds[4] = 7
odds[5] = 9
evens[5] = 8
evens[4] = 6
evens[2] = 2
evens[1] = 0

Note that all variables types are inferred, and that all locals and globals are automatically initialized.

This script prints the primes between 0 and 49.

function isprime (x) {
if (x < 2) return 0
for (i=2; i<x; i++) {
if (x % i == 0) return 0
if (i * i > x) break
}
return 1
}
probe begin {
for (i=0; i<50; i++)
if (isprime (i)) printf("%d0, i)
exit()
}

This script demonstrates recursive functions.

function fibonacci(i) {
if (i < 1) error ("bad number")
if (i == 1) return 1
if (i == 2) return 2
return fibonacci (i−1) + fibonacci (i−2)
}
probe begin {
printf ("11th fibonacci number: %d0, fibonacci (11))
exit ()
}

Any larger number may exceed the MAXACTION or MAXNESTING limits, and result in an error.

PROBING

To trace entry and exit from a function, use a pair of probes:

probe kernel.function("sys_mkdir") { println ("enter") }
probe kernel.function("sys_mkdir").return { println ("exit") }

To list the probeable functions in the kernel, use the listings mode.

% stap −l 'kernel.function("*")'

To list the probeable functions and local variables in the kernel, use another listings mode.

% stap −L 'kernel.function("*")'

MORE EXAMPLES

Larger examples, demos and samples can be found in /usr/doc/systemtap*/examples, each example comes with either a .txt or .meta file explaining what the example, sample or demo does and how it is ordinarily run.

SEE ALSO

/usr/doc/systemtap*/examples stap(1) stapprobes(5) stapfuncs(5)



stapex(5)