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 +++++++++++++++------ 1 file changed, 158 insertions(+), 65 deletions(-) (limited to 'doc/SystemTap_Beginners_Guide/en-US/Array-Operations.xml') 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 -- cgit