From 3be7261ad2c9496868e131147770fb3e9e409679 Mon Sep 17 00:00:00 2001 From: ddomingo Date: Mon, 3 Nov 2008 12:05:28 +1000 Subject: added aggregate stats --- .../en-US/Array-Operations.xml | 223 +++++++++++++++------ doc/SystemTap_Beginners_Guide/en-US/Arrays.xml | 2 +- doc/SystemTap_Beginners_Guide/en-US/Errors.xml | 18 +- .../en-US/Useful_Scripts-disktop.xml | 2 +- .../en-US/Useful_Scripts-functioncalls.xml | 2 +- .../en-US/Useful_Scripts-futexes.xml | 2 +- .../en-US/Useful_Scripts-iotop.xml | 2 +- .../en-US/Useful_Scripts-nettop.xml | 18 +- .../en-US/Useful_Scripts-sockettrace.xml | 2 +- .../en-US/Useful_Scripts-threadtimes.xml | 2 +- .../en-US/Useful_Scripts-traceio.xml | 2 +- 11 files changed, 192 insertions(+), 83 deletions(-) (limited to 'doc/SystemTap_Beginners_Guide/en-US') diff --git a/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml b/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml index ebac139f..32fdf021 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml @@ -40,9 +40,9 @@ delta = gettimeofday_s() - foo[execname()] -In , the first statement sets a timestamp associated with the returned value of the handler function execname() as a reference point. The second statement computes a value for the variable delta by subtracting the associated value the reference point from the current gettimeofday_s(). +In , the first statement sets a timestamp associated with the returned value of the handler function execname() as a reference point. The second statement computes a value for the variable delta by subtracting the associated value the reference point from the current gettimeofday_s(). Note that the first statement writes the value of gettimeofday_s() into the appropriate key of array foo, while in the second statement the value of foo[execname()] is read from the array in order to compute for delta. -In this situation, if the index_expression cannot find the unique key, it returns a null value (zero) by default. +In this situation, if the index_expression cannot find the unique key, it returns a value of 0 (for numerical operations, such as ) or a null/empty string value (for string operations) by default.
Incrementing Associated Values @@ -117,18 +117,19 @@ probe timer.s(3) vfsreads-per-2secs.stp -global reads -probe kernel.function("vfs_read") -{ - reads[execname()] ++ -} -probe timer.s(2) -{ - printf("=======\n") - foreach (count in reads+) - printf("%s : %d \n", count, reads[count]) - delete reads -} +global reads +probe kernel.function("vfs_read") +{ + reads[execname()] ++ + +} +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + delete reads +} @@ -139,28 +140,28 @@ probe timer.s(2) You can have multiple array operations within the same probe. Using the examples from and , you can track the number of VFS reads each process makes per 2-second period and tally the cumulative VFS reads of those same processes. Consider the following example: -global reads, totalreads - -probe kernel.function("vfs_read") -{ - reads[execname()] ++ - totalreads[execname()] ++ -} - -probe timer.s(2) -{ - printf("=======\n") - foreach (count in reads+) - printf("%s : %d \n", count, reads[count]) - delete reads - -} -probe end -{ - printf("TOTALS\n") - foreach (total in totalreads+) - printf("%s : %d \n", total, totalreads[total]) -} +global reads, totalreads + +probe kernel.function("vfs_read") +{ + reads[execname()] ++ + totalreads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + delete reads + +} +probe end +{ + printf("TOTALS\n") + foreach (total in totalreads+) + printf("%s : %d \n", total, totalreads[total]) +} In this example, the arrays reads and totalreads track the same information, and are printed out in a similar fashion. The only difference here is that reads is cleared every 2-second period, whereas totalreads keeps growing. @@ -174,18 +175,19 @@ probe end vfsreads-stop-on-stapio.stp -global reads -probe kernel.function("vfs_read") -{ - reads[execname()] ++ -} -probe timer.s(2) -{ - printf("=======\n") - foreach (count in reads+) - printf("%s : %d \n", count, reads[count]) - if(reads["stapio"] >= 20) - {exit()} +global reads +probe kernel.function("vfs_read") +{ + reads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + if(reads["stapio"] >= 20) + {exit()} } @@ -206,27 +208,118 @@ if([index_expression] in array_name vfsreads-stop-on-stapio2.stp -global reads - -probe kernel.function("vfs_read") -{ - reads[execname()] ++ -} - -probe timer.s(2) -{ - printf("=======\n") - foreach (count in reads+) - printf("%s : %d \n", count, reads[count]) - if(["stapio"] in reads) - {printf("stapio read detected, exiting\n") - exit() - } -} +global reads + +probe kernel.function("vfs_read") +{ + reads[execname()] ++ +} + +probe timer.s(2) +{ + printf("=======\n") + foreach (count in reads+) + printf("%s : %d \n", count, reads[count]) + if(["stapio"] in reads) + {printf("stapio read detected, exiting\n") + exit() + } +} The if(["stapio"] in reads) statement instructs the script to print stapio read detected, exiting once the unique key stapio is added to the array reads.
+
+ Computing for Statistical Aggregates + +Statistical aggregates are used to collect statistics on numerical values where it is important to accumulate new data quickly and in large volume (i.e. storing only aggregated stream statistics). Statistical aggregates can be used in global variables or as elements in an array. + +To add value to a statistical aggregate, use the operator <<< value. + +need more examples of supported rvalues, e.g. length, count, and what each one does. + + + stat-aggregates.stp + +global writes +probe vfs_write +{ +writes[execname()] <<< count +} + + + +In , the operator <<< count stores the amount returned by count to to the associated value of the corresponding execname() in the writes array. Remember, these values are stored; they are not added to the associated values of each unique key, nor are they used to replace the current associated values. In a manner of speaking, think of it as having each unique key (execname()) having multiple associated values, accumulating with each probe handler run. + + + Note + In the context of , count returns the amount of data written by the returned execname() to the virtual file system. + + +To extract data collected by statistical aggregates, use the syntax format @extractor(variable/array index expression). extractor can be any of the following integer extractors: + + + + + count + + + Returns the number of all values stored into the variable/array index expression. Given the sample probe in , the expression @count(writes[execname()]) will return how many values are stored in each unique key in array writes. + + + + + + sum + + + Returns the sum of all values stored into the variable/array index expression. Again, given sample probe in , the expression @sum(writes[execname()]) will return the total of all values stored in each unique key in array writes. + + + + + + min + + + Returns the smallest among all the values stored in the variable/array index expression. + + + + + + max + + + Returns the largest among all the values stored in the variable/array index expression. + + + + + + avg + + + Returns the average of all values stored in the variable/array index expression. + + + + + + + + + +
+ \ No newline at end of file diff --git a/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml b/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml index 6fc99f1d..cf8b2fea 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Arrays.xml @@ -27,7 +27,7 @@ foo["harry"] = 25 Important - Arrays are normally used in multiple probes throughout a script: in most cases, one probe builds the arrays while another probe processes the information collected by the array (e.g. print its elements). Since the treatment of arrays is similar to that of variables, arrays must also be declared globally with the statement global when they are used by multiple probes. + All associate arrays must be declared as global, regardless of whether the associate array is used in one or multiple probes. diff --git a/doc/SystemTap_Beginners_Guide/en-US/Errors.xml b/doc/SystemTap_Beginners_Guide/en-US/Errors.xml index 83022a31..55081185 100644 --- a/doc/SystemTap_Beginners_Guide/en-US/Errors.xml +++ b/doc/SystemTap_Beginners_Guide/en-US/Errors.xml @@ -12,7 +12,7 @@
Parse and Type Errors -These types of errors occur while SystemTap attempts to parse and translate the script into C, prior to being converted into a kernel module. +These types of errors occur while SystemTap attempts to parse and translate the script into C, prior to being converted into a kernel module. Specifically, type errors result from operations that assign invalid values to variables or arrays. parse error: expected <replaceable>foo</replaceable>, saw <replaceable>bar</replaceable> @@ -59,9 +59,9 @@ probe syscall.open
- Symbol-Related Errors + Symbol Errors -TBD +Symbol errors result from operations in the script that process variables, arrays, or function calls incorrectly. Unlike "type" errors — which assign invalid values to a variable or array — symbol errors prevent the script from assigning any value altogether. while searching for arity <replaceable>N</replaceable> function, semantic error: unresolved function call @@ -82,14 +82,14 @@ probe syscall.open
Probe Errors -TBD +Probe errors result from the use of invalid events (e.g. events that could not be found in the tapset library), or the use of handlers that are invalid in the context of the probe. semantic error: probe point mismatch at position <replaceable>N</replaceable>, while resolving probe point <replaceable>foo</replaceable> SystemTap did not understand what the event / handler function foo refers to. This usually means that SystemTap could not find a match for foo in the tapset library. -how to explain N in previous? "The divergence from the “tree” of probe point namespace is at position N (starting with zero at left)." +how to explain N in previous? "The divergence from the “tree” of probe point namespace is at position N (starting with zero at left)." (from tutorial) semantic error: no match for probe point, while resolving probe point <replaceable>foo</replaceable> @@ -98,17 +98,17 @@ probe syscall.open semantic error: unresolved target-symbol expression - TBD + A handler in the script references a target variable, but the value of the variable could not be resolved. This error could also mean that a handler is referencing a target variable that is not valid at all in the context when it was referenced. semantic error: libdwfl failure - TBD + There was a problem processing the debugging information. In most cases, this error results from the installation of a kernel-debuginfo RPM whose version does not match the probed kernel perfectly. Sometimes, the installed kernel-debuginfo RPM itself may have some consistency / correctness problems. - semantic error: cannot find foo debuginfo - TBD + semantic error: cannot find <replaceable>foo</replaceable> debuginfo + SystemTap could not find a suitable kernel-debuginfo at all.