Measurement storage and the aggregate functions implemented in metric.sv.
The metric API
Available operations
| Method | Behavior |
|---|---|
| measure(real value = 1) | Append one real-valued observation. |
| remove_measurement() | Remove the most recent observation when one exists. |
| total_measurements() | Return queue size. |
| sum() | Accumulate observations; the current declaration returns int. |
| mean() | Return zero for an empty metric, otherwise sum divided by count. |
| min() | Return zero when empty, otherwise scan for the minimum real value. |
| max() | Return zero when empty; the current declaration returns int. |
Type caveat
Measurements, minimum, and maximum are real, but sum() and max() currently return int. Fractional values can therefore be truncated at those boundaries. A production implementation should make the return types consistent with the stored measurement type.
Computation model
Count is constant time because it reads queue size. sum, mean, min, and max scan the stored observations each time, so they are linear in the number of samples and retain every value in memory.