VirtualBox

Changeset 12133

Show
Ignore:
Timestamp:
09/05/08 16:13:33 (3 months ago)
Author:
vboxsync
Message:

PerfAPI: Improved performance of getHostMemoryUsage() on Darwin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 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[]) 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy