# mco_stat_histogram_append
RT

> Add a new value to a statistics histogram.

### Prototype

        void mco_stat_histogram_append(
            /*IN*/ mco_stat_histogram_h hist,
            /*IN*/ timer_unit value
        );

### Arguments

`hist`
Pointer to an initialized `mco_stat_histogram_t` structure.
`value`
Numeric value (e.g., time in microseconds) to be added to the histogram.

### Description

> 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_AUTOSCALE` is 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.

### Return Value

None
This function does not return a value.

### Example

        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]);

### Files

Header file:
mcostatrt.h
Source file:
mcostat.c
Library:
libmcolib.a