- Timestamp:
- Jul 21, 2008 9:02:08 AM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/PerformanceImpl.cpp
r10753 r10770 103 103 /* @todo Obviously other platforms must be added as well. */ 104 104 #ifdef RT_OS_SOLARIS 105 m. mFactory = new pm::MetricFactorySolaris();105 m.factory = new pm::MetricFactorySolaris(); 106 106 #endif 107 107 #ifdef RT_OS_LINUX 108 m. mFactory = new pm::MetricFactoryLinux();108 m.factory = new pm::MetricFactoryLinux(); 109 109 #endif 110 110 #ifdef RT_OS_WINDOWS 111 m. mFactory = new pm::MetricFactoryWin();111 m.factory = new pm::MetricFactoryWin(); 112 112 #endif 113 113 #ifdef RT_OS_OS2 114 m. mFactory = new pm::MetricFactoryOS2();114 m.factory = new pm::MetricFactoryOS2(); 115 115 #endif 116 116 #ifdef RT_OS_DARWIN 117 m. mFactory = new pm::MetricFactoryDarwin();117 m.factory = new pm::MetricFactoryDarwin(); 118 118 #endif 119 119 … … 122 122 123 123 /* 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, 125 125 &PerformanceCollector::staticSamplerCallback, this); 126 126 AssertMsgRC (vrc, ("Failed to create resource usage " … … 158 158 159 159 /* Destroy resource usage sampler */ 160 int vrc = RTTimerDestroy (m. mSampler);160 int vrc = RTTimerDestroy (m.sampler); 161 161 AssertMsgRC (vrc, ("Failed to destroy resource usage " 162 162 "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; 167 167 168 168 LogFlowThisFuncLeave(); … … 197 197 //////////////////////////////////////////////////////////////////////////////// 198 198 199 STDMETHODIMP PerformanceCollector::GetMetrics(ComSafeArrayIn(INPTR BSTR, metricNames), 200 ComSafeArrayIn(IUnknown *, objects), 201 ComSafeArrayOut(IPerformanceMetric *, outMetrics)) 199 STDMETHODIMP 200 PerformanceCollector::GetMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), 201 ComSafeArrayIn (IUnknown *, objects), 202 ComSafeArrayOut (IPerformanceMetric *, outMetrics)) 202 203 { 203 204 //LogFlowThisFunc (("mState=%d, mType=%d\n", mState, mType)); … … 208 209 CheckComRCReturnRC (autoCaller.rc()); 209 210 210 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 211 pm::Filter filter (ComSafeArrayInArg (metricNames), 212 ComSafeArrayInArg (objects)); 211 213 212 214 AutoReadLock alock (this); … … 214 216 MetricList filteredMetrics; 215 217 MetricList::iterator it; 216 for (it = m.m Metrics.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()); 221 223 int i = 0; 222 224 for (it = filteredMetrics.begin(); it != filteredMetrics.end(); ++it) 223 225 { 224 ComObjPtr <PerformanceMetric> metric;226 ComObjPtr <PerformanceMetric> metric; 225 227 rc = metric.createObject(); 226 228 if (SUCCEEDED (rc)) 227 229 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]); 231 234 } 232 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics));235 retMetrics.detachTo (ComSafeArrayOutArg(outMetrics)); 233 236 return rc; 234 237 } 235 238 236 STDMETHODIMP PerformanceCollector::SetupMetrics (ComSafeArrayIn(INPTR BSTR, metricNames), 237 ComSafeArrayIn(IUnknown *, objects), 238 ULONG aPeriod, ULONG aCount) 239 STDMETHODIMP 240 PerformanceCollector::SetupMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), 241 ComSafeArrayIn (IUnknown *, objects), 242 ULONG aPeriod, ULONG aCount) 239 243 { 240 244 AutoCaller autoCaller (this); 241 245 CheckComRCReturnRC (autoCaller.rc()); 242 246 243 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 247 pm::Filter filter (ComSafeArrayInArg (metricNames), 248 ComSafeArrayInArg (objects)); 244 249 245 250 AutoWriteLock alock (this); 246 251 247 252 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) 249 254 if (filter.match((*it)->getObject(), (*it)->getName())) 250 255 { … … 256 261 } 257 262 258 STDMETHODIMP PerformanceCollector::EnableMetrics (ComSafeArrayIn(INPTR BSTR, metricNames), 259 ComSafeArrayIn(IUnknown *, objects)) 263 STDMETHODIMP 264 PerformanceCollector::EnableMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), 265 ComSafeArrayIn (IUnknown *, objects)) 260 266 { 261 267 AutoCaller autoCaller (this); 262 268 CheckComRCReturnRC (autoCaller.rc()); 263 269 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! 265 274 266 275 AutoReadLock alock (this); /* Need a read lock to access mBaseMetrics */ 267 276 268 277 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) 270 279 if (filter.match((*it)->getObject(), (*it)->getName())) 271 280 (*it)->enable(); … … 274 283 } 275 284 276 STDMETHODIMP PerformanceCollector::DisableMetrics (ComSafeArrayIn(INPTR BSTR, metricNames), 277 ComSafeArrayIn(IUnknown *, objects)) 285 STDMETHODIMP 286 PerformanceCollector::DisableMetrics (ComSafeArrayIn (INPTR BSTR, metricNames), 287 ComSafeArrayIn (IUnknown *, objects)) 278 288 { 279 289 AutoCaller autoCaller (this); 280 290 CheckComRCReturnRC (autoCaller.rc()); 281 291 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! 283 296 284 297 AutoReadLock alock (this); 285 298 286 299 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) 288 301 if (filter.match((*it)->getObject(), (*it)->getName())) 289 302 (*it)->disable(); … … 292 305 } 293 306 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)) 307 STDMETHODIMP 308 PerformanceCollector::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)) 301 315 { 302 316 AutoCaller autoCaller (this); … … 309 323 /* Let's compute the size of the resulting flat array */ 310 324 size_t flatSize = 0, numberOfMetrics = 0; 311 for (it = m.m Metrics.begin(); it != m.mMetrics.end(); ++it)325 for (it = m.metrics.begin(); it != m.metrics.end(); ++it) 312 326 { 313 327 /* @todo Filtering goes here! */ … … 316 330 } 317 331 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.m Metrics.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) 325 339 { 326 340 /* @todo Filtering goes here! */ … … 331 345 Bstr tmp((*it)->getName()); 332 346 tmp.detachTo(&retNames[i]); 333 (*it)->getObject().queryInterfaceTo (&retObjects[i]);347 (*it)->getObject().queryInterfaceTo (&retObjects[i]); 334 348 retLengths[i] = length; 335 349 retIndices[i] = flatIndex; … … 338 352 } 339 353 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)); 345 359 return S_OK; 346 360 } … … 351 365 void PerformanceCollector::registerBaseMetric (pm::BaseMetric *baseMetric) 352 366 { 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 353 370 AutoWriteLock alock (this); 354 m. mBaseMetrics.push_back (baseMetric);371 m.baseMetrics.push_back (baseMetric); 355 372 } 356 373 357 374 void PerformanceCollector::registerMetric (pm::Metric *metric) 358 375 { 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 359 379 AutoWriteLock alock (this); 360 m.m Metrics.push_back (metric);380 m.metrics.push_back (metric); 361 381 } 362 382 363 383 void PerformanceCollector::unregisterBaseMetricsFor (const ComPtr <IUnknown> &aObject) 364 384 { 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 365 388 AutoWriteLock alock (this); 366 std::remove_if (m. mBaseMetrics.begin(), m.mBaseMetrics.end(),389 std::remove_if (m.baseMetrics.begin(), m.baseMetrics.end(), 367 390 std::bind2nd (std::mem_fun (&pm::BaseMetric::associatedWith), 368 391 aObject)); … … 371 394 void PerformanceCollector::unregisterMetricsFor (const ComPtr <IUnknown> &aObject) 372 395 { 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 373 399 AutoWriteLock alock (this); 374 std::remove_if (m.m Metrics.begin(), m.mMetrics.end(),400 std::remove_if (m.metrics.begin(), m.metrics.end(), 375 401 std::bind2nd (std::mem_fun (&pm::Metric::associatedWith), 376 402 aObject)); … … 386 412 AssertReturnVoid (pvUser != NULL); 387 413 PerformanceCollector *collector = static_cast <PerformanceCollector *> (pvUser); 388 Assert (collector->mMagic == MAGIC);414 Assert (collector->mMagic == MAGIC); 389 415 if (collector->mMagic == MAGIC) 390 416 { … … 398 424 399 425 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)); 402 429 } 403 430 … … 446 473 STDMETHODIMP PerformanceMetric::COMGETTER(MetricName) (BSTR *aMetricName) 447 474 { 475 /// @todo (r=dmik) why do all these getters not do AutoCaller and 476 /// AutoReadLock? Is the underlying metric a constant object? 477 448 478 Bstr tmp (mMetric->getName()); 449 479 tmp.detachTo (aMetricName); … … 471 501 STDMETHODIMP PerformanceMetric::COMGETTER(Unit) (BSTR *aUnit) 472 502 { 473 Bstr tmp (mMetric->getUnit());503 Bstr tmp (mMetric->getUnit()); 474 504 tmp.detachTo(aUnit); 475 505 return S_OK; -
trunk/src/VBox/Main/include/Performance.h
r10753 r10770 29 29 #include <string> 30 30 31 namespace pm { 31 namespace pm 32 { 32 33 /* CPU load is measured in 1/1000 of per cent. */ 33 34 const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000); … … 109 110 bool mEnabled; 110 111 }; 111 112 112 113 class HostCpuLoad : public BaseMetric 113 114 { … … 127 128 SubMetric *mIdle; 128 129 }; 129 130 130 131 class HostCpuLoadRaw : public HostCpuLoad 131 132 { … … 155 156 SubMetric *mMHz; 156 157 }; 157 158 158 159 class HostRamUsage : public BaseMetric 159 160 { … … 172 173 SubMetric *mAvailable; 173 174 }; 174 175 175 176 class MachineCpuLoad : public BaseMetric 176 177 { … … 189 190 SubMetric *mKernel; 190 191 }; 191 192 192 193 class MachineCpuLoadRaw : public MachineCpuLoad 193 194 { … … 261 262 } 262 263 } 263 264 264 265 ~Metric() 265 266 { … … 276 277 unsigned long getLength() { return mAggregate ? 1 : mBaseMetric->getLength(); }; 277 278 void query(unsigned long **data, unsigned long *count); 278 279 279 280 private: 280 281 std::string mName; -
trunk/src/VBox/Main/include/PerformanceImpl.h
r10725 r10770 229 229 // public methods for internal purposes only 230 230 // (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; }; 233 233 234 234 // for VirtualBoxSupportErrorInfoImpl … … 250 250 unsigned int mMagic; 251 251 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; 260 263 }; 261 264
Note:
See TracChangeset
for help on using the changeset viewer.