VirtualBox

Changeset 10713 in vbox for trunk


Ignore:
Timestamp:
Jul 16, 2008 8:28:43 PM (16 years ago)
Author:
vboxsync
Message:

Perf API: aggregators, data collection, Host RAM metrics, Linux RAM metrics, and more

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HostImpl.cpp

    r10595 r10713  
    26962696    pm::MetricFactory *metricFactory = aCollector->getMetricFactory();
    26972697    /* Create sub metrics */
    2698     pm::SubMetric *cpuLoadUser = new pm::SubMetric ("CPU/Load/User");
     2698    pm::SubMetric *cpuLoadUser   = new pm::SubMetric ("CPU/Load/User");
    26992699    pm::SubMetric *cpuLoadKernel = new pm::SubMetric ("CPU/Load/Kernel");
    2700     pm::SubMetric *cpuLoadIdle = new pm::SubMetric ("CPU/Load/Idle");
     2700    pm::SubMetric *cpuLoadIdle   = new pm::SubMetric ("CPU/Load/Idle");
     2701    pm::SubMetric *ramUsageTotal = new pm::SubMetric ("RAM/Usage/Total");
     2702    pm::SubMetric *ramUsageUsed  = new pm::SubMetric ("RAM/Usage/Used");
     2703    pm::SubMetric *ramUsageFree  = new pm::SubMetric ("RAM/Usage/Free");
    27012704    /* Create and register base metrics */
    27022705    IUnknown *objptr;
     
    27072710                                          cpuLoadIdle);
    27082711    aCollector->registerBaseMetric (cpuLoad);
     2712    pm::BaseMetric *ramUsage =
     2713        metricFactory->createHostCpuLoad (objptr, ramUsageTotal, ramUsageUsed,
     2714                                          ramUsageFree);
     2715    aCollector->registerBaseMetric (ramUsage);
     2716
    27092717    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser, 0));
    27102718    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
     
    27142722    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
    27152723                                               new pm::AggregateMax()));
     2724
    27162725    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel, 0));
    27172726    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
     
    27212730    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
    27222731                                               new pm::AggregateMax()));
     2732
    27232733    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle, 0));
    27242734    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
     
    27282738    aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
    27292739                                               new pm::AggregateMax()));
     2740
     2741    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 0));
     2742    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
     2743                                               new pm::AggregateAvg()));
     2744    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
     2745                                               new pm::AggregateMin()));
     2746    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
     2747                                               new pm::AggregateMax()));
     2748
     2749    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 0));
     2750    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
     2751                                               new pm::AggregateAvg()));
     2752    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
     2753                                               new pm::AggregateMin()));
     2754    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
     2755                                               new pm::AggregateMax()));
     2756
     2757    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 0));
     2758    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
     2759                                               new pm::AggregateAvg()));
     2760    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
     2761                                               new pm::AggregateMin()));
     2762    aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
     2763                                               new pm::AggregateMax()));
    27302764};
    27312765
  • trunk/src/VBox/Main/Performance.cpp

    r10679 r10713  
    3535// Default factory
    3636
    37 BaseMetric *MetricFactory::createHostCpuLoad(IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
     37BaseMetric *MetricFactory::createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
    3838{
    3939    Assert(mHAL);
    4040    return new HostCpuLoad(mHAL, object, user, kernel, idle);
    4141}
    42 BaseMetric *MetricFactory::createHostCpuMHz(IUnknown *object, SubMetric *mhz)
     42BaseMetric *MetricFactory::createHostCpuMHz(ComPtr<IUnknown> object, SubMetric *mhz)
    4343{
    4444    Assert(mHAL);
    4545    return new HostCpuMhz(mHAL, object, mhz);
    4646}
    47 BaseMetric *MetricFactory::createHostRamUsage(IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available)
     47BaseMetric *MetricFactory::createHostRamUsage(ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available)
    4848{
    4949    Assert(mHAL);
    5050    return new HostRamUsage(mHAL, object, total, used, available);
    5151}
    52 BaseMetric *MetricFactory::createMachineCpuLoad(IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
     52BaseMetric *MetricFactory::createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
    5353{
    5454    Assert(mHAL);
    5555    return new MachineCpuLoad(mHAL, object, process, user, kernel);
    5656}
    57 BaseMetric *MetricFactory::createMachineRamUsage(IUnknown *object, RTPROCESS process, SubMetric *used)
     57BaseMetric *MetricFactory::createMachineRamUsage(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used)
    5858{
    5959    Assert(mHAL);
     
    6969}
    7070
    71 BaseMetric *MetricFactoryLinux::createHostCpuLoad(IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
     71BaseMetric *MetricFactoryLinux::createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
    7272{
    7373    Assert(mHAL);
     
    7575}
    7676
    77 BaseMetric *MetricFactoryLinux::createMachineCpuLoad(IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
     77BaseMetric *MetricFactoryLinux::createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
    7878{
    7979    Assert(mHAL);
     
    173173    return E_NOTIMPL;
    174174}
     175
    175176int CollectorLinux::getHostMemoryUsage(unsigned long *total, unsigned long *used, unsigned long *available)
    176177{
    177     return E_NOTIMPL;
     178#ifdef RT_OS_LINUX
     179    int rc = VINF_SUCCESS;
     180    unsigned long buffers, cached;
     181    FILE *f = fopen("/proc/meminfo", "r");
     182
     183    if (f)
     184    {
     185        int processed = fscanf(f, "MemTotal: %lu kB", total);
     186        processed    += fscanf(f, "MemFree: %lu kB", available);
     187        processed    += fscanf(f, "Buffers: %lu kB", &buffers);
     188        processed    += fscanf(f, "Cached: %lu kB", &cached);
     189        if (processed == 4)
     190            *available += buffers + cached;
     191        else
     192            rc = VERR_FILE_IO_ERROR;
     193        fclose(f);
     194    }
     195    else
     196        rc = VERR_ACCESS_DENIED;
     197
     198    return rc;
     199#else
     200    return E_NOTIMPL;
     201#endif
    178202}
    179203int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, unsigned long *used)
    180204{
    181205    return E_NOTIMPL;
     206}
     207
     208void BaseMetric::collectorBeat(uint64_t nowAt)
     209{
     210    if (isEnabled())
     211    {
     212        if (nowAt - mLastSampleTaken >= mPeriod * 1000)
     213        {
     214            mLastSampleTaken = nowAt;
     215            collect();
     216        }
     217    }
    182218}
    183219
     
    205241    unsigned long userDiff, kernelDiff, idleDiff, totalDiff;
    206242
    207     mHAL->getRawHostCpuLoad(&user, &kernel, &idle);
    208 
    209     userDiff   = user   - mUserPrev;
    210     kernelDiff = kernel - mKernelPrev;
    211     idleDiff   = idle   - mIdlePrev;
    212     totalDiff  = userDiff + kernelDiff + idleDiff;
    213 
    214     mUser->put(PM_CPU_LOAD_MULTIPLIER * userDiff / totalDiff);
    215     mKernel->put(PM_CPU_LOAD_MULTIPLIER * kernelDiff / totalDiff);
    216     mIdle->put(PM_CPU_LOAD_MULTIPLIER * idleDiff / totalDiff);
    217 
    218     mUserPrev   = user;
    219     mKernelPrev = kernel;
    220     mIdlePrev   = idle;
     243    int rc = mHAL->getRawHostCpuLoad(&user, &kernel, &idle);
     244    AssertRC(rc);
     245    if (RT_SUCCESS(rc))
     246    {
     247        userDiff   = user   - mUserPrev;
     248        kernelDiff = kernel - mKernelPrev;
     249        idleDiff   = idle   - mIdlePrev;
     250        totalDiff  = userDiff + kernelDiff + idleDiff;
     251   
     252        mUser->put(PM_CPU_LOAD_MULTIPLIER * userDiff / totalDiff);
     253        mKernel->put(PM_CPU_LOAD_MULTIPLIER * kernelDiff / totalDiff);
     254        mIdle->put(PM_CPU_LOAD_MULTIPLIER * idleDiff / totalDiff);
     255   
     256        mUserPrev   = user;
     257        mKernelPrev = kernel;
     258        mIdlePrev   = idle;
     259    }
    221260}
    222261
     
    231270{
    232271    unsigned long mhz;
    233     mHAL->getHostCpuMHz(&mhz);
    234     mMHz->put(mhz);
     272    int rc = mHAL->getHostCpuMHz(&mhz);
     273    AssertRC(rc);
     274    if (RT_SUCCESS(rc))
     275        mMHz->put(mhz);
    235276}
    236277
     
    247288{
    248289    unsigned long total, used, available;
    249     mHAL->getHostMemoryUsage(&total, &used, &available);
    250     mTotal->put(total);
    251     mUsed->put(used);
    252     mAvailable->put(available);
     290    int rc = mHAL->getHostMemoryUsage(&total, &used, &available);
     291    AssertRC(rc);
     292    if (RT_SUCCESS(rc))
     293    {
     294        mTotal->put(total);
     295        mUsed->put(used);
     296        mAvailable->put(available);
     297    }
    253298}
    254299
     
    266311{
    267312    unsigned long user, kernel;
    268     mHAL->getProcessCpuLoad(mProcess, &user, &kernel);
    269     mUser->put(user);
    270     mKernel->put(kernel);
     313    int rc = mHAL->getProcessCpuLoad(mProcess, &user, &kernel);
     314    AssertRC(rc);
     315    if (RT_SUCCESS(rc))
     316    {
     317        mUser->put(user);
     318        mKernel->put(kernel);
     319    }
    271320}
    272321
     
    276325    unsigned long processUser, processKernel;
    277326
    278     mHAL->getRawHostCpuLoad(&hostUser, &hostKernel, &hostIdle);
    279     hostTotal = hostUser + hostKernel + hostIdle;
    280 
    281     mHAL->getRawProcessCpuLoad(mProcess, &processUser, &processKernel);
    282     mUser->put(PM_CPU_LOAD_MULTIPLIER * (processUser - mProcessUserPrev) / (hostTotal - mHostTotalPrev));
    283     mUser->put(PM_CPU_LOAD_MULTIPLIER * (processKernel - mProcessKernelPrev ) / (hostTotal - mHostTotalPrev));
    284 
    285     mHostTotalPrev     = hostTotal;
    286     mProcessUserPrev   = processUser;
    287     mProcessKernelPrev = processKernel;
     327    int rc = mHAL->getRawHostCpuLoad(&hostUser, &hostKernel, &hostIdle);
     328    AssertRC(rc);
     329    if (RT_SUCCESS(rc))
     330    {
     331        hostTotal = hostUser + hostKernel + hostIdle;
     332   
     333        rc = mHAL->getRawProcessCpuLoad(mProcess, &processUser, &processKernel);
     334        AssertRC(rc);
     335        if (RT_SUCCESS(rc))
     336        {
     337            mUser->put(PM_CPU_LOAD_MULTIPLIER * (processUser - mProcessUserPrev) / (hostTotal - mHostTotalPrev));
     338            mUser->put(PM_CPU_LOAD_MULTIPLIER * (processKernel - mProcessKernelPrev ) / (hostTotal - mHostTotalPrev));
     339       
     340            mHostTotalPrev     = hostTotal;
     341            mProcessUserPrev   = processUser;
     342            mProcessKernelPrev = processKernel;
     343        }
     344    }
    288345}
    289346
     
    298355{
    299356    unsigned long used;
    300     mHAL->getProcessMemoryUsage(mProcess, &used);
    301     mUsed->put(used);
     357    int rc = mHAL->getProcessMemoryUsage(mProcess, &used);
     358    AssertRC(rc);
     359    if (RT_SUCCESS(rc))
     360        mUsed->put(used);
    302361}
    303362
     
    308367    mLength = length;
    309368    mData = (unsigned long *)RTMemAllocZ(length * sizeof(unsigned long));
    310     mPosition = 0;
     369    mWrapped = false;
     370    mEnd = 0;
    311371}
    312372
    313373unsigned long CircularBuffer::length()
    314374{
    315     return mLength;
     375    return mWrapped ? mLength : mEnd;
    316376}
    317377
    318378void CircularBuffer::put(unsigned long value)
    319379{
    320     mData[mPosition++] = value;
    321     if (mPosition >= mLength)
    322         mPosition = 0;
    323 }
    324 
    325 void CircularBuffer::copyTo(unsigned long *data, unsigned long length)
    326 {
    327     memcpy(data, mData + mPosition, (length - mPosition) * sizeof(unsigned long));
    328     // Copy the wrapped part
    329     if (mPosition)
    330         memcpy(data + mPosition, mData, mPosition * sizeof(unsigned long));
    331 }
    332 
    333 void SubMetric::query(unsigned long *data, unsigned long count)
    334 {
    335     copyTo(data, count);
     380    if (mData)
     381    {
     382        mData[mEnd++] = value;
     383        if (mEnd >= mLength)
     384        {
     385            mEnd = 0;
     386            mWrapped = true;
     387        }
     388    }
     389}
     390
     391void CircularBuffer::copyTo(unsigned long *data)
     392{
     393    if (mWrapped)
     394    {
     395        memcpy(data, mData + mEnd, (mLength - mEnd) * sizeof(unsigned long));
     396        // Copy the wrapped part
     397        if (mEnd)
     398            memcpy(data + mEnd, mData, mEnd * sizeof(unsigned long));
     399    }
     400    else
     401        memcpy(data, mData, mEnd * sizeof(unsigned long));
     402}
     403
     404void SubMetric::query(unsigned long *data)
     405{
     406    copyTo(data);
    336407}
    337408   
     
    345416    {
    346417        tmpData = (unsigned long*)RTMemAlloc(sizeof(*tmpData)*length);
    347         mSubMetric->query(tmpData, length);
     418        mSubMetric->query(tmpData);
    348419        if (mAggregate)
    349420        {
     
    351422            *data  = (unsigned long*)RTMemAlloc(sizeof(**data));
    352423            **data = mAggregate->compute(tmpData, length);
     424            RTMemFree(tmpData);
    353425        }
    354426        else
     
    367439unsigned long AggregateAvg::compute(unsigned long *data, unsigned long length)
    368440{
    369     return 0;
     441    uint64_t tmp = 0;
     442    for (unsigned long i = 0; i < length; ++i)
     443        tmp += data[i];
     444    return tmp / length;
    370445}
    371446
     
    377452unsigned long AggregateMin::compute(unsigned long *data, unsigned long length)
    378453{
    379     return 0;
     454    unsigned long tmp = *data;
     455    for (unsigned long i = 0; i < length; ++i)
     456        if (data[i] < tmp)
     457            tmp = data[i];
     458    return tmp;
    380459}
    381460
     
    387466unsigned long AggregateMax::compute(unsigned long *data, unsigned long length)
    388467{
    389     return 0;
     468    unsigned long tmp = *data;
     469    for (unsigned long i = 0; i < length; ++i)
     470        if (data[i] > tmp)
     471            tmp = data[i];
     472    return tmp;
    390473}
    391474
     
    395478}
    396479
    397 Filter::Filter(ComSafeArrayIn(const BSTR, metricNames),
     480Filter::Filter(ComSafeArrayIn(INPTR BSTR, metricNames),
    398481               ComSafeArrayIn(IUnknown *, objects))
    399482{
    400483    com::SafeIfaceArray <IUnknown> objectArray(ComSafeArrayInArg(objects));
    401     com::SafeArray <BSTR> nameArray(ComSafeArrayInArg(metricNames));
     484    com::SafeArray <INPTR BSTR> nameArray(ComSafeArrayInArg(metricNames));
    402485    for (size_t i = 0; i < objectArray.size(); ++i)
    403486        processMetricList(std::string(com::Utf8Str(nameArray[i])), objectArray[i]);
    404487}
    405488
    406 void Filter::processMetricList(const std::string &name, const IUnknown *object)
     489void Filter::processMetricList(const std::string &name, const ComPtr<IUnknown> object)
    407490{
    408491    std::string::size_type startPos = 0;
     
    418501}
    419502
    420 bool Filter::match(const IUnknown *object, const std::string &name) const
     503bool Filter::match(const ComPtr<IUnknown> object, const std::string &name) const
    421504{
    422505    return true;
  • trunk/src/VBox/Main/PerformanceImpl.cpp

    r10679 r10713  
    6969////////////////////////////////////////////////////////////////////////////////
    7070
    71 PerformanceCollector::PerformanceCollector() {}
     71PerformanceCollector::PerformanceCollector() : mMagic(0) {}
    7272
    7373PerformanceCollector::~PerformanceCollector() {}
     
    103103    /* @todo Obviously other platforms must be added as well. */
    104104    m.mFactory = new pm::MetricFactoryLinux();
     105
     106    /* Let the sampler know it gets a valid collector.  */
     107    mMagic = MAGIC;
     108
    105109    /* Start resource usage sampler */
    106 
    107110    int vrc = RTTimerCreate (&m.mSampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,
    108111                             &PerformanceCollector::staticSamplerCallback, this);
     
    138141    }
    139142
     143    mMagic = 0;
     144
    140145    /* Destroy resource usage sampler */
    141146    int vrc = RTTimerDestroy (m.mSampler);
     
    190195}
    191196
    192 STDMETHODIMP PerformanceCollector::SetupMetrics (ComSafeArrayIn(const BSTR, metricNames),
     197STDMETHODIMP PerformanceCollector::SetupMetrics (ComSafeArrayIn(INPTR BSTR, metricNames),
    193198                                                 ComSafeArrayIn(IUnknown *, objects),
    194199                                                 ULONG aPeriod, ULONG aCount)
     
    199204    for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
    200205        if (filter.match((*it)->getObject(), (*it)->getName()))
     206        {
    201207            (*it)->init(aPeriod, aCount);
     208            (*it)->enable();
     209        }
    202210
    203211    return S_OK;
     
    207215                                                  ComSafeArrayIn(IUnknown *, objects))
    208216{
    209     return E_NOTIMPL;
     217    pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
     218
     219    BaseMetricList::iterator it;
     220    for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
     221        if (filter.match((*it)->getObject(), (*it)->getName()))
     222            (*it)->enable();
     223
     224    return S_OK;
    210225}
    211226
     
    213228                                                   ComSafeArrayIn(IUnknown *, objects))
    214229{
    215     return E_NOTIMPL;
     230    pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
     231
     232    BaseMetricList::iterator it;
     233    for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
     234        if (filter.match((*it)->getObject(), (*it)->getName()))
     235            (*it)->disable();
     236
     237    return S_OK;
    216238}
    217239
     
    245267    com::SafeArray<ULONG> retLengths(numberOfMetrics);
    246268    com::SafeArray<LONG> retData(flatSize);
     269
    247270    for (it = m.mMetrics.begin(), i = 0; it != m.mMetrics.end(); ++it)
    248271    {
     
    254277        Bstr tmp((*it)->getName());
    255278        tmp.detachTo(&retNames[i]);
    256         retObjects[i] = (*it)->getObject();
     279        (*it)->getObject().queryInterfaceTo(&retObjects[i]);
    257280        retLengths[i] = length;
    258281        retIndices[i] = flatIndex;
     
    260283        flatIndex += length;
    261284    }
     285
    262286    retNames.detachTo(ComSafeArrayOutArg(outMetricNames));
    263287    retObjects.detachTo(ComSafeArrayOutArg(outObjects));
     
    303327{
    304328    AssertReturnVoid (pvUser != NULL);
    305     static_cast <PerformanceCollector *> (pvUser)->samplerCallback();
     329    PerformanceCollector *collector = static_cast <PerformanceCollector *> (pvUser);
     330    Assert(collector->mMagic == MAGIC);
     331    if (collector->mMagic == MAGIC)
     332    {
     333        collector->samplerCallback();
     334    }
    306335}
    307336
    308337void PerformanceCollector::samplerCallback()
    309338{
     339    uint64_t timestamp = RTTimeMilliTS();
     340    std::for_each(m.mBaseMetrics.begin(), m.mBaseMetrics.end(),
     341                  std::bind2nd (std::mem_fun (&pm::BaseMetric::collectorBeat), timestamp));
    310342}
    311343
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r10695 r10713  
    1015710157  >
    1015810158    <desc>
    10159       The IPerformanceCollector interfaces represents a service that collects
    10160       and stores performace metrics data.
     10159      The IPerformanceCollector interface represents a service that collects and
     10160      stores performace metrics data.
    1016110161
    1016210162      Performance metrics are associated with objects like IHost and IMachine.
     
    1028010280      <desc>
    1028110281        Queries collected metrics data for a set of objects.
     10282       
     10283        The data itself and related metric information are returned in four
     10284        parallel and one flattened array of arrays. Elements of @c
     10285        returnMetricNames, @c returnObjects, @c returnDataIndices and @
     10286        returnDataLengths with the same index describe one set of values
     10287        corresponding to a single metric.
    1028210288
    1028310289        The @a returnData parameter is a flattened array of arrays. Each start
    1028410290        and length of a sub-array is indicated by @a returnDataIndices and @a
    10285         returnDataLengths.
     10291        returnDataLengths. The first value for metric <tt>metricNames[i]</tt> is at
     10292        <tt> returnData[returnIndices[i]]</tt>.
    1028610293
    1028710294        <note>
     
    1032510332        <desc>
    1032610333          Flattened array of all metric data containing sequences of values for
    10327           each metric. The first value for metric <tt>metricNames[i]</tt> is at
    10328           <tt> returnData[returnIndices[i]]</tt>.
     10334          each metric.
    1032910335        </desc>
    1033010336      </param>
  • trunk/src/VBox/Main/include/Performance.h

    r10679 r10713  
    2929
    3030namespace pm {
    31     const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(1000000000);
    32     /*IUnknown * iunknown(ComPtr<IUnknown> object)
    33     {
    34         IUnknown *objptr;
    35 
    36         object.queryInterfaceTo(&objptr);
    37         return objptr;
    38     }*/
     31    const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000000);
    3932
    4033    /* Sub Metrics **********************************************************/
     
    4235    {
    4336    public:
    44         CircularBuffer() : mData(0), mLength(0), mPosition(0) {};
     37        CircularBuffer() : mData(0), mLength(0), mEnd(0), mWrapped(false) {};
    4538        void init(unsigned long length);
    4639        unsigned long length();
    4740        void put(unsigned long value);
    48         void copyTo(unsigned long *data, unsigned long length);
     41        void copyTo(unsigned long *data);
    4942    private:
    5043        unsigned long *mData;
    51         unsigned long mLength;
    52         unsigned long mPosition;
     44        unsigned long  mLength;
     45        unsigned long  mEnd;
     46        bool           mWrapped;
    5347    };
    5448
     
    5852        SubMetric(const char *name)
    5953        : mName(name) {};
    60         void query(unsigned long *data, unsigned long count);
     54        void query(unsigned long *data);
    6155        const char *getName() { return mName; };
    6256    private:
     
    9488    {
    9589    public:
    96         BaseMetric(CollectorHAL *hal, const char *name, IUnknown *object)
    97             : mHAL(hal), mLength(0), mName(name), mObject(object) {};
     90        BaseMetric(CollectorHAL *hal, const char *name, ComPtr<IUnknown> object)
     91            : mHAL(hal), mLength(0), mName(name), mObject(object), mLastSampleTaken(0), mEnabled(false) {};
    9892
    9993        virtual void init(unsigned long period, unsigned long length) = 0;
     
    10397        virtual unsigned long getMaxValue() = 0;
    10498
     99        void collectorBeat(uint64_t nowAt);
     100
     101        void enable() { mEnabled = true; };
     102        void disable() { mEnabled = false; };
     103
     104        bool isEnabled() { return mEnabled; };
    105105        unsigned long getPeriod() { return mPeriod; };
    106106        unsigned long getLength() { return mLength; };
    107107        const char *getName() { return mName; };
    108         IUnknown *getObject() { return mObject; };
    109         bool associatedWith(IUnknown *object) { return mObject == object; };
     108        ComPtr<IUnknown> getObject() { return mObject; };
     109        bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; };
    110110
    111111    protected:
    112         CollectorHAL *mHAL;
    113         unsigned long mPeriod;
    114         unsigned long mLength;
    115         const char   *mName;
    116         IUnknown     *mObject;
     112        CollectorHAL    *mHAL;
     113        unsigned long    mPeriod;
     114        unsigned long    mLength;
     115        const char      *mName;
     116        ComPtr<IUnknown> mObject;
     117        uint64_t         mLastSampleTaken;
     118        bool             mEnabled;
    117119    };
    118120   
     
    120122    {
    121123    public:
    122         HostCpuLoad(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
     124        HostCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
    123125        : BaseMetric(hal, "CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {};
    124126        void init(unsigned long period, unsigned long length);
     
    138140    {
    139141    public:
    140         HostCpuLoadRaw(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
     142        HostCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
    141143        : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {};
    142144
     
    151153    {
    152154    public:
    153         HostCpuMhz(CollectorHAL *hal, IUnknown *object, SubMetric *mhz)
     155        HostCpuMhz(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *mhz)
    154156        : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {};
    155157
     
    166168    {
    167169    public:
    168         HostRamUsage(CollectorHAL *hal, IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available)
     170        HostRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available)
    169171        : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mUsed(used), mAvailable(available) {};
    170172
     
    183185    {
    184186    public:
    185         MachineCpuLoad(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
     187        MachineCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
    186188        : BaseMetric(hal, "CPU/Load", object), mProcess(process), mUser(user), mKernel(kernel) {};
    187189
     
    200202    {
    201203    public:
    202         MachineCpuLoadRaw(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
     204        MachineCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
    203205        : MachineCpuLoad(hal, object, process, user, kernel), mHostTotalPrev(0), mProcessUserPrev(0), mProcessKernelPrev(0) {};
    204206
     
    213215    {
    214216    public:
    215         MachineRamUsage(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *used)
     217        MachineRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used)
    216218        : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {};
    217219
     
    273275            delete mAggregate;
    274276        }
    275         bool associatedWith(IUnknown *object) { return getObject() == object; };
     277        bool associatedWith(ComPtr<IUnknown> object) { return getObject() == object; };
    276278
    277279        const char *getName() { return mName.c_str(); };
    278         IUnknown *getObject() { return mBaseMetric->getObject(); };
     280        ComPtr<IUnknown> getObject() { return mBaseMetric->getObject(); };
    279281        const char *getUnit() { return mBaseMetric->getUnit(); };
    280282        unsigned long getMinValue() { return mBaseMetric->getMinValue(); };
     
    298300        ~MetricFactory() { delete mHAL; };
    299301
    300         virtual BaseMetric   *createHostCpuLoad(IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle);
    301         virtual BaseMetric   *createHostCpuMHz(IUnknown *object, SubMetric *mhz);
    302         virtual BaseMetric   *createHostRamUsage(IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available);
    303         virtual BaseMetric   *createMachineCpuLoad(IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel);
    304         virtual BaseMetric   *createMachineRamUsage(IUnknown *object, RTPROCESS process, SubMetric *used);
     302        virtual BaseMetric   *createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle);
     303        virtual BaseMetric   *createHostCpuMHz(ComPtr<IUnknown> object, SubMetric *mhz);
     304        virtual BaseMetric   *createHostRamUsage(ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available);
     305        virtual BaseMetric   *createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel);
     306        virtual BaseMetric   *createMachineRamUsage(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used);
    305307    protected:
    306308        CollectorHAL *mHAL;
     
    312314    public:
    313315        MetricFactoryLinux();
    314         virtual BaseMetric   *createHostCpuLoad(IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle);
    315         virtual BaseMetric   *createMachineCpuLoad(IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel);
     316        virtual BaseMetric   *createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle);
     317        virtual BaseMetric   *createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel);
    316318    };
    317319
     
    319321    {
    320322    public:
    321         Filter(ComSafeArrayIn(const BSTR, metricNames),
    322                ComSafeArrayIn(IUnknown *, objects));
    323         bool match(const IUnknown *object, const std::string &name) const;
    324     private:
    325         typedef std::pair<const IUnknown*, const std::string> FilterElement;
     323        Filter(ComSafeArrayIn(INPTR BSTR, metricNames),
     324               ComSafeArrayIn(IUnknown * , objects));
     325        bool match(const ComPtr<IUnknown> object, const std::string &name) const;
     326    private:
     327        typedef std::pair<const ComPtr<IUnknown>, const std::string> FilterElement;
    326328        std::list<FilterElement> mElements;
    327329
    328         void processMetricList(const std::string &name, const IUnknown *object);
     330        void processMetricList(const std::string &name, const ComPtr<IUnknown> object);
    329331    };
    330332}
  • trunk/src/VBox/Main/include/PerformanceImpl.h

    r10679 r10713  
    205205                           ComSafeArrayIn (IUnknown *, objects),
    206206                           ComSafeArrayOut (IPerformanceMetric *, metrics));
    207     STDMETHOD(SetupMetrics) (ComSafeArrayIn (const BSTR, metricNames),
     207    STDMETHOD(SetupMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames),
    208208                             ComSafeArrayIn (IUnknown *, objects),
    209209                             ULONG aPeriod, ULONG aCount);
     
    243243    typedef std::list<pm::BaseMetric*> BaseMetricList;
    244244
     245    enum
     246    {
     247        MAGIC = 0xABBA1972u
     248    };
     249
     250    unsigned int mMagic;
     251
    245252    struct Data {
    246253        Data() : mFactory(0) {};
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r10679 r10713  
    921921#if 1
    922922    do {
    923         Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg" };
    924         com::SafeArray<BSTR> metrics (1);
    925         metricNames[0].cloneTo (&metrics [0]);
     923        Bstr baseMetricNames[] = { L"CPU/Load,RAM/Usage" };
     924        com::SafeArray<BSTR> baseMetrics (1);
     925        baseMetricNames[0].cloneTo (&baseMetrics [0]);
    926926
    927927        ComPtr <IHost> host;
     
    933933        com::SafeIfaceArray<IUnknown> objects(1);
    934934        host.queryInterfaceTo(&objects[0]);
    935         CHECK_ERROR_BREAK (collector, SetupMetrics(ComSafeArrayAsInParam(metrics),
     935        CHECK_ERROR_BREAK (collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
    936936                                                ComSafeArrayAsInParam(objects), 1u, 10u) );
    937937        RTThreadSleep(3000); /* Sleep 10 seconds. */
     938
     939        Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total.RAM/Usage/Used:avg" };
     940        com::SafeArray<BSTR> metrics (1);
     941        metricNames[0].cloneTo (&metrics [0]);
    938942        com::SafeArray<BSTR>          retNames;
    939943        com::SafeIfaceArray<IUnknown> retObjects;
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