VirtualBox

Changeset 12400 in vbox for trunk/src/VBox/Main/include


Ignore:
Timestamp:
Sep 11, 2008 10:34:58 AM (16 years ago)
Author:
vboxsync
Message:

PerfAPI: Improved Win collector. More realistic performance test. No factories.

Location:
trunk/src/VBox/Main/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/Performance.h

    r11583 r12400  
    2626#include <VBox/com/defs.h>
    2727#include <VBox/com/ptr.h>
     28#include <algorithm>
    2829#include <list>
    2930#include <string>
     31#include <vector>
    3032
    3133namespace pm
     
    6567
    6668    /* Collector Hardware Abstraction Layer *********************************/
     69    enum {
     70        COLLECT_NONE      = 0x0,
     71        COLLECT_CPU_LOAD  = 0x1,
     72        COLLECT_RAM_USAGE = 0x2
     73    };
     74    typedef int HintFlags;
     75    typedef std::pair<RTPROCESS, HintFlags> ProcessFlagsPair;
     76
     77    inline bool processEqual(ProcessFlagsPair pair, RTPROCESS process)
     78    {
     79        return pair.first == process;
     80    }
     81
     82    class CollectorHints
     83    {
     84        typedef std::list<ProcessFlagsPair> ProcessList;
     85
     86        HintFlags   mHostFlags;
     87        ProcessList mProcesses;
     88
     89        ProcessFlagsPair& findProcess(RTPROCESS process)
     90        {
     91            ProcessList::iterator it;
     92
     93            it = std::find_if(mProcesses.begin(),
     94                              mProcesses.end(),
     95                              std::bind2nd(std::ptr_fun(processEqual), process));
     96
     97            if (it != mProcesses.end())
     98                return *it;
     99
     100            /* Not found -- add new */
     101            mProcesses.push_back(ProcessFlagsPair(process, COLLECT_NONE));
     102            return mProcesses.back();
     103        }
     104
     105    public:
     106        CollectorHints() : mHostFlags(COLLECT_NONE) {}
     107        void collectHostCpuLoad() { mHostFlags |= COLLECT_CPU_LOAD; }
     108        void collectHostRamUsage() { mHostFlags |= COLLECT_RAM_USAGE; }
     109        void collectProcessCpuLoad(RTPROCESS process)
     110        {
     111            findProcess(process).second |= COLLECT_CPU_LOAD;
     112        }
     113        void collectProcessRamUsage(RTPROCESS process)
     114        {
     115            findProcess(process).second |= COLLECT_RAM_USAGE;
     116        }
     117        bool isHostCpuLoadCollected() { return (mHostFlags & COLLECT_CPU_LOAD) != 0; }
     118        bool isHostRamUsageCollected() { return (mHostFlags & COLLECT_RAM_USAGE) != 0; }
     119        bool isProcessCpuLoadCollected(RTPROCESS process)
     120        {
     121            return (findProcess(process).second & COLLECT_CPU_LOAD) != 0;
     122        }
     123        bool isProcessRamUsageCollected(RTPROCESS process)
     124        {
     125            return (findProcess(process).second & COLLECT_RAM_USAGE) != 0;
     126        }
     127        void getProcesses(std::vector<RTPROCESS>& processes) const
     128        {
     129            processes.clear();
     130            processes.reserve(mProcesses.size());
     131            for (ProcessList::const_iterator it = mProcesses.begin(); it != mProcesses.end(); it++)
     132                processes.push_back(it->first);
     133        }
     134    };
     135
    67136    class CollectorHAL
    68137    {
    69138    public:
     139        virtual int preCollect(const CollectorHints& hints) { return VINF_SUCCESS; }
    70140        virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
    71141        virtual int getHostCpuMHz(ULONG *mhz);
     
    78148    };
    79149
     150    extern CollectorHAL *createHAL();
     151
    80152    /* Base Metrics *********************************************************/
    81153    class BaseMetric
     
    86158
    87159        virtual void init(ULONG period, ULONG length) = 0;
     160        virtual void preCollect(CollectorHints& hints) = 0;
    88161        virtual void collect() = 0;
    89162        virtual const char *getUnit() = 0;
     
    91164        virtual ULONG getMaxValue() = 0;
    92165
    93         void collectorBeat(uint64_t nowAt);
     166        bool collectorBeat(uint64_t nowAt);
    94167
    95168        void enable() { mEnabled = true; };
     
    137210        : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {};
    138211
     212        void preCollect(CollectorHints& hints);
    139213        void collect();
    140214    private:
     
    151225
    152226        void init(ULONG period, ULONG length);
     227        void preCollect(CollectorHints& hints) {}
    153228        void collect();
    154229        const char *getUnit() { return "MHz"; };
     
    166241
    167242        void init(ULONG period, ULONG length);
     243        void preCollect(CollectorHints& hints);
    168244        void collect();
    169245        const char *getUnit() { return "kB"; };
     
    199275        : MachineCpuLoad(hal, object, process, user, kernel), mHostTotalPrev(0), mProcessUserPrev(0), mProcessKernelPrev(0) {};
    200276
     277        void preCollect(CollectorHints& hints);
    201278        void collect();
    202279    private:
     
    213290
    214291        void init(ULONG period, ULONG length);
     292        void preCollect(CollectorHints& hints);
    215293        void collect();
    216294        const char *getUnit() { return "kB"; };
     
    290368    };
    291369
    292     /* Metric Factories *****************************************************/
    293     class MetricFactory
    294     {
    295     public:
    296         MetricFactory() : mHAL(0) {};
    297         ~MetricFactory() { delete mHAL; };
    298 
    299         virtual BaseMetric   *createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle);
    300         virtual BaseMetric   *createHostCpuMHz(ComPtr<IUnknown> object, SubMetric *mhz);
    301         virtual BaseMetric   *createHostRamUsage(ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available);
    302         virtual BaseMetric   *createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel);
    303         virtual BaseMetric   *createMachineRamUsage(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used);
    304     protected:
    305         CollectorHAL *mHAL;
    306     };
    307 
    308     class MetricFactorySolaris : public MetricFactory
    309     {
    310     public:
    311         MetricFactorySolaris();
    312         // Nothing else to do here (yet)
    313     };
    314 
    315     class MetricFactoryLinux : public MetricFactory
    316     {
    317     public:
    318         MetricFactoryLinux();
    319         // Nothing else to do here (yet)
    320     };
    321 
    322     class MetricFactoryWin : public MetricFactory
    323     {
    324     public:
    325         MetricFactoryWin();
    326         // Nothing else to do here (yet)
    327     };
    328 
    329     class MetricFactoryOS2 : public MetricFactory
    330     {
    331     public:
    332         MetricFactoryOS2();
    333         // Nothing else to do here (yet)
    334     };
    335 
    336     class MetricFactoryDarwin : public MetricFactory
    337     {
    338     public:
    339         MetricFactoryDarwin();
    340         // Nothing else to do here (yet)
    341     };
     370    /* Filter Class *********************************************************/
    342371
    343372    class Filter
  • trunk/src/VBox/Main/include/PerformanceImpl.h

    r11583 r12400  
    3434
    3535#include <list>
    36 #include <set>
     36//#include <set>
    3737
    3838#include "Performance.h"
     
    107107};
    108108
    109 
    110 #if 0
    111 class ATL_NO_VTABLE PerformanceData :
    112     public VirtualBoxBaseNEXT,
    113     public VirtualBoxSupportTranslation <PerformanceData>,
    114     public IPerformanceData
    115 {
    116 private:
    117 
    118     struct Data
    119     {
    120         /* Constructor. */
    121         Data() { }
    122 
    123         bool operator== (const Data &that) const
    124         {
    125             return this == &that;
    126         }
    127     };
    128 
    129 public:
    130 
    131     VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (PerformanceData)
    132 
    133     DECLARE_NOT_AGGREGATABLE (PerformanceData)
    134 
    135     DECLARE_PROTECT_FINAL_CONSTRUCT()
    136 
    137     BEGIN_COM_MAP(PerformanceData)
    138         COM_INTERFACE_ENTRY (ISupportErrorInfo)
    139         COM_INTERFACE_ENTRY (IPerformanceData)
    140     END_COM_MAP()
    141 
    142     NS_DECL_ISUPPORTS
    143 
    144     DECLARE_EMPTY_CTOR_DTOR (PerformanceData)
    145 
    146     HRESULT FinalConstruct();
    147     void FinalRelease();
    148 
    149     // public initializer/uninitializer for internal purposes only
    150     HRESULT init (cosnt BSTR aMetricName, IUnknown *anObject,
    151                   ULONG *data, ULONG aLength);
    152     void uninit();
    153 
    154     // IPerformanceData properties
    155     STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);
    156     STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);
    157     STDMETHOD(COMGETTER(Values)) (ComSafeArrayOut (LONG, values));
    158 
    159     // IPerformanceData methods
    160 
    161     // public methods only for internal purposes
    162 
    163 private:
    164 
    165     Bstr mMetricName;
    166     IUnknown *mObject;
    167     ULONG *mData;
    168     ULONG mLength;
    169 };
    170 #endif
    171109
    172110class ATL_NO_VTABLE PerformanceCollector :
     
    232170    // (ensure there is a caller and a read lock before calling them!)
    233171
    234     pm::MetricFactory *getMetricFactory() { return m.factory; };
     172    pm::CollectorHAL *getHAL() { return m.hal; };
    235173
    236174    // for VirtualBoxSupportErrorInfoImpl
     
    254192    struct Data
    255193    {
    256         Data() : factory(0) {};
     194        Data() : hal(0) {};
    257195
    258196        BaseMetricList     baseMetrics;
    259197        MetricList         metrics;
    260198        RTTIMERLR          sampler;
    261         pm::MetricFactory *factory;
     199        pm::CollectorHAL  *hal;
    262200    };
    263201
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