mco_perfmon_attach

Attaches a database to the Performance Monitor for runtime metric collection.

Prototype

    MCO_RET mco_perfmon_attach(/*IN*/ const char *dbName);

Arguments

dbName
Name of the database to be monitored.

Description

This function registers the specified database with the Performance Monitor so that runtime metrics (e.g., transaction counts, cache usage, I/O latency) are collected and stored in the internal perfmon database.

The Performance Monitor must be initialized with mco_perfmon_init() before calling this function.

Return Codes

MCO_S_OK
Database successfully attached for monitoring.
MCO_E_PERFMON_NOT_INITIALIZED
Performance Monitor has not been initialized. Call mco_perfmon_init() first.

Example

    #define PERF_DATABASE_SEGMENT_SIZE (64 << 20)  /* 64 MB */
    const char* dbName = "SimpleDb";

    int main(int argc, char* argv[])
    {
        mco_db_h db;
        MCO_RET rc;
        void *perf_memory;

        // Allocate memory for the perfmon database
        perf_memory = malloc(PERF_DATABASE_SEGMENT_SIZE);
        if (!perf_memory) { /* handle error */ }

        // Initialize Performance Monitor
        rc = mco_perfmon_init(perf_memory, PERF_DATABASE_SEGMENT_SIZE);
        if (rc != MCO_S_OK) { /* handle error */ }

        // Attach target database for monitoring
        rc = mco_perfmon_attach(dbName);
        if (rc != MCO_S_OK) { /* handle error */ }

        // Connect to the database (now being monitored)
        rc = mco_db_connect(dbName, &db);
        if (rc != MCO_S_OK) { /* handle error */ }

        // ... perform monitored operations ...

        return 0;
    }

Files

Header file:
mcoperfmon.h
Source file:
mcoperf.c
Library:
libmcoperf.a