VirtualBox

儲存庫 vbox 的更動 12546


忽略:
時間撮記:
2008-9-17 下午05:11:15 (16 年 以前)
作者:
vboxsync
訊息:

PerfAPI: Improved Linux collector

位置:
trunk/src/VBox/Main
檔案:
修改 3 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Main/include/Performance.h

    r12513 r12546  
    8686
    8787        CollectorHints() : mHostFlags(COLLECT_NONE) {}
    88         void collectHostCpuLoad() { mHostFlags |= COLLECT_CPU_LOAD; }
    89         void collectHostRamUsage() { mHostFlags |= COLLECT_RAM_USAGE; }
     88        void collectHostCpuLoad()
     89            { mHostFlags |= COLLECT_CPU_LOAD; }
     90        void collectHostRamUsage()
     91            { mHostFlags |= COLLECT_RAM_USAGE; }
    9092        void collectProcessCpuLoad(RTPROCESS process)
    91         {
    92             findProcess(process).second |= COLLECT_CPU_LOAD;
    93         }
     93            { findProcess(process).second |= COLLECT_CPU_LOAD; }
    9494        void collectProcessRamUsage(RTPROCESS process)
    95         {
    96             findProcess(process).second |= COLLECT_RAM_USAGE;
    97         }
    98         bool isHostCpuLoadCollected() { return (mHostFlags & COLLECT_CPU_LOAD) != 0; }
    99         bool isHostRamUsageCollected() { return (mHostFlags & COLLECT_RAM_USAGE) != 0; }
     95            { findProcess(process).second |= COLLECT_RAM_USAGE; }
     96        bool isHostCpuLoadCollected() const
     97            { return (mHostFlags & COLLECT_CPU_LOAD) != 0; }
     98        bool isHostRamUsageCollected() const
     99            { return (mHostFlags & COLLECT_RAM_USAGE) != 0; }
    100100        bool isProcessCpuLoadCollected(RTPROCESS process)
    101         {
    102             return (findProcess(process).second & COLLECT_CPU_LOAD) != 0;
    103         }
     101            { return (findProcess(process).second & COLLECT_CPU_LOAD) != 0; }
    104102        bool isProcessRamUsageCollected(RTPROCESS process)
    105         {
    106             return (findProcess(process).second & COLLECT_RAM_USAGE) != 0;
    107         }
     103            { return (findProcess(process).second & COLLECT_RAM_USAGE) != 0; }
    108104        void getProcesses(std::vector<RTPROCESS>& processes) const
    109105        {
  • 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
  • trunk/src/VBox/Main/testcase/tstCollector.cpp

    r12513 r12546  
    5151#endif
    5252
    53 pm::CollectorHAL *createCollector()
    54 {
    55 #ifdef RT_OS_SOLARIS
    56     return new pm::CollectorSolaris();
    57 #endif
    58 #ifdef RT_OS_LINUX
    59     return new pm::CollectorLinux();
    60 #endif
    61 #ifdef RT_OS_WINDOWS
    62     return new pm::CollectorWin();
    63 #endif
    64 #ifdef RT_OS_OS2
    65     return new pm::CollectorOS2();
    66 #endif
    67 #ifdef RT_OS_DARWIN
    68     return new pm::CollectorDarwin();
    69 #endif
    70     return 0;
    71 }
    72 
    7353#define RUN_TIME_MS        1000
    7454
     
    128108    uint64_t start;
    129109    unsigned int nCalls;
    130     uint32_t totalTime = 0;
    131110    /* Pre-collect */
    132111    CALLS_PER_SECOND(preCollect(hints));
     
    199178#endif
    200179
    201     pm::CollectorHAL *collector = createCollector();
     180    pm::CollectorHAL *collector = pm::createHAL();
    202181    if (!collector)
    203182    {
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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