Retrieve and optionally reset statistics for a specific database connection or aggregated across all connections of a database.
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
);
db_name
conn_no
-1 — aggregates stats across all active connections in the database.out_stats
mco_stat_counter_value with size MCO_STATRT_TOTAL_COUNTERS.
Receives the aggregated counter values.hist
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
MCO_NO — read only,MCO_YES — read and reset.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 specificconn_nois 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.
MCO_S_OK
MCO_S_NOTFOUND
MCO_S_CURSOR_END
conn_no = -1 and all connections are free).
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);
}