# mco_stat_histogram_get
RT

> Retrieve a pointer to a specific histogram by its internal index.

### Prototype

        MCO_RET mco_stat_histogram_get(
            /*IN*/  mco_stat_hdl hist_idx,
            /*OUT*/ mco_stat_histogram_h *ret_hist
        );

### Arguments

`hist_idx`
Internal histogram index (obtained, for example, via `mco_stat_get_histogram_source()`).
`ret_hist`
Pointer to a variable that will receive the address of the requested `mco_stat_histogram_t` structure.

### Description

> This function provides direct access to a histogram stored in the database's statistics memory region. It is typically used after obtaining a valid histogram index from `mco_stat_get_histogram_source()`.

> The returned pointer points to internal runtime data and remains valid as long as the database is open. The histogram contains distribution data (e.g., transaction durations) collected automatically when a counter with histogram support is updated.

> Applications should not modify the histogram data directly. The structure is intended for read-only inspection (e.g., by monitoring tools or diagnostic utilities).

> Note: The statistics subsystem must be initialized (i.e., a database with statistics support must be open) before calling this function.

### Return Codes

`MCO_S_OK`
Histogram pointer successfully retrieved.
`MCO_E_INVALID_HANDLE`
The specified histogram index is out of range or the statistics subsystem is not initialized.

### Example

        mco_stat_hdl hist_idx;
        mco_stat_histogram_h hist;
        MCO_RET rc;

        // Assume we have a counter with histogram enabled
        rc = mco_stat_get_histogram_source(MCO_STATRT_MAX_TRANS_TIME, &hist_idx);
        if (rc == MCO_S_OK && hist_idx != MCO_STAT_INVALID_HANDLE) {
            rc = mco_stat_histogram_get(hist_idx, &hist);
            if (rc == MCO_S_OK) {
                printf("Histogram range: %u\n", hist->range);
                printf("Total samples: %u\n",
                    hist->bars[0] + hist->bars[1] + ... ); // sum all bars
            }
        }

### Files

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