VirtualBox

Ignore:
Timestamp:
May 30, 2013 12:37:09 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86099
Message:

Main/PerformanceLinux: switch to the runtime function for determining total/free RAM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp

    r45051 r46328  
    3030#include <iprt/path.h>
    3131#include <iprt/string.h>
     32#include <iprt/system.h>
    3233#include <iprt/mp.h>
    3334
     
    8081    uint64_t     mSingleUser, mSingleKernel, mSingleIdle;
    8182    uint32_t     mHZ;
     83    ULONG        totalRAM;
    8284};
    8385
     
    100102        mHZ = hz;
    101103    LogFlowThisFunc(("mHZ=%u\n", mHZ));
     104
     105    uint64_t cb;
     106    int rc = RTSystemQueryTotalRam(&cb);
     107    if (RT_FAILURE(rc))
     108        totalRAM = 0;
     109    else
     110        totalRAM = (ULONG)(cb / 1024);
    102111}
    103112
     
    202211int CollectorLinux::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
    203212{
    204     int rc = VINF_SUCCESS;
    205     ULONG buffers, cached;
    206     FILE *f = fopen("/proc/meminfo", "r");
    207 
    208     if (f)
    209     {
    210         int processed = fscanf(f, "MemTotal: %u kB\n", total);
    211         processed    += fscanf(f, "MemFree: %u kB\n", available);
    212         processed    += fscanf(f, "Buffers: %u kB\n", &buffers);
    213         processed    += fscanf(f, "Cached: %u kB\n", &cached);
    214         if (processed == 4)
    215         {
    216             *available += buffers + cached;
    217             *used       = *total - *available;
    218         }
    219         else
    220             rc = VERR_FILE_IO_ERROR;
    221         fclose(f);
    222     }
    223     else
    224         rc = VERR_ACCESS_DENIED;
    225 
     213    AssertReturn(totalRAM, VERR_INTERNAL_ERROR);
     214    uint64_t cb;
     215    int rc = RTSystemQueryAvailableRam(&cb);
     216    if (RT_SUCCESS(rc))
     217    {
     218        *total = totalRAM;
     219        *available = cb / 1024;
     220        *used = *total - *available;
     221    }
    226222    return rc;
    227223}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette