Changeset 12400 in vbox for trunk/src/VBox/Main/include
- Timestamp:
- Sep 11, 2008 10:34:58 AM (16 years ago)
- Location:
- trunk/src/VBox/Main/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/Performance.h
r11583 r12400 26 26 #include <VBox/com/defs.h> 27 27 #include <VBox/com/ptr.h> 28 #include <algorithm> 28 29 #include <list> 29 30 #include <string> 31 #include <vector> 30 32 31 33 namespace pm … … 65 67 66 68 /* 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 67 136 class CollectorHAL 68 137 { 69 138 public: 139 virtual int preCollect(const CollectorHints& hints) { return VINF_SUCCESS; } 70 140 virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle); 71 141 virtual int getHostCpuMHz(ULONG *mhz); … … 78 148 }; 79 149 150 extern CollectorHAL *createHAL(); 151 80 152 /* Base Metrics *********************************************************/ 81 153 class BaseMetric … … 86 158 87 159 virtual void init(ULONG period, ULONG length) = 0; 160 virtual void preCollect(CollectorHints& hints) = 0; 88 161 virtual void collect() = 0; 89 162 virtual const char *getUnit() = 0; … … 91 164 virtual ULONG getMaxValue() = 0; 92 165 93 voidcollectorBeat(uint64_t nowAt);166 bool collectorBeat(uint64_t nowAt); 94 167 95 168 void enable() { mEnabled = true; }; … … 137 210 : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {}; 138 211 212 void preCollect(CollectorHints& hints); 139 213 void collect(); 140 214 private: … … 151 225 152 226 void init(ULONG period, ULONG length); 227 void preCollect(CollectorHints& hints) {} 153 228 void collect(); 154 229 const char *getUnit() { return "MHz"; }; … … 166 241 167 242 void init(ULONG period, ULONG length); 243 void preCollect(CollectorHints& hints); 168 244 void collect(); 169 245 const char *getUnit() { return "kB"; }; … … 199 275 : MachineCpuLoad(hal, object, process, user, kernel), mHostTotalPrev(0), mProcessUserPrev(0), mProcessKernelPrev(0) {}; 200 276 277 void preCollect(CollectorHints& hints); 201 278 void collect(); 202 279 private: … … 213 290 214 291 void init(ULONG period, ULONG length); 292 void preCollect(CollectorHints& hints); 215 293 void collect(); 216 294 const char *getUnit() { return "kB"; }; … … 290 368 }; 291 369 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 *********************************************************/ 342 371 343 372 class Filter -
trunk/src/VBox/Main/include/PerformanceImpl.h
r11583 r12400 34 34 35 35 #include <list> 36 #include <set>36 //#include <set> 37 37 38 38 #include "Performance.h" … … 107 107 }; 108 108 109 110 #if 0111 class ATL_NO_VTABLE PerformanceData :112 public VirtualBoxBaseNEXT,113 public VirtualBoxSupportTranslation <PerformanceData>,114 public IPerformanceData115 {116 private:117 118 struct Data119 {120 /* Constructor. */121 Data() { }122 123 bool operator== (const Data &that) const124 {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_ISUPPORTS143 144 DECLARE_EMPTY_CTOR_DTOR (PerformanceData)145 146 HRESULT FinalConstruct();147 void FinalRelease();148 149 // public initializer/uninitializer for internal purposes only150 HRESULT init (cosnt BSTR aMetricName, IUnknown *anObject,151 ULONG *data, ULONG aLength);152 void uninit();153 154 // IPerformanceData properties155 STDMETHOD(COMGETTER(MetricName)) (BSTR *aMetricName);156 STDMETHOD(COMGETTER(Object)) (IUnknown **anObject);157 STDMETHOD(COMGETTER(Values)) (ComSafeArrayOut (LONG, values));158 159 // IPerformanceData methods160 161 // public methods only for internal purposes162 163 private:164 165 Bstr mMetricName;166 IUnknown *mObject;167 ULONG *mData;168 ULONG mLength;169 };170 #endif171 109 172 110 class ATL_NO_VTABLE PerformanceCollector : … … 232 170 // (ensure there is a caller and a read lock before calling them!) 233 171 234 pm:: MetricFactory *getMetricFactory() { return m.factory; };172 pm::CollectorHAL *getHAL() { return m.hal; }; 235 173 236 174 // for VirtualBoxSupportErrorInfoImpl … … 254 192 struct Data 255 193 { 256 Data() : factory(0) {};194 Data() : hal(0) {}; 257 195 258 196 BaseMetricList baseMetrics; 259 197 MetricList metrics; 260 198 RTTIMERLR sampler; 261 pm:: MetricFactory *factory;199 pm::CollectorHAL *hal; 262 200 }; 263 201
Note:
See TracChangeset
for help on using the changeset viewer.