mco_flashsim_get_stat

Retrieve detailed runtime statistics and block state information from a flash memory simulator instance.

Prototype

    MCO_RET mco_flashsim_get_stat(
        /*IN*/  mco_flashsim_h fs,
        /*OUT*/ mco_flashsim_stat_t *fstat,
        /*OUT*/ mco_int4 *block_state
    );

Arguments

fs
Handle to an open flash simulator instance.
fstat
Pointer to a mco_flashsim_stat_t structure that will receive aggregated I/O and timing statistics.
block_state
Optional pointer to an array of mco_int4 values (size = number of blocks). If provided, the function fills it with the state of each erase block:
  • Non-negative value — number of erase cycles,
  • MCO_BLOCK_STATE_ERROR (–1) — block has a programming/erase error,
  • MCO_BLOCK_STATE_BAD (–2) — block is marked as bad.
May be NULL if block-level details are not needed.

Description

This function collects comprehensive diagnostic data from the flash simulator, including:

The statistics are **not reset** after reading — they accumulate for the lifetime of the simulator instance.

If block_state is provided, the caller must ensure the array is large enough to hold geom.n_blocks elements (where geom is the flash geometry used during initialization).

Return Codes

MCO_S_OK
Statistics successfully retrieved.
MCO_E_INVALID_HANDLE
The provided simulator handle is invalid.
MCO_E_DISK
Internal error occurred while accessing block state data.

Example

    mco_flashsim_stat_t stats;
    mco_int4 *block_states = NULL;
    MCO_RET rc;

    // Assume fs is a valid simulator handle
    // and n_blocks is known from initialization params

    block_states = malloc(n_blocks * sizeof(mco_int4));

    rc = mco_flashsim_get_stat(fs, &stats, block_states);
    if (rc == MCO_S_OK) {
        printf("Total erases: %llu\n", stats.n_erases);
        printf("Simulated time: %llu µs\n", stats.simulate_time);

        // Inspect first block
        if (block_states[0] == MCO_BLOCK_STATE_BAD) {
            printf("Block 0 is marked BAD\n");
        }
    }

    free(block_states);

Files

Header file:
mcoflashsim.h
Source file:
mcoflashsim.c
Library:
libmcoflashsim.a