mco_stat_get_conn_stats

Retrieve and optionally reset statistics for a specific database connection or aggregated across all connections of a database.

Prototype

    MCO_RET mco_stat_get_conn_stats(
        /*IN*/  const char *db_name,
        /*IN*/  int conn_no,
        /*OUT*/ mco_conn_statistics_t out_stats,
        /*OUT*/ mco_stat_histogram_t *hist,
        /*IN*/  mco_bool reset
    );

Arguments

db_name
Name of the target database.
conn_no
Connection identifier:
  • A non-negative integer — retrieves stats for a specific connection,
  • -1 — aggregates stats across all active connections in the database.
out_stats
Pointer to an array of mco_stat_counter_value with size MCO_STATRT_TOTAL_COUNTERS. Receives the aggregated counter values.
hist
Optional pointer to a mco_stat_histogram_t structure to receive the combined histogram (e.g., for transaction commit times). May be NULL if histograms are not needed.
reset
Flag indicating whether to clear the counters and histogram after reading:
  • MCO_NO — read only,
  • MCO_YES — read and reset.

Description

This function retrieves runtime statistics for one or all connections of a specified database. It is useful for per-connection diagnostics, performance monitoring, or debugging specific sessions.

When conn_no = -1, the function iterates over all active connections in the database, sums their counters, and merges their histograms (if requested). When a specific conn_no is provided, it returns data for that connection only.

If reset = MCO_YES, the function clears both the counters and the histogram(s) after aggregation, enabling delta-based monitoring.

The histogram (if requested) typically represents distribution of transaction durations or other time-based metrics, depending on which counters have histogram collection enabled via mco_statrt_register_counter(..., MCO_YES).

Note: The database must be open, and the specified connection (if not -1) must be active.

Return Codes

MCO_S_OK
Statistics successfully retrieved (and optionally reset).
MCO_S_NOTFOUND
The specified database or connection does not exist.
MCO_S_CURSOR_END
No active connections found (when conn_no = -1 and all connections are free).
Other error codes
May include registry access errors or internal system failures.

Example

    mco_conn_statistics_t stats;
    mco_stat_histogram_t hist;
    MCO_RET rc;

    /* Get stats for all connections in "mydb", with histogram, and reset */
    rc = mco_stat_get_conn_stats("mydb", -1, stats, &hist, MCO_YES);
    if (rc == MCO_S_OK) {
        printf("Total commits: %u\n", stats[MCO_STATRT_COMMIT_COUNT]);
        printf("Max commit time: %u\n", stats[MCO_STATRT_MAX_TRANS_TIME]);
        printf("Histogram range: %u\n", hist.range);
    }

Files

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