Exemplo n.º 1
0
static void
printMemoryUsage(
    c_base base)
{
    c_mm mm;
    c_mmStatus s;

    mm = c_baseMM(base);
    s = c_mmState(mm, FALSE);

    printf("Total size: %lld, Available: %lld, Reusable: %lld.\n", s.used + s.size + s.garbage, s.size + s.garbage, s.garbage);
}
Exemplo n.º 2
0
void
monitor_msAction (
    v_entity entity,
    c_voidp args
    )
{
    time_t ct;
    int cv;
    char timbuf[30];
    char extra[70];
    c_mm mm;
    c_mmStatus s;
    c_mmStatus ms,ls;
    c_base base;
    monitor_ms msData;

    msData = monitor_ms(args);
    base = c_getBase(entity);
    mm = c_baseMM(base);
    s = c_mmState(mm, msData->preallocated);
    ms = c_mmMapState(mm);
    ls = c_mmListState(mm);

    if (msData->rawMode == FALSE) {
        time (&ct);

        if (msData->header == 0) {
            strftime (timbuf, sizeof(timbuf), "%d/%m/%Y", localtime(&ct));

            if (msData->delta && msData->preallocated) {
                printf (MM_MS_TIME_BUF_FMT
                        MM_MS_D_AVAILABLE_HDR_FMT
                        MM_MS_D_COUNT_HDR_FMT
                        MM_MS_D_USED_HDR_FMT
                        MM_MS_D_PREALLOCATED_HDR_FMT
                        MM_MS_D_MAXUSED_HDR_FMT
                        MM_MS_D_REUSABLE_HDR_FMT
                        MM_MS_D_FAILS_HDR_FMT
                        MM_MS_NEWLINE
                        ,
                        timbuf,
                        MM_MS_D_AVAILABLE_HDR,
                        MM_MS_D_COUNT_HDR,
                        MM_MS_D_USED_HDR,
                        MM_MS_D_PREALLOCATED_HDR,
                        MM_MS_D_MAXUSED_HDR,
                        MM_MS_D_REUSABLE_HDR,
                        MM_MS_D_FAILS_HDR);

                msData->header = 1;
            } else if(msData->delta){
                printf (MM_MS_TIME_BUF_FMT
                        MM_MS_D_AVAILABLE_HDR_FMT
                        MM_MS_D_COUNT_HDR_FMT
                        MM_MS_D_USED_HDR_FMT
                        MM_MS_D_MAXUSED_HDR_FMT
                        MM_MS_D_REUSABLE_HDR_FMT
                        MM_MS_D_FAILS_HDR_FMT
                        MM_MS_NEWLINE
                        ,
                        timbuf,
                        MM_MS_D_AVAILABLE_HDR,
                        MM_MS_D_COUNT_HDR,
                        MM_MS_D_USED_HDR,
                        MM_MS_D_MAXUSED_HDR,
                        MM_MS_D_REUSABLE_HDR,
                        MM_MS_D_FAILS_HDR);
                msData->header = 1;
            } else if(msData->preallocated){
                printf (MM_MS_TIME_BUF_HDR_FMT
                        MM_MS_AVAILABLE_HDR_FMT
                        MM_MS_COUNT_HDR_FMT
                        MM_MS_USED_HDR_FMT
                        MM_MS_PREALLOCATED_HDR_FMT
                        MM_MS_MAXUSED_HDR_FMT
                        MM_MS_REUSABLE_HDR_FMT
                        MM_MS_FAILS_HDR_FMT
                        MM_MS_NEWLINE
                        ,
                        timbuf,
                        MM_MS_AVAILABLE_HDR,
                        MM_MS_COUNT_HDR,
                        MM_MS_USED_HDR,
                        MM_MS_PREALLOCATED_HDR,
                        MM_MS_MAXUSED_HDR,
                        MM_MS_REUSABLE_HDR,
                        MM_MS_FAILS_HDR);
                msData->header = 15;
            } else {
                printf (MM_MS_TIME_BUF_HDR_FMT
                        MM_MS_AVAILABLE_HDR_FMT
                        MM_MS_COUNT_HDR_FMT
                        MM_MS_USED_HDR_FMT
                        MM_MS_MAXUSED_HDR_FMT
                        MM_MS_REUSABLE_HDR_FMT
                        MM_MS_FAILS_HDR_FMT
                        MM_MS_NEWLINE
                        ,
                        timbuf,
                        MM_MS_AVAILABLE_HDR,
                        MM_MS_COUNT_HDR,
                        MM_MS_USED_HDR,
                        MM_MS_MAXUSED_HDR,
                        MM_MS_REUSABLE_HDR,
                        MM_MS_FAILS_HDR);
                msData->header = 15;
            }
        }
        strftime (timbuf, sizeof(timbuf), "%H:%M:%S", localtime(&ct));
    } else {
        /* no headers and print time as seconds since start of mmstat */
        os_time now = os_timeGet();
        os_sprintf(timbuf,"%d.%9.9d ",now.tv_sec,now.tv_nsec);
    }

    if (msData->extendedMode) {
        cv = ((s.used * 40)/s.size);
       os_strncpy (extra, "  |                                        |\r\n",
                 sizeof(extra));
        extra [cv+3] = '*';
    } else {
       os_strncpy (extra, "\r\n", sizeof(extra));
    }
    if(msData->delta && msData->preallocated){
        printf (MM_MS_TIME_BUF_FMT
                MM_MS_D_AVAILABLE_FMT
                MM_MS_D_COUNT_FMT
                MM_MS_D_USED_FMT
                MM_MS_D_PREALLOCATED_FMT
                MM_MS_D_MAXUSED_FMT
                MM_MS_D_REUSABLE_FMT
                MM_MS_D_FAILS_FMT
                MM_MS_NEWLINE
                ,
                timbuf,
                s.size - msData->prevState.size,
                s.count - msData->prevState.count,
                s.used - msData->prevState.used,
                s.preallocated - msData->prevState.preallocated,
                s.maxUsed - msData->prevState.maxUsed,
                s.garbage - msData->prevState.garbage,
                s.fails - msData->prevState.fails);

        msData->prevState = s;
    } else if (msData->delta) {
        printf (MM_MS_TIME_BUF_FMT
                MM_MS_D_AVAILABLE_FMT
                MM_MS_D_COUNT_FMT
                MM_MS_D_USED_FMT
                MM_MS_D_MAXUSED_FMT
                MM_MS_D_REUSABLE_FMT
                MM_MS_D_FAILS_FMT
                MM_MS_NEWLINE
                ,
                timbuf,
                s.size - msData->prevState.size,
                s.count - msData->prevState.count,
                s.used - msData->prevState.used,
                s.maxUsed - msData->prevState.maxUsed,
                s.garbage - msData->prevState.garbage,
                s.fails - msData->prevState.fails);

        msData->prevState = s;
    } else {
        char _size[32], _used[32], _maxUsed[32], _reusable[32];

        to_string(ls.size + ls.garbage + ms.garbage, _size);
        to_string(ls.used + ms.used, _used);
        to_string(ls.maxUsed + ms.maxUsed, _maxUsed);
        to_string(ls.garbage + ms.garbage, _reusable);

        if(msData->preallocated){
            char _preallocated[32];

            to_string(s.preallocated, _preallocated);

            printf(MM_MS_TIME_BUF_FMT
                   MM_MS_AVAILABLE_FMT
                   MM_MS_COUNT_FMT
                   MM_MS_USED_FMT
                   MM_MS_PREALLOCATED_FMT
                   MM_MS_MAXUSED_FMT
                   MM_MS_REUSABLE_FMT
                   MM_MS_FAILS_FMT
                   MM_MS_EXTRA_FMT
                   ,
                   timbuf,
                   _size,
                   ls.count + ms.count,
                   _used,
                   _preallocated,
                   _maxUsed,
                   _reusable,
                   ls.fails + ms.fails,
                   extra);
        } else {
            printf(MM_MS_TIME_BUF_FMT
                   MM_MS_AVAILABLE_FMT
                   MM_MS_COUNT_FMT
                   MM_MS_USED_FMT
                   MM_MS_MAXUSED_FMT
                   MM_MS_REUSABLE_FMT
                   MM_MS_FAILS_FMT
                   MM_MS_EXTRA_FMT
                   ,
                   timbuf,
                   _size,
                   ls.count + ms.count,
                   _used,
                   _maxUsed,
                   _reusable,
                   ls.fails + ms.fails,
                   extra);
        }
    }
    msData->header--;
}