⁠3.5.7. 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 (that is, 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.

Example 3.21. stat-aggregates.stp

{
}
In Example 3.21, “stat-aggregates.stp”, the operator <<< \$count stores the amount returned by \$count to the associated value of the corresponding execname() in the reads 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 Example 3.21, “stat-aggregates.stp”, count returns the amount of data read 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 Example 3.21, “stat-aggregates.stp”, the expression @count(reads[execname()]) will return how many values are stored in each unique key in array reads.
sum
Returns the sum of all values stored into the variable/array index expression. Again, given sample probe in Example 3.21, “stat-aggregates.stp”, the expression @sum(reads[execname()]) will return the total of all values stored in each unique key in array reads.
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.
When using statistical aggregates, you can also build array constructs that use multiple index expressions (to a maximum of 5). This is helpful in capturing additional contextual information during a probe. For example:

Example 3.22. Multiple Array Indexes