Retrieve and optionally reset I/O statistics for disk operations on a specific database connection or aggregated across all connections.
MCO_RET mco_stat_get_disk_stats(
/*IN*/ const char *db_name,
/*IN*/ int conn_no,
/*OUT*/ mco_disk_stat_t *ret,
/*IN*/ mco_bool reset
);
db_name
conn_no
-1 — aggregates stats across all active connections in the database.ret
mco_disk_stat_t structure that will receive the aggregated I/O statistics.reset
MCO_NO — read only,MCO_YES — read and reset counters to zero.This function collects low-level disk I/O metrics for a database, including counts and timing data for read, write, and synchronization operations. It is available only when
MCO_CFG_SUPPORT_DISK_OBJECTSis enabled at build time.When
conn_no = -1, statistics from all active connections are summed. When a specific connection ID is provided, only that connection’s data is returned.The
mco_disk_stat_tstructure includes:
- Operation counts (
db_total_read,db_total_write,db_sync_count),- Total time spent in each operation type,
- Maximum (peak) time observed for a single operation.
If
reset = MCO_YES, the underlying per-connection counters are cleared after aggregation, enabling delta-based monitoring.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_disk_stat_t disk_stats;
MCO_RET rc;
// Get aggregated disk stats for "mydb" and reset counters
rc = mco_stat_get_disk_stats("mydb", -1, &disk_stats, MCO_YES);
if (rc == MCO_S_OK) {
printf("Total reads: %llu\n", disk_stats.db_total_read);
printf("Max write time: %llu µs\n", disk_stats.db_max_write_time);
printf("Sync operations: %llu\n", disk_stats.db_sync_count);
}