VirtualBox

Ignore:
Timestamp:
Oct 5, 2012 11:23:42 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81167
Message:

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

File:
1 edited

Legend:

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

    r28800 r43555  
    2626#include <iprt/log.h>
    2727#include <iprt/param.h>
     28#include <iprt/system.h>
    2829#include "Performance.h"
    2930
     
    7475CollectorDarwin::CollectorDarwin()
    7576{
    76     uint64_t hostMemory;
    77     int mib[2];
    78     size_t size;
    79 
    80     mib[0] = CTL_HW;
    81     mib[1] = HW_MEMSIZE;
    82 
    83     size = sizeof(hostMemory);
    84     if (sysctl(mib, 2, &hostMemory, &size, NULL, 0) == -1) {
    85         Log(("sysctl() -> %s", strerror(errno)));
    86         hostMemory = 0;
    87     }
    88     totalRAM = (ULONG)(hostMemory / 1024);
     77    uint64_t cb;
     78    int rc = RTSystemQueryTotalRam(&cb);
     79    if (RT_FAILED(rc))
     80        totalRAM = 0;
     81    else
     82        totalRAM = (ULONG)(cb / 1024);
    8983}
    9084
     
    113107int CollectorDarwin::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
    114108{
    115     kern_return_t krc;
    116     mach_msg_type_number_t count;
    117     vm_statistics_data_t info;
    118 
    119     count = HOST_VM_INFO_COUNT;
    120 
    121     krc = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&info, &count);
    122     if (krc != KERN_SUCCESS)
     109    uint64_t cb;
     110    int rc = RTSystemQueryAvailableRam(&cb);
     111    if (RT_SUCCESS(rc))
    123112    {
    124         Log(("host_statistics() -> %s", mach_error_string(krc)));
    125         return RTErrConvertFromDarwinKern(krc);
     113        *total = totalRAM;
     114        *available = cb / 1024;
     115        *used = *total - *available;
    126116    }
    127 
    128     *total = totalRAM;
    129     *available = info.free_count * (PAGE_SIZE / 1024);
    130     *used = *total - *available;
    131     return VINF_SUCCESS;
     117    return rc;
    132118}
    133119
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