Changeset 10679 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jul 15, 2008 6:59:56 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Performance.cpp
r10641 r10679 22 22 */ 23 23 24 #include <VBox/com/array.h> 24 25 #include <VBox/com/ptr.h> 26 #include <VBox/com/string.h> 25 27 #include <VBox/err.h> 26 28 #include <iprt/string.h> … … 219 221 } 220 222 223 void HostCpuMhz::init(unsigned long period, unsigned long length) 224 { 225 mPeriod = period; 226 mLength = length; 227 mMHz->init(mLength); 228 } 229 221 230 void HostCpuMhz::collect() 222 231 { … … 224 233 mHAL->getHostCpuMHz(&mhz); 225 234 mMHz->put(mhz); 235 } 236 237 void 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); 226 244 } 227 245 … … 236 254 237 255 256 257 void 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 238 265 void MachineCpuLoad::collect() 239 266 { … … 259 286 mProcessUserPrev = processUser; 260 287 mProcessKernelPrev = processKernel; 288 } 289 290 void MachineRamUsage::init(unsigned long period, unsigned long length) 291 { 292 mPeriod = period; 293 mLength = length; 294 mUsed->init(mLength); 261 295 } 262 296 … … 361 395 } 362 396 397 Filter::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 406 void 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 420 bool Filter::match(const IUnknown *object, const std::string &name) const 421 { 422 return true; 423 } -
trunk/src/VBox/Main/PerformanceImpl.cpp
r10641 r10679 39 39 static Bstr gMetricNames[] = 40 40 { 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", 50 50 "CPU/MHz:avg", 51 51 "CPU/MHz:min", 52 52 "CPU/MHz:max", 53 "RAM/ Total:avg",54 "RAM/ Total:min",55 "RAM/ Total:max",56 "RAM/Us ed:avg",57 "RAM/Us ed:min",58 "RAM/Us ed: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", 62 62 }; 63 63 … … 69 69 //////////////////////////////////////////////////////////////////////////////// 70 70 71 PerformanceCollector::PerformanceCollector() : mFactory(0){}71 PerformanceCollector::PerformanceCollector() {} 72 72 73 73 PerformanceCollector::~PerformanceCollector() {} … … 102 102 103 103 /* @todo Obviously other platforms must be added as well. */ 104 m Factory = new pm::MetricFactoryLinux();104 m.mFactory = new pm::MetricFactoryLinux(); 105 105 /* Start resource usage sampler */ 106 106 107 int vrc = RTTimerCreate (&m Sampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL,107 int vrc = RTTimerCreate (&m.mSampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL, 108 108 &PerformanceCollector::staticSamplerCallback, this); 109 109 AssertMsgRC (vrc, ("Failed to create resource usage " … … 139 139 140 140 /* Destroy resource usage sampler */ 141 int vrc = RTTimerDestroy (m Sampler);141 int vrc = RTTimerDestroy (m.mSampler); 142 142 AssertMsgRC (vrc, ("Failed to destroy resource usage " 143 143 "sampling timer (%Rra)\n", vrc)); 144 m Sampler = NULL;145 146 delete m Factory;147 m Factory = NULL;144 m.mSampler = NULL; 145 146 delete m.mFactory; 147 m.mFactory = NULL; 148 148 149 149 LogFlowThisFuncLeave(); … … 194 194 ULONG aPeriod, ULONG aCount) 195 195 { 196 #if 0197 196 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 198 197 199 std::list<pm::Metric*>::iterator it;200 for (it = m Metrics.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())) 202 201 (*it)->init(aPeriod, aCount); 203 #endif 204 return E_NOTIMPL;202 203 return S_OK; 205 204 } 206 205 … … 231 230 232 231 int i; 233 std::list<pm::Metric*>::const_iterator it;232 MetricList::const_iterator it; 234 233 /* Let's compute the size of the resulting flat array */ 235 234 size_t flatSize = 0, numberOfMetrics = 0; 236 for (it = m Metrics.begin(); it !=mMetrics.end(); ++it)235 for (it = m.mMetrics.begin(); it != m.mMetrics.end(); ++it) 237 236 { 238 237 /* @todo Filtering goes here! */ … … 246 245 com::SafeArray<ULONG> retLengths(numberOfMetrics); 247 246 com::SafeArray<LONG> retData(flatSize); 248 for (it = m Metrics.begin(), i = 0; it !=mMetrics.end(); ++it)247 for (it = m.mMetrics.begin(), i = 0; it != m.mMetrics.end(); ++it) 249 248 { 250 249 /* @todo Filtering goes here! */ … … 274 273 void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric) 275 274 { 276 m BaseMetrics.push_back (baseMetric);275 m.mBaseMetrics.push_back (baseMetric); 277 276 } 278 277 279 278 void PerformanceCollector::registerMetric (pm::Metric *metric) 280 279 { 281 m Metrics.push_back (metric);280 m.mMetrics.push_back (metric); 282 281 } 283 282 284 283 void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr <IUnknown> &aObject) 285 284 { 286 std::remove_if (m BaseMetrics.begin(),mBaseMetrics.end(),285 std::remove_if (m.mBaseMetrics.begin(), m.mBaseMetrics.end(), 287 286 std::bind2nd (std::mem_fun (&pm::BaseMetric::associatedWith), 288 287 aObject)); … … 291 290 void PerformanceCollector::unregisterMetricsFor (const ComPtr <IUnknown> &aObject) 292 291 { 293 std::remove_if (m Metrics.begin(),mMetrics.end(),292 std::remove_if (m.mMetrics.begin(), m.mMetrics.end(), 294 293 std::bind2nd (std::mem_fun (&pm::Metric::associatedWith), 295 294 aObject)); … … 311 310 } 312 311 313 #if 0314 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 #endif376 377 312 //////////////////////////////////////////////////////////////////////////////// 378 313 // PerformanceMetric class -
trunk/src/VBox/Main/include/Performance.h
r10641 r10679 25 25 #include <iprt/types.h> 26 26 #include <VBox/com/defs.h> 27 #include <list> 27 28 #include <string> 28 29 … … 93 94 { 94 95 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; 97 100 virtual void collect() = 0; 98 101 virtual const char *getUnit() = 0; … … 102 105 unsigned long getPeriod() { return mPeriod; }; 103 106 unsigned long getLength() { return mLength; }; 107 const char *getName() { return mName; }; 104 108 IUnknown *getObject() { return mObject; }; 105 109 bool associatedWith(IUnknown *object) { return mObject == object; }; 106 110 107 111 protected: 112 CollectorHAL *mHAL; 108 113 unsigned long mPeriod; 109 114 unsigned long mLength; 110 CollectorHAL *mHAL;115 const char *mName; 111 116 IUnknown *mObject; 112 117 }; … … 116 121 public: 117 122 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) {}; 119 124 void init(unsigned long period, unsigned long length); 120 125 … … 135 140 HostCpuLoadRaw(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle) 136 141 : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {}; 137 void init(unsigned long period, unsigned long length);138 142 139 143 void collect(); … … 148 152 public: 149 153 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); 152 157 void collect(); 153 158 const char *getUnit() { return "MHz"; }; … … 162 167 public: 163 168 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); 166 172 void collect(); 167 173 const char *getUnit() { return "kB"; }; … … 178 184 public: 179 185 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); 182 189 void collect(); 183 190 const char *getUnit() { return "%"; }; … … 207 214 public: 208 215 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); 211 219 void collect(); 212 220 const char *getUnit() { return "kB"; }; … … 307 315 virtual BaseMetric *createMachineCpuLoad(IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel); 308 316 }; 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 }; 309 330 } 310 331 -
trunk/src/VBox/Main/include/PerformanceImpl.h
r10641 r10679 35 35 36 36 #include <list> 37 #include <set> 37 38 38 39 #include "Performance.h" … … 229 230 // (ensure there is a caller and a read lock before calling them!) 230 231 // 231 pm::MetricFactory *getMetricFactory() { return m Factory; };232 pm::MetricFactory *getMetricFactory() { return m.mFactory; }; 232 233 233 234 // for VirtualBoxSupportErrorInfoImpl … … 239 240 void samplerCallback(); 240 241 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; 245 253 }; 246 254 -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r10595 r10679 921 921 #if 1 922 922 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" }; 924 924 com::SafeArray<BSTR> metrics (1); 925 925 metricNames[0].cloneTo (&metrics [0]); … … 954 954 for (unsigned j = 0; j < retLengths[i]; j++) 955 955 { 956 printf(" %d \n", retData[retIndices[i] + j]);956 printf(" %d", retData[retIndices[i] + j]); 957 957 } 958 printf("\n"); 958 959 } 959 960 } while (0);
Note:
See TracChangeset
for help on using the changeset viewer.