VirtualBox

Changeset 10770 in vbox for trunk


Ignore:
Timestamp:
Jul 21, 2008 9:02:08 AM (16 years ago)
Author:
vboxsync
Message:

Main: Performance: Second m is redundant. Some locking-related todos.

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

Legend:

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

    r10753 r10770  
    103103    /* @todo Obviously other platforms must be added as well. */
    104104#ifdef RT_OS_SOLARIS
    105     m.mFactory = new pm::MetricFactorySolaris();
     105    m.factory = new pm::MetricFactorySolaris();
    106106#endif
    107107#ifdef RT_OS_LINUX
    108     m.mFactory = new pm::MetricFactoryLinux();
     108    m.factory = new pm::MetricFactoryLinux();
    109109#endif
    110110#ifdef RT_OS_WINDOWS
    111     m.mFactory = new pm::MetricFactoryWin();
     111    m.factory = new pm::MetricFactoryWin();
    112112#endif
    113113#ifdef RT_OS_OS2
    114     m.mFactory = new pm::MetricFactoryOS2();
     114    m.factory = new pm::MetricFactoryOS2();
    115115#endif
    116116#ifdef RT_OS_DARWIN
    117     m.mFactory = new pm::MetricFactoryDarwin();
     117    m.factory = new pm::MetricFactoryDarwin();
    118118#endif
    119119
     
    122122
    123123    /* Start resource usage sampler */
    124     int vrc = RTTimerCreate (&m.mSampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,
     124    int vrc = RTTimerCreate (&m.sampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,
    125125                             &PerformanceCollector::staticSamplerCallback, this);
    126126    AssertMsgRC (vrc, ("Failed to create resource usage "
     
    158158
    159159    /* Destroy resource usage sampler */
    160     int vrc = RTTimerDestroy (m.mSampler);
     160    int vrc = RTTimerDestroy (m.sampler);
    161161    AssertMsgRC (vrc, ("Failed to destroy resource usage "
    162162                       "sampling timer (%Rra)\n", vrc));
    163     m.mSampler = NULL;
    164 
    165     delete m.mFactory;
    166     m.mFactory = NULL;
     163    m.sampler = NULL;
     164
     165    delete m.factory;
     166    m.factory = NULL;
    167167
    168168    LogFlowThisFuncLeave();
     
    197197////////////////////////////////////////////////////////////////////////////////
    198198
    199 STDMETHODIMP PerformanceCollector::GetMetrics(ComSafeArrayIn(INPTR BSTR, metricNames),
    200                                               ComSafeArrayIn(IUnknown *, objects),
    201                                               ComSafeArrayOut(IPerformanceMetric *, outMetrics))
     199STDMETHODIMP
     200PerformanceCollector::GetMetrics (ComSafeArrayIn (INPTR BSTR, metricNames),
     201                                  ComSafeArrayIn (IUnknown *, objects),
     202                                  ComSafeArrayOut (IPerformanceMetric *, outMetrics))
    202203{
    203204    //LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType));
     
    208209    CheckComRCReturnRC (autoCaller.rc());
    209210
    210     pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
     211    pm::Filter filter (ComSafeArrayInArg (metricNames),
     212                       ComSafeArrayInArg (objects));
    211213
    212214    AutoReadLock alock (this);
     
    214216    MetricList filteredMetrics;
    215217    MetricList::iterator it;
    216     for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it)
    217         if (filter.match((*it)->getObject(), (*it)->getName()))
    218             filteredMetrics.push_back(*it);
    219 
    220     com::SafeIfaceArray<IPerformanceMetric> retMetrics(filteredMetrics.size());
     218    for (it = m.metrics.begin(); it != m.metrics.end(); ++it)
     219        if (filter.match ((*it)->getObject(), (*it)->getName()))
     220            filteredMetrics.push_back (*it);
     221
     222    com::SafeIfaceArray<IPerformanceMetric> retMetrics (filteredMetrics.size());
    221223    int i = 0;
    222224    for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it)
    223225    {
    224         ComObjPtr<PerformanceMetric> metric;
     226        ComObjPtr <PerformanceMetric> metric;
    225227        rc = metric.createObject();
    226228        if (SUCCEEDED (rc))
    227229            rc = metric->init (*it);
    228         ComAssertComRCThrowRC (rc);
    229         LogFlow(("PerformanceCollector::GetMetrics() store a metric at retMetrics[%d]...\n", i));
    230         metric.queryInterfaceTo(&retMetrics[i++]);
     230        AssertComRCReturnRC (rc);
     231        LogFlow (("PerformanceCollector::GetMetrics() store a metric at "
     232                  "retMetrics[%d]...\n", i));
     233        metric.queryInterfaceTo (&retMetrics [++ i]);
    231234    }
    232     retMetrics.detachTo(ComSafeArrayOutArg(outMetrics));
     235    retMetrics.detachTo (ComSafeArrayOutArg(outMetrics));
    233236    return rc;
    234237}
    235238
    236 STDMETHODIMP PerformanceCollector::SetupMetrics (ComSafeArrayIn(INPTR BSTR, metricNames),
    237                                                  ComSafeArrayIn(IUnknown *, objects),
    238                                                  ULONG aPeriod, ULONG aCount)
     239STDMETHODIMP
     240PerformanceCollector::SetupMetrics (ComSafeArrayIn (INPTR BSTR, metricNames),
     241                                    ComSafeArrayIn (IUnknown *, objects),
     242                                    ULONG aPeriod, ULONG aCount)
    239243{
    240244    AutoCaller autoCaller (this);
    241245    CheckComRCReturnRC (autoCaller.rc());
    242246
    243     pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
     247    pm::Filter filter (ComSafeArrayInArg (metricNames),
     248                       ComSafeArrayInArg (objects));
    244249
    245250    AutoWriteLock alock (this);
    246251
    247252    BaseMetricList::iterator it;
    248     for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
     253    for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
    249254        if (filter.match((*it)->getObject(), (*it)->getName()))
    250255        {
     
    256261}
    257262
    258 STDMETHODIMP PerformanceCollector::EnableMetrics (ComSafeArrayIn(INPTR BSTR, metricNames),
    259                                                   ComSafeArrayIn(IUnknown *, objects))
     263STDMETHODIMP
     264PerformanceCollector::EnableMetrics (ComSafeArrayIn (INPTR BSTR, metricNames),
     265                                     ComSafeArrayIn (IUnknown *, objects))
    260266{
    261267    AutoCaller autoCaller (this);
    262268    CheckComRCReturnRC (autoCaller.rc());
    263269
    264     pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
     270    pm::Filter filter (ComSafeArrayInArg (metricNames),
     271                       ComSafeArrayInArg (objects));
     272
     273    /// @todo (r=dmik) why read lock below? individual elements get modified!
    265274
    266275    AutoReadLock alock (this); /* Need a read lock to access mBaseMetrics */
    267276
    268277    BaseMetricList::iterator it;
    269     for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
     278    for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
    270279        if (filter.match((*it)->getObject(), (*it)->getName()))
    271280            (*it)->enable();
     
    274283}
    275284
    276 STDMETHODIMP PerformanceCollector::DisableMetrics (ComSafeArrayIn(INPTR BSTR, metricNames),
    277                                                    ComSafeArrayIn(IUnknown *, objects))
     285STDMETHODIMP
     286PerformanceCollector::DisableMetrics (ComSafeArrayIn (INPTR BSTR, metricNames),
     287                                      ComSafeArrayIn (IUnknown *, objects))
    278288{
    279289    AutoCaller autoCaller (this);
    280290    CheckComRCReturnRC (autoCaller.rc());
    281291
    282     pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
     292    pm::Filter filter (ComSafeArrayInArg (metricNames),
     293                       ComSafeArrayInArg (objects));
     294
     295    /// @todo (r=dmik) why read lock below? individual elements get modified!
    283296
    284297    AutoReadLock alock (this);
    285298
    286299    BaseMetricList::iterator it;
    287     for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
     300    for (it = m.baseMetrics.begin(); it != m.baseMetrics.end(); ++it)
    288301        if (filter.match((*it)->getObject(), (*it)->getName()))
    289302            (*it)->disable();
     
    292305}
    293306
    294 STDMETHODIMP PerformanceCollector::QueryMetricsData (ComSafeArrayIn(INPTR BSTR, metricNames),
    295                                                      ComSafeArrayIn(IUnknown *, objects),
    296                                                      ComSafeArrayOut(BSTR, outMetricNames),
    297                                                      ComSafeArrayOut(IUnknown *, outObjects),
    298                                                      ComSafeArrayOut(ULONG, outDataIndices),
    299                                                      ComSafeArrayOut(ULONG, outDataLengths),
    300                                                      ComSafeArrayOut(LONG, outData))
     307STDMETHODIMP
     308PerformanceCollector::QueryMetricsData (ComSafeArrayIn (INPTR BSTR, metricNames),
     309                                        ComSafeArrayIn (IUnknown *, objects),
     310                                        ComSafeArrayOut (BSTR, outMetricNames),
     311                                        ComSafeArrayOut (IUnknown *, outObjects),
     312                                        ComSafeArrayOut (ULONG, outDataIndices),
     313                                        ComSafeArrayOut (ULONG, outDataLengths),
     314                                        ComSafeArrayOut (LONG, outData))
    301315{
    302316    AutoCaller autoCaller (this);
     
    309323    /* Let's compute the size of the resulting flat array */
    310324    size_t flatSize = 0, numberOfMetrics = 0;
    311     for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it)
     325    for (it = m.metrics.begin(); it != m.metrics.end(); ++it)
    312326    {
    313327        /* @todo Filtering goes here! */
     
    316330    }
    317331    size_t flatIndex = 0;
    318     com::SafeArray<BSTR> retNames(numberOfMetrics);
    319     com::SafeIfaceArray<IUnknown> retObjects(numberOfMetrics);
    320     com::SafeArray<ULONG> retIndices(numberOfMetrics);
    321     com::SafeArray<ULONG> retLengths(numberOfMetrics);
    322     com::SafeArray<LONG> retData(flatSize);
    323 
    324     for (it = m.mMetrics.begin(), i = 0; it != m.mMetrics.end(); ++it)
     332    com::SafeArray <BSTR> retNames (numberOfMetrics);
     333    com::SafeIfaceArray <IUnknown> retObjects (numberOfMetrics);
     334    com::SafeArray <ULONG> retIndices (numberOfMetrics);
     335    com::SafeArray <ULONG> retLengths (numberOfMetrics);
     336    com::SafeArray <LONG> retData (flatSize);
     337
     338    for (it = m.metrics.begin(), i = 0; it != m.metrics.end(); ++it)
    325339    {
    326340        /* @todo Filtering goes here! */
     
    331345        Bstr tmp((*it)->getName());
    332346        tmp.detachTo(&retNames[i]);
    333         (*it)->getObject().queryInterfaceTo(&retObjects[i]);
     347        (*it)->getObject().queryInterfaceTo (&retObjects[i]);
    334348        retLengths[i] = length;
    335349        retIndices[i] = flatIndex;
     
    338352    }
    339353
    340     retNames.detachTo(ComSafeArrayOutArg(outMetricNames));
    341     retObjects.detachTo(ComSafeArrayOutArg(outObjects));
    342     retIndices.detachTo(ComSafeArrayOutArg(outDataIndices));
    343     retLengths.detachTo(ComSafeArrayOutArg(outDataLengths));
    344     retData.detachTo(ComSafeArrayOutArg(outData));
     354    retNames.detachTo (ComSafeArrayOutArg (outMetricNames));
     355    retObjects.detachTo (ComSafeArrayOutArg (outObjects));
     356    retIndices.detachTo (ComSafeArrayOutArg (outDataIndices));
     357    retLengths.detachTo (ComSafeArrayOutArg (outDataLengths));
     358    retData.detachTo (ComSafeArrayOutArg (outData));
    345359    return S_OK;
    346360}
     
    351365void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric)
    352366{
     367    /// @todo (r=dmik) better always use AutoCaller unless you are 100% sure
     368    /// the object is not uninitialized while you are doing something here
     369
    353370    AutoWriteLock alock (this);
    354     m.mBaseMetrics.push_back (baseMetric);
     371    m.baseMetrics.push_back (baseMetric);
    355372}
    356373
    357374void PerformanceCollector::registerMetric (pm::Metric *metric)
    358375{
     376    /// @todo (r=dmik) better always use AutoCaller unless you are 100% sure
     377    /// the object is not uninitialized while you are doing something here
     378
    359379    AutoWriteLock alock (this);
    360     m.mMetrics.push_back (metric);
     380    m.metrics.push_back (metric);
    361381}
    362382
    363383void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr <IUnknown> &aObject)
    364384{
     385    /// @todo (r=dmik) better always use AutoCaller unless you are 100% sure
     386    /// the object is not uninitialized while you are doing something here
     387
    365388    AutoWriteLock alock (this);
    366     std::remove_if (m.mBaseMetrics.begin(), m.mBaseMetrics.end(),
     389    std::remove_if (m.baseMetrics.begin(), m.baseMetrics.end(),
    367390                    std::bind2nd (std::mem_fun (&pm::BaseMetric::associatedWith),
    368391                                  aObject));
     
    371394void PerformanceCollector::unregisterMetricsFor (const ComPtr <IUnknown> &aObject)
    372395{
     396    /// @todo (r=dmik) better always use AutoCaller unless you are 100% sure
     397    /// the object is not uninitialized while you are doing something here
     398
    373399    AutoWriteLock alock (this);
    374     std::remove_if (m.mMetrics.begin(), m.mMetrics.end(),
     400    std::remove_if (m.metrics.begin(), m.metrics.end(),
    375401                    std::bind2nd (std::mem_fun (&pm::Metric::associatedWith),
    376402                                  aObject));
     
    386412    AssertReturnVoid (pvUser != NULL);
    387413    PerformanceCollector *collector = static_cast <PerformanceCollector *> (pvUser);
    388     Assert(collector->mMagic == MAGIC);
     414    Assert (collector->mMagic == MAGIC);
    389415    if (collector->mMagic == MAGIC)
    390416    {
     
    398424
    399425    uint64_t timestamp = RTTimeMilliTS();
    400     std::for_each(m.mBaseMetrics.begin(), m.mBaseMetrics.end(),
    401                   std::bind2nd (std::mem_fun (&pm::BaseMetric::collectorBeat), timestamp));
     426    std::for_each (m.baseMetrics.begin(), m.baseMetrics.end(),
     427                   std::bind2nd (std::mem_fun (&pm::BaseMetric::collectorBeat),
     428                                 timestamp));
    402429}
    403430
     
    446473STDMETHODIMP PerformanceMetric::COMGETTER(MetricName) (BSTR *aMetricName)
    447474{
     475    /// @todo (r=dmik) why do all these getters not do AutoCaller and
     476    /// AutoReadLock? Is the underlying metric a constant object?
     477
    448478    Bstr tmp (mMetric->getName());
    449479    tmp.detachTo (aMetricName);
     
    471501STDMETHODIMP PerformanceMetric::COMGETTER(Unit) (BSTR *aUnit)
    472502{
    473     Bstr tmp(mMetric->getUnit());
     503    Bstr tmp (mMetric->getUnit());
    474504    tmp.detachTo(aUnit);
    475505    return S_OK;
  • trunk/src/VBox/Main/include/Performance.h

    r10753 r10770  
    2929#include <string>
    3030
    31 namespace pm {
     31namespace pm
     32{
    3233    /* CPU load is measured in 1/1000 of per cent. */
    3334    const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000);
     
    109110        bool             mEnabled;
    110111    };
    111    
     112
    112113    class HostCpuLoad : public BaseMetric
    113114    {
     
    127128        SubMetric *mIdle;
    128129    };
    129    
     130
    130131    class HostCpuLoadRaw : public HostCpuLoad
    131132    {
     
    155156        SubMetric *mMHz;
    156157    };
    157    
     158
    158159    class HostRamUsage : public BaseMetric
    159160    {
     
    172173        SubMetric *mAvailable;
    173174    };
    174    
     175
    175176    class MachineCpuLoad : public BaseMetric
    176177    {
     
    189190        SubMetric *mKernel;
    190191    };
    191    
     192
    192193    class MachineCpuLoadRaw : public MachineCpuLoad
    193194    {
     
    261262            }
    262263        }
    263    
     264
    264265        ~Metric()
    265266        {
     
    276277        unsigned long getLength() { return mAggregate ? 1 : mBaseMetric->getLength(); };
    277278        void query(unsigned long **data, unsigned long *count);
    278    
     279
    279280    private:
    280281        std::string mName;
  • trunk/src/VBox/Main/include/PerformanceImpl.h

    r10725 r10770  
    229229    // public methods for internal purposes only
    230230    // (ensure there is a caller and a read lock before calling them!)
    231     //
    232     pm::MetricFactory *getMetricFactory() { return m.mFactory; };
     231
     232    pm::MetricFactory *getMetricFactory() { return m.factory; };
    233233
    234234    // for VirtualBoxSupportErrorInfoImpl
     
    250250    unsigned int mMagic;
    251251
    252     struct Data {
    253         Data() : mFactory(0) {};
    254 
    255         BaseMetricList     mBaseMetrics;
    256         MetricList         mMetrics;
    257         PRTTIMER           mSampler;
    258         pm::MetricFactory *mFactory;
    259     } m;
     252    struct Data
     253    {
     254        Data() : factory(0) {};
     255
     256        BaseMetricList     baseMetrics;
     257        MetricList         metrics;
     258        PRTTIMER           sampler;
     259        pm::MetricFactory *factory;
     260    };
     261
     262    Data m;
    260263};
    261264
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