Add a new value to a statistics histogram.
void mco_stat_histogram_append(
/*IN*/ mco_stat_histogram_h hist,
/*IN*/ timer_unit value
);
hist
mco_stat_histogram_t structure.value
This function inserts a new sample value into the specified histogram. The histogram automatically determines the appropriate bin (bucket) based on the current range and number of bars (
MCO_STAT_HISTOGRAM_NELEMENT).If the value exceeds the current histogram range, the behavior depends on the build configuration:
- If
MCO_STAT_HISTOGRAM_AUTOSCALEis enabled (default), the histogram range is doubled and existing data is merged into fewer bins to accommodate larger values.- Otherwise, the value is placed in the last bin (clamped to the maximum range).
This function is typically called internally by the statistics subsystem when a counter with histogram collection enabled is updated via
mco_statrt_update(). It may also be used directly in custom instrumentation code.The histogram must be initialized with
mco_stat_histogram_init()before use.
mco_stat_histogram_t my_hist;
timer_unit duration = 150; // e.g., transaction time in µs
mco_stat_histogram_init(&my_hist);
mco_stat_histogram_append(&my_hist, duration);
printf("Histogram range: %u\n", my_hist.range);
printf("First bin count: %u\n", my_hist.bars[0]);