next up previous contents
Next: Safety Up: Analysis Previous: Arrays   Contents

Aggregates

When we said above that values can only be strings or numbers, we lied a little. There is a third type: statistics aggregates, or aggregates for short. Instances of this type are used to collect statistics on numerical values, where it is important to accumulate new data quickly (without exclusive locks) and in large volume (storing only aggregated stream statistics). This type only makes sense for global variables, and may be stored individually or as elements of an array.

To add a value to a statistics aggregate, systemtap uses the special operator <<<. Think of it like C++'s << output streamer: the left hand side object accumulates the data sample given on the right hand side. This operation is efficient (taking a shared lock) because the aggregate values are kept separately on each processor, and are only aggregated across processors on request.

a <<< delta_timestamp
writes[execname()] <<< count

To read the aggregate value, special functions are available to extract a selected statistical function. The aggregate value cannot be read by simply naming it as if it were an ordinary variable. These operations take an exclusive lock on the respective globals, and should therefore be relatively rare. The simple ones are: @min, @max, @count, @avg, and @sum, and evaluate to a single number. In addition, histograms of the data stream may be extracted using the @hist_log and @hist_linear. These evaluate to a special sort of array that may at present2 only be printed.

@avg(a) the average of all the values accumulated into a
print(@hist_linear(a,0,100,10)) print an ``ascii art'' linear histogram of the same data stream,
  bounds $0 \ldots 100$, bucket width is $10$
@count(writes["zsh"]) the number of times ``zsh'' ran the probe handler
print(@hist_log(writes["zsh"])) print an ``ascii art'' logarithmic histogram of the same data stream


next up previous contents
Next: Safety Up: Analysis Previous: Arrays   Contents