From e9a2c05304d28c9f8d249eca323cbe507dcbdd32 Mon Sep 17 00:00:00 2001 From: ddomingo Date: Tue, 21 Oct 2008 16:25:00 +1000 Subject: minor changes throughout, esp in Scripts.xml --- doc/SystemTap_Beginners_Guide/en-US/Scripts.xml | 43 ++++++++++++++++++++----- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'doc/SystemTap_Beginners_Guide/en-US/Scripts.xml') diff --git a/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml b/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml index ced4d698..2c69057b 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Scripts.xml @@ -512,18 +512,30 @@ probe timer.ms(12345) Note - In some cases, such as in , a variable may be declared without any specific value as yet. You need to declare such values as integers using the notation ++. + The ++ notation in (i.e. count_jiffies ++ and count_ms ++) is used to increment the value of a variable by 1. In the following probe, count_jiffies is incremented by 1 every 100 jiffies: + +probe timer.jiffies(100) { count_jiffies ++ } + + In this instance, SystemTap understands that count_jiffies is an integer. Because no initial value was assigned to count_jiffies, its initial value is zero by default. + + - + +
Conditional Statements In some cases, the output of a SystemTap script may be too big. To address this, you need to further refine the script's logic in order to delimit the output into something more relevant or useful to your probe. - + You can do this by using conditionals in handlers. SystemTap accepts the following types of conditional statements: @@ -535,8 +547,23 @@ You can do this by using conditionals in handlers. SystemTa Format: if (condition) - {handler} [else {handler}] + {handler} else {handler} + + + + ifelse.stp + +global foo +probe begin { foo = 1 } +probe timer.s(1) { +foo++ +if (foo<6) {printf("hello world\n")} +else {printf("goodbye world\n")} +} + + + is a script that prints hello world if less than 6 seconds has passed. If more than 6 seconds have passed, it prints goodbye world instead. @@ -575,11 +602,11 @@ for (argument1; argument2; These constructs are better illustrated in the different examples available in . will get back to these ones later - - +
+
Command-Line Arguments You can also allow a SystemTap script to accept simple command-line arguments and declare them in the script without using target(). One way to do this is to use the variable notation $ or @. - + commandlineargs.stp @@ -601,4 +628,4 @@ probe kernel.function(@1).return { }
--> - + -- cgit