VirtualBox

Changeset 46328 in vbox for trunk/src/VBox/Main


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

Location:
trunk/src/VBox/Main/src-server
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/darwin/PerformanceDarwin.cpp

    r44529 r46328  
    6666    virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
    6767private:
    68     ULONG totalRAM;
     68    ULONG    totalRAM;
    6969    uint32_t nCpus;
    7070};
     
    116116int CollectorDarwin::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
    117117{
     118    AssertReturn(totalRAM, VERR_INTERNAL_ERROR);
    118119    uint64_t cb;
    119120    int rc = RTSystemQueryAvailableRam(&cb);
  • 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}
  • trunk/src/VBox/Main/src-server/solaris/PerformanceSolaris.cpp

    r46320 r46328  
    105105    FsMap             mFsMap;
    106106    uint32_t          mCpus;
    107 
    108107    ULONG             totalRAM;
    109108};
     
    282281int CollectorSolaris::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
    283282{
    284         uint64_t cb;
    285         int rc = RTSystemQueryAvailableRam(&cb);
    286         if (RT_SUCCESS(rc))
    287         {
    288             *total = totalRAM;
    289             *available = cb / 1024;
    290             *used = *total - *available;
    291         }
    292         return rc;
     283    AssertReturn(totalRAM, VERR_INTERNAL_ERROR);
     284    uint64_t cb;
     285    int rc = RTSystemQueryAvailableRam(&cb);
     286    if (RT_SUCCESS(rc))
     287    {
     288        *total = totalRAM;
     289        *available = cb / 1024;
     290        *used = *total - *available;
     291    }
     292    return rc;
    293293}
    294294
  • trunk/src/VBox/Main/src-server/win/PerformanceWin.cpp

    r46321 r46328  
    9090    HMODULE mhNtDll;
    9191
    92     ULONG totalRAM;
     92    ULONG   totalRAM;
    9393};
    9494
     
    311311int CollectorWin::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
    312312{
     313    AssertReturn(totalRAM, VERR_INTERNAL_ERROR);
    313314    uint64_t cb;
    314315    int rc = RTSystemQueryAvailableRam(&cb);
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