VirtualBox

Changeset 12546 in vbox for trunk/src/VBox/Main/linux


Ignore:
Timestamp:
Sep 17, 2008 5:11:15 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
36733
Message:

PerfAPI: Improved Linux collector

File:
1 edited

Legend:

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

    r12400 r12546  
    2727#include <iprt/param.h>
    2828#include <iprt/string.h>
     29
     30#include <map>
     31#include <vector>
     32
     33#include "Logging.h"
    2934#include "Performance.h"
    3035
     
    3439{
    3540public:
     41    virtual int preCollect(const CollectorHints& hints);
    3642    virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
    3743    virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
     
    4046    virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
    4147private:
     48    virtual int _getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
    4249    int getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, ULONG *memPagesUsed);
     50
     51    struct VMProcessStats
     52    {
     53        uint64_t cpuUser;
     54        uint64_t cpuKernel;
     55        ULONG    pagesUsed;
     56    };
     57
     58    typedef std::map<RTPROCESS, VMProcessStats> VMProcessMap;
     59
     60    VMProcessMap mProcessStats;
     61    uint64_t     mUser, mKernel, mIdle;
    4362};
    4463
     
    5069// Collector HAL for Linux
    5170
    52 int CollectorLinux::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
     71int CollectorLinux::preCollect(const CollectorHints& hints)
     72{
     73    std::vector<RTPROCESS> processes;
     74    hints.getProcesses(processes);
     75
     76    std::vector<RTPROCESS>::iterator it;
     77    for(it = processes.begin(); it != processes.end(); it++)
     78    {
     79        VMProcessStats vmStats;
     80        int rc = getRawProcessStats(*it, &vmStats.cpuUser, &vmStats.cpuKernel, &vmStats.pagesUsed);
     81        if (RT_FAILURE(rc))
     82            return rc;
     83        mProcessStats[*it] = vmStats;
     84    }
     85    if (hints.isHostCpuLoadCollected() || mProcessStats.size())
     86    {
     87        _getRawHostCpuLoad(&mUser, &mKernel, &mIdle);
     88    }
     89    return VINF_SUCCESS;
     90}
     91
     92int CollectorLinux::_getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
    5393{
    5494    int rc = VINF_SUCCESS;
     
    74114}
    75115
     116int CollectorLinux::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
     117{
     118    *user   = mUser;
     119    *kernel = mKernel;
     120    *idle   = mIdle;
     121    return VINF_SUCCESS;
     122}
     123
    76124int CollectorLinux::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total)
    77125{
    78     int rc = VINF_SUCCESS;
    79     uint64_t uHostUser, uHostKernel, uHostIdle;
    80 
    81     rc = getRawHostCpuLoad(&uHostUser, &uHostKernel, &uHostIdle);
    82     if (RT_SUCCESS(rc))
    83     {
    84         ULONG ulTmp;
    85         *total = (uint64_t)uHostUser + uHostKernel + uHostIdle;
    86         rc = getRawProcessStats(process, user, kernel, &ulTmp);
    87     }
    88 
    89     return rc;
     126    VMProcessMap::const_iterator it = mProcessStats.find(process);
     127
     128    if (it == mProcessStats.end())
     129    {
     130        Log (("No stats pre-collected for process %x\n", process));
     131        return VERR_INTERNAL_ERROR;
     132    }
     133    *user   = it->second.cpuUser;
     134    *kernel = it->second.cpuKernel;
     135    *total  = mUser + mKernel + mIdle;
     136    return VINF_SUCCESS;
    90137}
    91138
     
    119166int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
    120167{
    121     uint64_t u64Tmp;
    122     ULONG nPagesUsed;
    123     int rc = getRawProcessStats(process, &u64Tmp, &u64Tmp, &nPagesUsed);
    124     if (RT_SUCCESS(rc))
    125     {
    126         Assert(PAGE_SIZE >= 1024);
    127         *used = nPagesUsed * (PAGE_SIZE / 1024);
    128     }
    129     return rc;
     168    VMProcessMap::const_iterator it = mProcessStats.find(process);
     169
     170    if (it == mProcessStats.end())
     171    {
     172        Log (("No stats pre-collected for process %x\n", process));
     173        return VERR_INTERNAL_ERROR;
     174    }
     175    *used = it->second.pagesUsed * (PAGE_SIZE / 1024);
     176    return VINF_SUCCESS;
    130177}
    131178
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