VirtualBox

Changeset 12133 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 5, 2008 2:13:33 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
36087
Message:

PerfAPI: Improved performance of getHostMemoryUsage() on Darwin

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

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

    r12066 r12133  
    6565{
    6666public:
     67    CollectorDarwin();
    6768    virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
    6869    virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
    6970    virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
    7071    virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
     72private:
     73    ULONG totalRAM;
    7174};
    7275
     
    7578    mHAL = new CollectorDarwin();
    7679    Assert(mHAL);
     80}
     81
     82CollectorDarwin::CollectorDarwin()
     83{
     84    uint64_t hostMemory;
     85    int mib[2];
     86    size_t size;
     87
     88    mib[0] = CTL_HW;
     89    mib[1] = HW_MEMSIZE;
     90
     91    size = sizeof(hostMemory);
     92    if (sysctl(mib, 2, &hostMemory, &size, NULL, 0) == -1) {
     93        Log(("sysctl() -> %s", strerror(errno)));
     94        hostMemory = 0;
     95    }
     96    totalRAM = (ULONG)(hostMemory / 1024);
    7797}
    7898
     
    114134    }
    115135
    116     uint64_t hostMemory;
    117     int mib[2];
    118     size_t size;
    119 
    120     mib[0] = CTL_HW;
    121     mib[1] = HW_MEMSIZE;
    122 
    123     size = sizeof(hostMemory);
    124     if (sysctl(mib, 2, &hostMemory, &size, NULL, 0) == -1) {
    125         int error = errno;
    126         Log(("sysctl() -> %s", strerror(error)));
    127         return RTErrConvertFromErrno(error);
    128     }
    129     *total = (ULONG)(hostMemory / 1024);
     136    *total = totalRAM;
    130137    *available = info.free_count * (PAGE_SIZE / 1024);
    131138    *used = *total - *available;
  • trunk/src/VBox/Main/testcase/tstCollector.cpp

    r12085 r12133  
    7676    { \
    7777        RTPrintf("tstCollector: "#fn" -> %Vrc\n", rc); \
    78         return 1; \
    7978    } \
    80     RTPrintf("%50s -- %u calls per second\n", #fn, nCalls)
     79    else \
     80        RTPrintf("%50s -- %u calls per second\n", #fn, nCalls)
    8181
    8282int main(int argc, char *argv[])
Note: See TracChangeset for help on using the changeset viewer.

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