mco_disk_get_alloc_info

This function collects information about the distribution of free disk space.

Prototype

    MCO_RET mco_disk_get_alloc_info(
            /* IN */ mco_db_h con,
            /* OUT */ mco_disk_alloc_info_t* unaligned,
            /* OUT */ mco_disk_alloc_info_t* aligned);

Arguments

con
The database handle for a database connection
unaligned
A pointer to a structure to receive information about the unaligned disk space
aligned
A pointer to a structure to receive information about the aligned disk space

Description

This function collects information about the distribution of free space in the database file. During database operations, the engine may allocate or deallocate space within the file, potentially creating holes. This function analyzes those holes and returns the results in a mco_disk_alloc_info_t structure, which includes a histogram of hole counters.

The mco_disk_alloc_info_t structure is defined as follows:

typedef struct {
    mco_size_t allocated;
    mco_size_t used;
    mco_counter_t profile[MCO_DISK_FRAG_PROFILE_SIZE];
} mco_disk_alloc_info_t;

The fields of the mco_disk_alloc_info_t structure are:

Specifically, profile[0] counts holes that are 1 in-memory page in size, profile[1] counts holes of 2 pages, and so on.

Note: This function scans all bitmap pages in the database file and may take a significant amount of time to complete.

Return Codes

MCO_S_OK
The function completed successfully.
MCO_E_UNSUPPORTED
Unsupported call.

Example

        ...
        #define CHECK(func)  { MCO_RET rc_ = func; if (rc_ != MCO_S_OK) { \
            printf("\nCall \"" #func "\" at %s:%d failed , code = %d\n\t(%s)\n", __FILE__, __LINE__, rc_, mco_ret_string(rc_, 0)); \
            dbg_exit(rc_); }}

        ...
        mco_disk_alloc_info_t unaligned, aligned;
        mco_offs_t allocated, used, total_allocated, total_used;
        ...
        CHECK(mco_disk_get_alloc_info(db, &unaligned, &aligned));
        CHECK(mco_disk_get_allocated_space(db, &allocated, &used));

        total_allocated = unaligned.allocated + aligned.allocated;
        total_used = unaligned.used + aligned.used;
        ...
        printf("alloc_info:      alloc %lld(bytes), used %lld(bytes)\n",
            (mco_int8)total_allocated, (mco_int8)total_used);
        printf("allocated_space: alloc %lld(bytes), used %lld(bytes)\n\n",
            (mco_int8)allocated, (mco_int8)used);
        ...

Files

Header file:
mco.h
Source file:
mcodisk.c
Library:
libmcolib.a