# mco_perfmon_init

> Initializes the Performance Monitor (perfmon) database.

### Prototype

        MCO_RET mco_perfmon_init(/*IN*/ void *memory, /*IN*/ mco_size_t memory_size);

### Arguments

`memory`
Pointer to a memory block allocated for the perfmon database.
`memory_size`
Size of the memory block, in bytes.

### Description

> This function initializes the internal perfmon database used to store runtime performance metrics. The provided memory block must remain valid for the entire duration of monitoring.

> This function must be called before any other perfmon API function (e.g., `mco_perfmon_attach()`).

### Return Codes

`MCO_S_OK`
Perfmon database initialized successfully.
`MCO_E_PERFMON_ALREADY_INITIALIZED`
A perfmon instance is already active. Only one instance can exist at a time.

### Example

        #define PERF_DATABASE_SEGMENT_SIZE (64 << 20)  /* 64 MB */

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

            perf_memory = malloc(PERF_DATABASE_SEGMENT_SIZE);
            if (!perf_memory) {
                /* handle allocation error */
            }

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

            /* Proceed with mco_perfmon_attach(), etc. */

            return 0;
        }

### Files

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