From c41e99c8f098302a9ed2eb4fcac6ff5e7cd79cab Mon Sep 17 00:00:00 2001 From: ddomingo Date: Thu, 27 Nov 2008 08:18:03 +1000 Subject: added index --- .../en-US/ScriptConstructs.xml | 200 ++++++++++++++++++++- 1 file changed, 197 insertions(+), 3 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 1cda95a4..e0917280 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/ScriptConstructs.xml @@ -4,15 +4,84 @@
Basic SystemTap Handler Constructs - + +handlers +SystemTap handler constructs + + + +SystemTap handlers +SystemTap handler constructs + + + + + +handlers +SystemTap handler constructs +syntax and format + + + +SystemTap handlers +SystemTap handler constructs +syntax and format + + + +syntax and format +SystemTap handler constructs +handlers + SystemTap supports the use of several basic constructs in handlers. The syntax for most of these handler constructs are mostly based on C and awk syntax. This section describes several of the most useful SystemTap handler constructs, which should provide you with enough information to write simple yet useful SystemTap scripts.
Variables - + + +handlers +SystemTap handler constructs +variables + + + +SystemTap handlers +SystemTap handler constructs +variables + + + +variables +SystemTap handler constructs +handlers + + + + format and syntax + 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(). + + + +handlers +SystemTap handler constructs +global + + +SystemTap handlers +SystemTap handler constructs +global + + + +global +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: @@ -30,6 +99,10 @@ 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). @@ -50,6 +123,15 @@ probe timer.jiffies(100) { count_jiffies ++ }
Conditional Statements + +handlers +conditional statements + + + +SystemTap handlers +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. @@ -62,6 +144,25 @@ You can do this by using conditionals in handlers. SystemTa If/Else Statements + + +handlers +conditional statements +if/else + + + +SystemTap handlers +conditional statements +if/else + + + +if/else +conditional statements +handlers + + Format: if (condition) @@ -95,6 +196,25 @@ probe end While Loops + + + +handlers +conditional statements +while loops + + + +SystemTap handlers +conditional statements +while loops + + + +while loops +conditional statements +handlers + Format: while (condition) {statement} @@ -119,6 +239,25 @@ printf("goodbye world\n") For Loops + + + +handlers +conditional statements +for loops + + + +SystemTap handlers +conditional statements +for loops + + + +for loops +conditional statements +handlers + Format: for (argument1; argument2; argument3) {statement} @@ -144,6 +283,26 @@ for (argument1; argument2; Conditional Operators + + + +handlers +conditional statements +conditional operators + + + +SystemTap handlers +conditional statements +conditional operators + + + +conditional operators +conditional statements +handlers + + Aside from == ("is equal to"), you can also use the following operators in your conditional statements: @@ -174,6 +333,23 @@ for (argument1; argument2;
Command-Line Arguments + +handlers +SystemTap handler constructs +command-line arguments + + + +SystemTap handlers +SystemTap handler constructs +command-line arguments + + + +command-line arguments +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 @. @@ -186,7 +362,25 @@ probe kernel.function(@1).return { } is similar to , except that it allows you to pass the kernel function to be probed as a command-line argument (as in stap commandlineargs.stp kernel function). You can also specify the script to accept multiple command-line arguments, noting them as @1, @2, and so on, in the order they are entered by the user. - + + + +handlers +SystemTap handler constructs +variable notations + + + +SystemTap handlers +SystemTap handler constructs +variable notations + + + +variable notations +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