From b866b7adfac0649db534a98b723b13692c1da4d9 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Mon, 8 Dec 2008 22:37:17 -0500 Subject: Edits to Scripts.xml and ScriptConstructs.xml. --- .../en-US/ScriptConstructs.xml | 67 ++++++++++++++++------ 1 file changed, 51 insertions(+), 16 deletions(-) (limited to 'doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml') diff --git a/doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml b/doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml index e0917280..a139015d 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml @@ -61,7 +61,8 @@ SystemTap handler constructs handlers - Variables can be used freely throughout a handler; simply choose a name, assign it to a function, and use it in an expression. SystemTap automatically identifies whether a variable should be identified as a string or integer, based on the function it is assigned to. For instance, if you use set the variable foo to gettimeofday_s() (as in foo = gettimeofday_s()), then foo can be used as an integer argument (%d) in printf(). + Variables can be used freely throughout a handler; simply choose a +name, assign a value from a function or expression to it, and use it in an expression. SystemTap automatically identifies whether a variable should be typed as a string or integer, based on the type of the values assigned to it. For instance, if you use set the variable foo to gettimeofday_s() (as in foo = gettimeofday_s()), then foo is typed as an number and can be printed in a printf() with the integer format specifier (%d). @@ -82,7 +83,7 @@ SystemTap handler constructs handlers -Note, however, that by default variables are only local to the probe they are used in. This means that variables are initialized, used and disposed at each probe handler invocation. To share a variable between probes, declare the variable name first using global outside of any probe. Consider the following example: +Note, however, that by default variables are only local to the probe they are used in. This means that variables are initialized, used and disposed at each probe handler invocation. To share a variable between probes, declare the variable name using global outside of the probes. Consider the following example: timer-jiffies.stp @@ -104,7 +105,7 @@ probe timer.ms(12345) CONFIG_HZ, computing for - attempts to compute the CONFIG_HZ setting of the kernel using timers that count jiffies and milliseconds, then computing accordingly. The global statement allows the script to use the variables count_jiffies and count_ms (set in their own respective probes) to be shared with probe timer.ms(12345). + computes the CONFIG_HZ setting of the kernel using timers that count jiffies and milliseconds, then computing accordingly. The global statement allows the script to use the variables count_jiffies and count_ms (set in their own respective probes) to be shared with probe timer.ms(12345). Note @@ -165,25 +166,38 @@ You can do this by using conditionals in handlers. SystemTa Format: -if (condition) - {statement} else {statement} +if (condition) + statement1 +else + statement2 + +The statement1 is executed if the +condition expression is +non-zero. The statement2 is +executed if the condition +expression is zero. The else is optional. Both +statement1 and +statement2 can be statement +blocks. + + ifelse.stp global countread, countnonread probe kernel.function("vfs_read"),kernel.function("vfs_write") { - if (probefunc()=="vfs_read") - countread ++ - else - countnonread ++ + if (probefunc()=="vfs_read") + countread ++ + else + countnonread ++ } probe timer.s(5) { exit() } probe end { - printf("VFS reads total %d\n VFS writes total %d\n", countread, countnonread) + printf("VFS reads total %d\n VFS writes total %d\n", countread, countnonread) } @@ -217,8 +231,17 @@ probe end Format: -while (condition) {statement} +while (condition) + statement + +So long as condition is non-zero +the block of statements in +statement are executed. The +statement is often a statement +block and it must change a value so +condition will eventually be zero. + @@ -350,7 +384,9 @@ for (argument1; argument2; SystemTap handler constructs handlers - 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 @. + You can also allow a SystemTap script to accept simple command-line arguments using a $ or @ immediately +followed by the number of the argument on the command line. Use $ if you are expecting the user to enter an integer as a command-line argument, and @ if you are expecting a string. + @@ -381,7 +417,6 @@ probe kernel.function(@1).return { } SystemTap handler constructs handlers -Both variable notations $ and @ also represent a specific variable type. Use $ if you are expecting the user to enter an integer as a command-line argument, and @ if you are expecting a string. -- cgit