VirtualBox

Changeset 10679 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jul 15, 2008 6:59:56 PM (16 years ago)
Author:
vboxsync
Message:

Filtering sketched. There is a crash in VirtualBox::uninit on Windows.

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

Legend:

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

    r10641 r10679  
    2222 */
    2323
     24#include <VBox/com/array.h>
    2425#include <VBox/com/ptr.h>
     26#include <VBox/com/string.h>
    2527#include <VBox/err.h>
    2628#include <iprt/string.h>
     
    219221}
    220222
     223void HostCpuMhz::init(unsigned long period, unsigned long length)
     224{
     225    mPeriod = period;
     226    mLength = length;
     227    mMHz->init(mLength);
     228}
     229
    221230void HostCpuMhz::collect()
    222231{
     
    224233    mHAL->getHostCpuMHz(&mhz);
    225234    mMHz->put(mhz);
     235}
     236
     237void HostRamUsage::init(unsigned long period, unsigned long length)
     238{
     239    mPeriod = period;
     240    mLength = length;
     241    mTotal->init(mLength);
     242    mUsed->init(mLength);
     243    mAvailable->init(mLength);
    226244}
    227245
     
    236254
    237255
     256
     257void MachineCpuLoad::init(unsigned long period, unsigned long length)
     258{
     259    mPeriod = period;
     260    mLength = length;
     261    mUser->init(mLength);
     262    mKernel->init(mLength);
     263}
     264
    238265void MachineCpuLoad::collect()
    239266{
     
    259286    mProcessUserPrev   = processUser;
    260287    mProcessKernelPrev = processKernel;
     288}
     289
     290void MachineRamUsage::init(unsigned long period, unsigned long length)
     291{
     292    mPeriod = period;
     293    mLength = length;
     294    mUsed->init(mLength);
    261295}
    262296
     
    361395}
    362396
     397Filter::Filter(ComSafeArrayIn(const BSTR, metricNames),
     398               ComSafeArrayIn(IUnknown *, objects))
     399{
     400    com::SafeIfaceArray <IUnknown> objectArray(ComSafeArrayInArg(objects));
     401    com::SafeArray <BSTR> nameArray(ComSafeArrayInArg(metricNames));
     402    for (size_t i = 0; i < objectArray.size(); ++i)
     403        processMetricList(std::string(com::Utf8Str(nameArray[i])), objectArray[i]);
     404}
     405
     406void Filter::processMetricList(const std::string &name, const IUnknown *object)
     407{
     408    std::string::size_type startPos = 0;
     409
     410    for (std::string::size_type pos = name.find(",");
     411         pos != std::string::npos;
     412         pos = name.find(",", startPos))
     413    {
     414        mElements.push_back(std::make_pair(object, name.substr(startPos, pos - startPos)));
     415        startPos = pos + 1;
     416    }
     417    mElements.push_back(std::make_pair(object, name.substr(startPos)));
     418}
     419
     420bool Filter::match(const IUnknown *object, const std::string &name) const
     421{
     422    return true;
     423}
  • trunk/src/VBox/Main/PerformanceImpl.cpp

    r10641 r10679  
    3939static Bstr gMetricNames[] =
    4040{
    41     "CPU/User:avg",
    42     "CPU/User:min",
    43     "CPU/User:max",
    44     "CPU/Kernel:avg",
    45     "CPU/Kernel:min",
    46     "CPU/Kernel:max",
    47     "CPU/Idle:avg",
    48     "CPU/Idle:min",
    49     "CPU/Idle:max",
     41    "CPU/Load/User:avg",
     42    "CPU/Load/User:min",
     43    "CPU/Load/User:max",
     44    "CPU/Load/Kernel:avg",
     45    "CPU/Load/Kernel:min",
     46    "CPU/Load/Kernel:max",
     47    "CPU/Load/Idle:avg",
     48    "CPU/Load/Idle:min",
     49    "CPU/Load/Idle:max",
    5050    "CPU/MHz:avg",
    5151    "CPU/MHz:min",
    5252    "CPU/MHz:max",
    53     "RAM/Total:avg",
    54     "RAM/Total:min",
    55     "RAM/Total:max",
    56     "RAM/Used:avg",
    57     "RAM/Used:min",
    58     "RAM/Used:max",
    59     "RAM/Free:avg",
    60     "RAM/Free:min",
    61     "RAM/Free:max",
     53    "RAM/Usage/Total:avg",
     54    "RAM/Usage/Total:min",
     55    "RAM/Usage/Total:max",
     56    "RAM/Usage/Used:avg",
     57    "RAM/Usage/Used:min",
     58    "RAM/Usage/Used:max",
     59    "RAM/Usage/Free:avg",
     60    "RAM/Usage/Free:min",
     61    "RAM/Usage/Free:max",
    6262};
    6363
     
    6969////////////////////////////////////////////////////////////////////////////////
    7070
    71 PerformanceCollector::PerformanceCollector() : mFactory(0) {}
     71PerformanceCollector::PerformanceCollector() {}
    7272
    7373PerformanceCollector::~PerformanceCollector() {}
     
    102102
    103103    /* @todo Obviously other platforms must be added as well. */
    104     mFactory = new pm::MetricFactoryLinux();
     104    m.mFactory = new pm::MetricFactoryLinux();
    105105    /* Start resource usage sampler */
    106106
    107     int vrc = RTTimerCreate (&mSampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,
     107    int vrc = RTTimerCreate (&m.mSampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,
    108108                             &PerformanceCollector::staticSamplerCallback, this);
    109109    AssertMsgRC (vrc, ("Failed to create resource usage "
     
    139139
    140140    /* Destroy resource usage sampler */
    141     int vrc = RTTimerDestroy (mSampler);
     141    int vrc = RTTimerDestroy (m.mSampler);
    142142    AssertMsgRC (vrc, ("Failed to destroy resource usage "
    143143                       "sampling timer (%Rra)\n", vrc));
    144     mSampler = NULL;
    145 
    146     delete mFactory;
    147     mFactory = NULL;
     144    m.mSampler = NULL;
     145
     146    delete m.mFactory;
     147    m.mFactory = NULL;
    148148
    149149    LogFlowThisFuncLeave();
     
    194194                                                 ULONG aPeriod, ULONG aCount)
    195195{
    196 #if 0
    197196    pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects));
    198197
    199     std::list<pm::Metric*>::iterator it;
    200     for (it = mMetrics.begin(); it != mMetrics.end(); ++it)
    201         if (filter.match(*it))
     198    BaseMetricList::iterator it;
     199    for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it)
     200        if (filter.match((*it)->getObject(), (*it)->getName()))
    202201            (*it)->init(aPeriod, aCount);
    203 #endif
    204     return E_NOTIMPL;
     202
     203    return S_OK;
    205204}
    206205
     
    231230
    232231    int i;
    233     std::list<pm::Metric*>::const_iterator it;
     232    MetricList::const_iterator it;
    234233    /* Let's compute the size of the resulting flat array */
    235234    size_t flatSize = 0, numberOfMetrics = 0;
    236     for (it = mMetrics.begin(); it != mMetrics.end(); ++it)
     235    for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it)
    237236    {
    238237        /* @todo Filtering goes here! */
     
    246245    com::SafeArray<ULONG> retLengths(numberOfMetrics);
    247246    com::SafeArray<LONG> retData(flatSize);
    248     for (it = mMetrics.begin(), i = 0; it != mMetrics.end(); ++it)
     247    for (it = m.mMetrics.begin(), i = 0; it != m.mMetrics.end(); ++it)
    249248    {
    250249        /* @todo Filtering goes here! */
     
    274273void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric)
    275274{
    276     mBaseMetrics.push_back (baseMetric);
     275    m.mBaseMetrics.push_back (baseMetric);
    277276}
    278277
    279278void PerformanceCollector::registerMetric (pm::Metric *metric)
    280279{
    281     mMetrics.push_back (metric);
     280    m.mMetrics.push_back (metric);
    282281}
    283282
    284283void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr <IUnknown> &aObject)
    285284{
    286     std::remove_if (mBaseMetrics.begin(), mBaseMetrics.end(),
     285    std::remove_if (m.mBaseMetrics.begin(), m.mBaseMetrics.end(),
    287286                    std::bind2nd (std::mem_fun (&pm::BaseMetric::associatedWith),
    288287                                  aObject));
     
    291290void PerformanceCollector::unregisterMetricsFor (const ComPtr <IUnknown> &aObject)
    292291{
    293     std::remove_if (mMetrics.begin(), mMetrics.end(),
     292    std::remove_if (m.mMetrics.begin(), m.mMetrics.end(),
    294293                    std::bind2nd (std::mem_fun (&pm::Metric::associatedWith),
    295294                                  aObject));
     
    311310}
    312311
    313 #if 0
    314 PerformanceData::PerformanceData()
    315 {
    316 }
    317 
    318 PerformanceData::~PerformanceData()
    319 {
    320 }
    321 
    322 HRESULT PerformanceData::FinalConstruct()
    323 {
    324     LogFlowThisFunc (("\n"));
    325 
    326     return S_OK;
    327 }
    328 
    329 void PerformanceData::FinalRelease()
    330 {
    331     LogFlowThisFunc (("\n"));
    332 
    333     uninit ();
    334 }
    335 
    336 HRESULT PerformanceData::init (const char *aMetricName, IUnknown *anObject,
    337                                unsigned long *data, unsigned long aLength)
    338 {
    339     mMetricName = aMetricName;
    340     mObject = anObject;
    341     mData = data;
    342     mLength = aLength;
    343     return S_OK;
    344 }
    345 
    346 void PerformanceData::uninit()
    347 {
    348     RTMemFree(mData);
    349     mData = 0;
    350     mLength = 0;
    351 }
    352 
    353 STDMETHODIMP PerformanceData::COMGETTER(MetricName) (BSTR *aMetricName)
    354 {
    355     Bstr tmp(mMetricName);
    356     tmp.detachTo(aMetricName);
    357     return S_OK;
    358 }
    359 
    360 STDMETHODIMP PerformanceData::COMGETTER(Object) (IUnknown **anObject)
    361 {
    362     *anObject = mObject;
    363     return S_OK;
    364 }
    365 
    366 STDMETHODIMP PerformanceData::COMGETTER(Values) (ComSafeArrayOut (LONG, values))
    367 {
    368     SafeArray <LONG> ret (mLength);
    369     for (size_t i = 0; i < mLength; ++ i)
    370         ret[i] = mData[i];
    371 
    372     ret.detachTo(ComSafeArrayOutArg(values));
    373     return S_OK;
    374 }
    375 #endif
    376 
    377312////////////////////////////////////////////////////////////////////////////////
    378313// PerformanceMetric class
  • trunk/src/VBox/Main/include/Performance.h

    r10641 r10679  
    2525#include <iprt/types.h>
    2626#include <VBox/com/defs.h>
     27#include <list>
    2728#include <string>
    2829
     
    9394    {
    9495    public:
    95         BaseMetric(CollectorHAL *hal, IUnknown *object) : mLength(0), mHAL(hal), mObject(object) {};
    96 
     96        BaseMetric(CollectorHAL *hal, const char *name, IUnknown *object)
     97            : mHAL(hal), mLength(0), mName(name), mObject(object) {};
     98
     99        virtual void init(unsigned long period, unsigned long length) = 0;
    97100        virtual void collect() = 0;
    98101        virtual const char *getUnit() = 0;
     
    102105        unsigned long getPeriod() { return mPeriod; };
    103106        unsigned long getLength() { return mLength; };
     107        const char *getName() { return mName; };
    104108        IUnknown *getObject() { return mObject; };
    105109        bool associatedWith(IUnknown *object) { return mObject == object; };
    106110
    107111    protected:
     112        CollectorHAL *mHAL;
    108113        unsigned long mPeriod;
    109114        unsigned long mLength;
    110         CollectorHAL *mHAL;
     115        const char   *mName;
    111116        IUnknown     *mObject;
    112117    };
     
    116121    public:
    117122        HostCpuLoad(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
    118         : BaseMetric(hal, object), mUser(user), mKernel(kernel), mIdle(idle) {};
     123        : BaseMetric(hal, "CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {};
    119124        void init(unsigned long period, unsigned long length);
    120125
     
    135140        HostCpuLoadRaw(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)
    136141        : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {};
    137         void init(unsigned long period, unsigned long length);
    138142
    139143        void collect();
     
    148152    public:
    149153        HostCpuMhz(CollectorHAL *hal, IUnknown *object, SubMetric *mhz)
    150         : BaseMetric(hal, object), mMHz(mhz) {};
    151 
     154        : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {};
     155
     156        void init(unsigned long period, unsigned long length);
    152157        void collect();
    153158        const char *getUnit() { return "MHz"; };
     
    162167    public:
    163168        HostRamUsage(CollectorHAL *hal, IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available)
    164         : BaseMetric(hal, object), mTotal(total), mUsed(used), mAvailable(available) {};
    165 
     169        : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mUsed(used), mAvailable(available) {};
     170
     171        void init(unsigned long period, unsigned long length);
    166172        void collect();
    167173        const char *getUnit() { return "kB"; };
     
    178184    public:
    179185        MachineCpuLoad(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)
    180         : BaseMetric(hal, object), mProcess(process), mUser(user), mKernel(kernel) {};
    181 
     186        : BaseMetric(hal, "CPU/Load", object), mProcess(process), mUser(user), mKernel(kernel) {};
     187
     188        void init(unsigned long period, unsigned long length);
    182189        void collect();
    183190        const char *getUnit() { return "%"; };
     
    207214    public:
    208215        MachineRamUsage(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *used)
    209         : BaseMetric(hal, object), mProcess(process), mUsed(used) {};
    210 
     216        : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {};
     217
     218        void init(unsigned long period, unsigned long length);
    211219        void collect();
    212220        const char *getUnit() { return "kB"; };
     
    307315        virtual BaseMetric   *createMachineCpuLoad(IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel);
    308316    };
     317
     318    class Filter
     319    {
     320    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;
     326        std::list<FilterElement> mElements;
     327
     328        void processMetricList(const std::string &name, const IUnknown *object);
     329    };
    309330}
    310331
  • trunk/src/VBox/Main/include/PerformanceImpl.h

    r10641 r10679  
    3535
    3636#include <list>
     37#include <set>
    3738
    3839#include "Performance.h"
     
    229230    // (ensure there is a caller and a read lock before calling them!)
    230231    //
    231     pm::MetricFactory *getMetricFactory() { return mFactory; };
     232    pm::MetricFactory *getMetricFactory() { return m.mFactory; };
    232233
    233234    // for VirtualBoxSupportErrorInfoImpl
     
    239240    void samplerCallback();
    240241
    241     std::list<pm::BaseMetric*> mBaseMetrics;
    242     std::list<pm::Metric*>     mMetrics;
    243     PRTTIMER                   mSampler;
    244     pm::MetricFactory         *mFactory;
     242    typedef std::list<pm::Metric*> MetricList;
     243    typedef std::list<pm::BaseMetric*> BaseMetricList;
     244
     245    struct Data {
     246        Data() : mFactory(0) {};
     247
     248        BaseMetricList     mBaseMetrics;
     249        MetricList         mMetrics;
     250        PRTTIMER           mSampler;
     251        pm::MetricFactory *mFactory;
     252    } m;
    245253};
    246254
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r10595 r10679  
    921921#if 1
    922922    do {
    923         Bstr metricNames[] = { L"CPU/User:avg,CPU/System:avg,CPU/Idle:avg" };
     923        Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg" };
    924924        com::SafeArray<BSTR> metrics (1);
    925925        metricNames[0].cloneTo (&metrics [0]);
     
    954954            for (unsigned j = 0; j < retLengths[i]; j++)
    955955            {
    956                 printf(" %d\n", retData[retIndices[i] + j]);
     956                printf(" %d", retData[retIndices[i] + j]);
    957957            }
     958            printf("\n");
    958959        }
    959960    } while (0);
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