Changeset 10713 in vbox
- Timestamp:
- Jul 16, 2008 8:28:43 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r10595 r10713 2696 2696 pm::MetricFactory *metricFactory = aCollector->getMetricFactory(); 2697 2697 /* Create sub metrics */ 2698 pm::SubMetric *cpuLoadUser = new pm::SubMetric ("CPU/Load/User");2698 pm::SubMetric *cpuLoadUser = new pm::SubMetric ("CPU/Load/User"); 2699 2699 pm::SubMetric *cpuLoadKernel = new pm::SubMetric ("CPU/Load/Kernel"); 2700 pm::SubMetric *cpuLoadIdle = new pm::SubMetric ("CPU/Load/Idle"); 2700 pm::SubMetric *cpuLoadIdle = new pm::SubMetric ("CPU/Load/Idle"); 2701 pm::SubMetric *ramUsageTotal = new pm::SubMetric ("RAM/Usage/Total"); 2702 pm::SubMetric *ramUsageUsed = new pm::SubMetric ("RAM/Usage/Used"); 2703 pm::SubMetric *ramUsageFree = new pm::SubMetric ("RAM/Usage/Free"); 2701 2704 /* Create and register base metrics */ 2702 2705 IUnknown *objptr; … … 2707 2710 cpuLoadIdle); 2708 2711 aCollector->registerBaseMetric (cpuLoad); 2712 pm::BaseMetric *ramUsage = 2713 metricFactory->createHostCpuLoad (objptr, ramUsageTotal, ramUsageUsed, 2714 ramUsageFree); 2715 aCollector->registerBaseMetric (ramUsage); 2716 2709 2717 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser, 0)); 2710 2718 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser, … … 2714 2722 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser, 2715 2723 new pm::AggregateMax())); 2724 2716 2725 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel, 0)); 2717 2726 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel, … … 2721 2730 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel, 2722 2731 new pm::AggregateMax())); 2732 2723 2733 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle, 0)); 2724 2734 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle, … … 2728 2738 aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle, 2729 2739 new pm::AggregateMax())); 2740 2741 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 0)); 2742 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 2743 new pm::AggregateAvg())); 2744 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 2745 new pm::AggregateMin())); 2746 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 2747 new pm::AggregateMax())); 2748 2749 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 0)); 2750 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 2751 new pm::AggregateAvg())); 2752 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 2753 new pm::AggregateMin())); 2754 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 2755 new pm::AggregateMax())); 2756 2757 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 0)); 2758 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 2759 new pm::AggregateAvg())); 2760 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 2761 new pm::AggregateMin())); 2762 aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 2763 new pm::AggregateMax())); 2730 2764 }; 2731 2765 -
trunk/src/VBox/Main/Performance.cpp
r10679 r10713 35 35 // Default factory 36 36 37 BaseMetric *MetricFactory::createHostCpuLoad( IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)37 BaseMetric *MetricFactory::createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle) 38 38 { 39 39 Assert(mHAL); 40 40 return new HostCpuLoad(mHAL, object, user, kernel, idle); 41 41 } 42 BaseMetric *MetricFactory::createHostCpuMHz( IUnknown *object, SubMetric *mhz)42 BaseMetric *MetricFactory::createHostCpuMHz(ComPtr<IUnknown> object, SubMetric *mhz) 43 43 { 44 44 Assert(mHAL); 45 45 return new HostCpuMhz(mHAL, object, mhz); 46 46 } 47 BaseMetric *MetricFactory::createHostRamUsage( IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available)47 BaseMetric *MetricFactory::createHostRamUsage(ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available) 48 48 { 49 49 Assert(mHAL); 50 50 return new HostRamUsage(mHAL, object, total, used, available); 51 51 } 52 BaseMetric *MetricFactory::createMachineCpuLoad( IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)52 BaseMetric *MetricFactory::createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel) 53 53 { 54 54 Assert(mHAL); 55 55 return new MachineCpuLoad(mHAL, object, process, user, kernel); 56 56 } 57 BaseMetric *MetricFactory::createMachineRamUsage( IUnknown *object, RTPROCESS process, SubMetric *used)57 BaseMetric *MetricFactory::createMachineRamUsage(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used) 58 58 { 59 59 Assert(mHAL); … … 69 69 } 70 70 71 BaseMetric *MetricFactoryLinux::createHostCpuLoad( IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)71 BaseMetric *MetricFactoryLinux::createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle) 72 72 { 73 73 Assert(mHAL); … … 75 75 } 76 76 77 BaseMetric *MetricFactoryLinux::createMachineCpuLoad( IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)77 BaseMetric *MetricFactoryLinux::createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel) 78 78 { 79 79 Assert(mHAL); … … 173 173 return E_NOTIMPL; 174 174 } 175 175 176 int CollectorLinux::getHostMemoryUsage(unsigned long *total, unsigned long *used, unsigned long *available) 176 177 { 177 return E_NOTIMPL; 178 #ifdef RT_OS_LINUX 179 int rc = VINF_SUCCESS; 180 unsigned long buffers, cached; 181 FILE *f = fopen("/proc/meminfo", "r"); 182 183 if (f) 184 { 185 int processed = fscanf(f, "MemTotal: %lu kB", total); 186 processed += fscanf(f, "MemFree: %lu kB", available); 187 processed += fscanf(f, "Buffers: %lu kB", &buffers); 188 processed += fscanf(f, "Cached: %lu kB", &cached); 189 if (processed == 4) 190 *available += buffers + cached; 191 else 192 rc = VERR_FILE_IO_ERROR; 193 fclose(f); 194 } 195 else 196 rc = VERR_ACCESS_DENIED; 197 198 return rc; 199 #else 200 return E_NOTIMPL; 201 #endif 178 202 } 179 203 int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, unsigned long *used) 180 204 { 181 205 return E_NOTIMPL; 206 } 207 208 void BaseMetric::collectorBeat(uint64_t nowAt) 209 { 210 if (isEnabled()) 211 { 212 if (nowAt - mLastSampleTaken >= mPeriod * 1000) 213 { 214 mLastSampleTaken = nowAt; 215 collect(); 216 } 217 } 182 218 } 183 219 … … 205 241 unsigned long userDiff, kernelDiff, idleDiff, totalDiff; 206 242 207 mHAL->getRawHostCpuLoad(&user, &kernel, &idle); 208 209 userDiff = user - mUserPrev; 210 kernelDiff = kernel - mKernelPrev; 211 idleDiff = idle - mIdlePrev; 212 totalDiff = userDiff + kernelDiff + idleDiff; 213 214 mUser->put(PM_CPU_LOAD_MULTIPLIER * userDiff / totalDiff); 215 mKernel->put(PM_CPU_LOAD_MULTIPLIER * kernelDiff / totalDiff); 216 mIdle->put(PM_CPU_LOAD_MULTIPLIER * idleDiff / totalDiff); 217 218 mUserPrev = user; 219 mKernelPrev = kernel; 220 mIdlePrev = idle; 243 int rc = mHAL->getRawHostCpuLoad(&user, &kernel, &idle); 244 AssertRC(rc); 245 if (RT_SUCCESS(rc)) 246 { 247 userDiff = user - mUserPrev; 248 kernelDiff = kernel - mKernelPrev; 249 idleDiff = idle - mIdlePrev; 250 totalDiff = userDiff + kernelDiff + idleDiff; 251 252 mUser->put(PM_CPU_LOAD_MULTIPLIER * userDiff / totalDiff); 253 mKernel->put(PM_CPU_LOAD_MULTIPLIER * kernelDiff / totalDiff); 254 mIdle->put(PM_CPU_LOAD_MULTIPLIER * idleDiff / totalDiff); 255 256 mUserPrev = user; 257 mKernelPrev = kernel; 258 mIdlePrev = idle; 259 } 221 260 } 222 261 … … 231 270 { 232 271 unsigned long mhz; 233 mHAL->getHostCpuMHz(&mhz); 234 mMHz->put(mhz); 272 int rc = mHAL->getHostCpuMHz(&mhz); 273 AssertRC(rc); 274 if (RT_SUCCESS(rc)) 275 mMHz->put(mhz); 235 276 } 236 277 … … 247 288 { 248 289 unsigned long total, used, available; 249 mHAL->getHostMemoryUsage(&total, &used, &available); 250 mTotal->put(total); 251 mUsed->put(used); 252 mAvailable->put(available); 290 int rc = mHAL->getHostMemoryUsage(&total, &used, &available); 291 AssertRC(rc); 292 if (RT_SUCCESS(rc)) 293 { 294 mTotal->put(total); 295 mUsed->put(used); 296 mAvailable->put(available); 297 } 253 298 } 254 299 … … 266 311 { 267 312 unsigned long user, kernel; 268 mHAL->getProcessCpuLoad(mProcess, &user, &kernel); 269 mUser->put(user); 270 mKernel->put(kernel); 313 int rc = mHAL->getProcessCpuLoad(mProcess, &user, &kernel); 314 AssertRC(rc); 315 if (RT_SUCCESS(rc)) 316 { 317 mUser->put(user); 318 mKernel->put(kernel); 319 } 271 320 } 272 321 … … 276 325 unsigned long processUser, processKernel; 277 326 278 mHAL->getRawHostCpuLoad(&hostUser, &hostKernel, &hostIdle); 279 hostTotal = hostUser + hostKernel + hostIdle; 280 281 mHAL->getRawProcessCpuLoad(mProcess, &processUser, &processKernel); 282 mUser->put(PM_CPU_LOAD_MULTIPLIER * (processUser - mProcessUserPrev) / (hostTotal - mHostTotalPrev)); 283 mUser->put(PM_CPU_LOAD_MULTIPLIER * (processKernel - mProcessKernelPrev ) / (hostTotal - mHostTotalPrev)); 284 285 mHostTotalPrev = hostTotal; 286 mProcessUserPrev = processUser; 287 mProcessKernelPrev = processKernel; 327 int rc = mHAL->getRawHostCpuLoad(&hostUser, &hostKernel, &hostIdle); 328 AssertRC(rc); 329 if (RT_SUCCESS(rc)) 330 { 331 hostTotal = hostUser + hostKernel + hostIdle; 332 333 rc = mHAL->getRawProcessCpuLoad(mProcess, &processUser, &processKernel); 334 AssertRC(rc); 335 if (RT_SUCCESS(rc)) 336 { 337 mUser->put(PM_CPU_LOAD_MULTIPLIER * (processUser - mProcessUserPrev) / (hostTotal - mHostTotalPrev)); 338 mUser->put(PM_CPU_LOAD_MULTIPLIER * (processKernel - mProcessKernelPrev ) / (hostTotal - mHostTotalPrev)); 339 340 mHostTotalPrev = hostTotal; 341 mProcessUserPrev = processUser; 342 mProcessKernelPrev = processKernel; 343 } 344 } 288 345 } 289 346 … … 298 355 { 299 356 unsigned long used; 300 mHAL->getProcessMemoryUsage(mProcess, &used); 301 mUsed->put(used); 357 int rc = mHAL->getProcessMemoryUsage(mProcess, &used); 358 AssertRC(rc); 359 if (RT_SUCCESS(rc)) 360 mUsed->put(used); 302 361 } 303 362 … … 308 367 mLength = length; 309 368 mData = (unsigned long *)RTMemAllocZ(length * sizeof(unsigned long)); 310 mPosition = 0; 369 mWrapped = false; 370 mEnd = 0; 311 371 } 312 372 313 373 unsigned long CircularBuffer::length() 314 374 { 315 return m Length;375 return mWrapped ? mLength : mEnd; 316 376 } 317 377 318 378 void CircularBuffer::put(unsigned long value) 319 379 { 320 mData[mPosition++] = value; 321 if (mPosition >= mLength) 322 mPosition = 0; 323 } 324 325 void CircularBuffer::copyTo(unsigned long *data, unsigned long length) 326 { 327 memcpy(data, mData + mPosition, (length - mPosition) * sizeof(unsigned long)); 328 // Copy the wrapped part 329 if (mPosition) 330 memcpy(data + mPosition, mData, mPosition * sizeof(unsigned long)); 331 } 332 333 void SubMetric::query(unsigned long *data, unsigned long count) 334 { 335 copyTo(data, count); 380 if (mData) 381 { 382 mData[mEnd++] = value; 383 if (mEnd >= mLength) 384 { 385 mEnd = 0; 386 mWrapped = true; 387 } 388 } 389 } 390 391 void CircularBuffer::copyTo(unsigned long *data) 392 { 393 if (mWrapped) 394 { 395 memcpy(data, mData + mEnd, (mLength - mEnd) * sizeof(unsigned long)); 396 // Copy the wrapped part 397 if (mEnd) 398 memcpy(data + mEnd, mData, mEnd * sizeof(unsigned long)); 399 } 400 else 401 memcpy(data, mData, mEnd * sizeof(unsigned long)); 402 } 403 404 void SubMetric::query(unsigned long *data) 405 { 406 copyTo(data); 336 407 } 337 408 … … 345 416 { 346 417 tmpData = (unsigned long*)RTMemAlloc(sizeof(*tmpData)*length); 347 mSubMetric->query(tmpData , length);418 mSubMetric->query(tmpData); 348 419 if (mAggregate) 349 420 { … … 351 422 *data = (unsigned long*)RTMemAlloc(sizeof(**data)); 352 423 **data = mAggregate->compute(tmpData, length); 424 RTMemFree(tmpData); 353 425 } 354 426 else … … 367 439 unsigned long AggregateAvg::compute(unsigned long *data, unsigned long length) 368 440 { 369 return 0; 441 uint64_t tmp = 0; 442 for (unsigned long i = 0; i < length; ++i) 443 tmp += data[i]; 444 return tmp / length; 370 445 } 371 446 … … 377 452 unsigned long AggregateMin::compute(unsigned long *data, unsigned long length) 378 453 { 379 return 0; 454 unsigned long tmp = *data; 455 for (unsigned long i = 0; i < length; ++i) 456 if (data[i] < tmp) 457 tmp = data[i]; 458 return tmp; 380 459 } 381 460 … … 387 466 unsigned long AggregateMax::compute(unsigned long *data, unsigned long length) 388 467 { 389 return 0; 468 unsigned long tmp = *data; 469 for (unsigned long i = 0; i < length; ++i) 470 if (data[i] > tmp) 471 tmp = data[i]; 472 return tmp; 390 473 } 391 474 … … 395 478 } 396 479 397 Filter::Filter(ComSafeArrayIn( constBSTR, metricNames),480 Filter::Filter(ComSafeArrayIn(INPTR BSTR, metricNames), 398 481 ComSafeArrayIn(IUnknown *, objects)) 399 482 { 400 483 com::SafeIfaceArray <IUnknown> objectArray(ComSafeArrayInArg(objects)); 401 com::SafeArray < BSTR> nameArray(ComSafeArrayInArg(metricNames));484 com::SafeArray <INPTR BSTR> nameArray(ComSafeArrayInArg(metricNames)); 402 485 for (size_t i = 0; i < objectArray.size(); ++i) 403 486 processMetricList(std::string(com::Utf8Str(nameArray[i])), objectArray[i]); 404 487 } 405 488 406 void Filter::processMetricList(const std::string &name, const IUnknown *object)489 void Filter::processMetricList(const std::string &name, const ComPtr<IUnknown> object) 407 490 { 408 491 std::string::size_type startPos = 0; … … 418 501 } 419 502 420 bool Filter::match(const IUnknown *object, const std::string &name) const503 bool Filter::match(const ComPtr<IUnknown> object, const std::string &name) const 421 504 { 422 505 return true; -
trunk/src/VBox/Main/PerformanceImpl.cpp
r10679 r10713 69 69 //////////////////////////////////////////////////////////////////////////////// 70 70 71 PerformanceCollector::PerformanceCollector() {}71 PerformanceCollector::PerformanceCollector() : mMagic(0) {} 72 72 73 73 PerformanceCollector::~PerformanceCollector() {} … … 103 103 /* @todo Obviously other platforms must be added as well. */ 104 104 m.mFactory = new pm::MetricFactoryLinux(); 105 106 /* Let the sampler know it gets a valid collector. */ 107 mMagic = MAGIC; 108 105 109 /* Start resource usage sampler */ 106 107 110 int vrc = RTTimerCreate (&m.mSampler, VBOX_USAGE_SAMPLER_MIN_INTERVAL, 108 111 &PerformanceCollector::staticSamplerCallback, this); … … 138 141 } 139 142 143 mMagic = 0; 144 140 145 /* Destroy resource usage sampler */ 141 146 int vrc = RTTimerDestroy (m.mSampler); … … 190 195 } 191 196 192 STDMETHODIMP PerformanceCollector::SetupMetrics (ComSafeArrayIn( constBSTR, metricNames),197 STDMETHODIMP PerformanceCollector::SetupMetrics (ComSafeArrayIn(INPTR BSTR, metricNames), 193 198 ComSafeArrayIn(IUnknown *, objects), 194 199 ULONG aPeriod, ULONG aCount) … … 199 204 for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it) 200 205 if (filter.match((*it)->getObject(), (*it)->getName())) 206 { 201 207 (*it)->init(aPeriod, aCount); 208 (*it)->enable(); 209 } 202 210 203 211 return S_OK; … … 207 215 ComSafeArrayIn(IUnknown *, objects)) 208 216 { 209 return E_NOTIMPL; 217 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 218 219 BaseMetricList::iterator it; 220 for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it) 221 if (filter.match((*it)->getObject(), (*it)->getName())) 222 (*it)->enable(); 223 224 return S_OK; 210 225 } 211 226 … … 213 228 ComSafeArrayIn(IUnknown *, objects)) 214 229 { 215 return E_NOTIMPL; 230 pm::Filter filter(ComSafeArrayInArg(metricNames), ComSafeArrayInArg(objects)); 231 232 BaseMetricList::iterator it; 233 for (it = m.mBaseMetrics.begin(); it != m.mBaseMetrics.end(); ++it) 234 if (filter.match((*it)->getObject(), (*it)->getName())) 235 (*it)->disable(); 236 237 return S_OK; 216 238 } 217 239 … … 245 267 com::SafeArray<ULONG> retLengths(numberOfMetrics); 246 268 com::SafeArray<LONG> retData(flatSize); 269 247 270 for (it = m.mMetrics.begin(), i = 0; it != m.mMetrics.end(); ++it) 248 271 { … … 254 277 Bstr tmp((*it)->getName()); 255 278 tmp.detachTo(&retNames[i]); 256 retObjects[i] = (*it)->getObject();279 (*it)->getObject().queryInterfaceTo(&retObjects[i]); 257 280 retLengths[i] = length; 258 281 retIndices[i] = flatIndex; … … 260 283 flatIndex += length; 261 284 } 285 262 286 retNames.detachTo(ComSafeArrayOutArg(outMetricNames)); 263 287 retObjects.detachTo(ComSafeArrayOutArg(outObjects)); … … 303 327 { 304 328 AssertReturnVoid (pvUser != NULL); 305 static_cast <PerformanceCollector *> (pvUser)->samplerCallback(); 329 PerformanceCollector *collector = static_cast <PerformanceCollector *> (pvUser); 330 Assert(collector->mMagic == MAGIC); 331 if (collector->mMagic == MAGIC) 332 { 333 collector->samplerCallback(); 334 } 306 335 } 307 336 308 337 void PerformanceCollector::samplerCallback() 309 338 { 339 uint64_t timestamp = RTTimeMilliTS(); 340 std::for_each(m.mBaseMetrics.begin(), m.mBaseMetrics.end(), 341 std::bind2nd (std::mem_fun (&pm::BaseMetric::collectorBeat), timestamp)); 310 342 } 311 343 -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r10695 r10713 10157 10157 > 10158 10158 <desc> 10159 The IPerformanceCollector interface s represents a service that collects10160 andstores performace metrics data.10159 The IPerformanceCollector interface represents a service that collects and 10160 stores performace metrics data. 10161 10161 10162 10162 Performance metrics are associated with objects like IHost and IMachine. … … 10280 10280 <desc> 10281 10281 Queries collected metrics data for a set of objects. 10282 10283 The data itself and related metric information are returned in four 10284 parallel and one flattened array of arrays. Elements of @c 10285 returnMetricNames, @c returnObjects, @c returnDataIndices and @ 10286 returnDataLengths with the same index describe one set of values 10287 corresponding to a single metric. 10282 10288 10283 10289 The @a returnData parameter is a flattened array of arrays. Each start 10284 10290 and length of a sub-array is indicated by @a returnDataIndices and @a 10285 returnDataLengths. 10291 returnDataLengths. The first value for metric <tt>metricNames[i]</tt> is at 10292 <tt> returnData[returnIndices[i]]</tt>. 10286 10293 10287 10294 <note> … … 10325 10332 <desc> 10326 10333 Flattened array of all metric data containing sequences of values for 10327 each metric. The first value for metric <tt>metricNames[i]</tt> is at 10328 <tt> returnData[returnIndices[i]]</tt>. 10334 each metric. 10329 10335 </desc> 10330 10336 </param> -
trunk/src/VBox/Main/include/Performance.h
r10679 r10713 29 29 30 30 namespace pm { 31 const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(1000000000); 32 /*IUnknown * iunknown(ComPtr<IUnknown> object) 33 { 34 IUnknown *objptr; 35 36 object.queryInterfaceTo(&objptr); 37 return objptr; 38 }*/ 31 const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000000); 39 32 40 33 /* Sub Metrics **********************************************************/ … … 42 35 { 43 36 public: 44 CircularBuffer() : mData(0), mLength(0), m Position(0) {};37 CircularBuffer() : mData(0), mLength(0), mEnd(0), mWrapped(false) {}; 45 38 void init(unsigned long length); 46 39 unsigned long length(); 47 40 void put(unsigned long value); 48 void copyTo(unsigned long *data , unsigned long length);41 void copyTo(unsigned long *data); 49 42 private: 50 43 unsigned long *mData; 51 unsigned long mLength; 52 unsigned long mPosition; 44 unsigned long mLength; 45 unsigned long mEnd; 46 bool mWrapped; 53 47 }; 54 48 … … 58 52 SubMetric(const char *name) 59 53 : mName(name) {}; 60 void query(unsigned long *data , unsigned long count);54 void query(unsigned long *data); 61 55 const char *getName() { return mName; }; 62 56 private: … … 94 88 { 95 89 public: 96 BaseMetric(CollectorHAL *hal, const char *name, IUnknown *object)97 : mHAL(hal), mLength(0), mName(name), mObject(object) {};90 BaseMetric(CollectorHAL *hal, const char *name, ComPtr<IUnknown> object) 91 : mHAL(hal), mLength(0), mName(name), mObject(object), mLastSampleTaken(0), mEnabled(false) {}; 98 92 99 93 virtual void init(unsigned long period, unsigned long length) = 0; … … 103 97 virtual unsigned long getMaxValue() = 0; 104 98 99 void collectorBeat(uint64_t nowAt); 100 101 void enable() { mEnabled = true; }; 102 void disable() { mEnabled = false; }; 103 104 bool isEnabled() { return mEnabled; }; 105 105 unsigned long getPeriod() { return mPeriod; }; 106 106 unsigned long getLength() { return mLength; }; 107 107 const char *getName() { return mName; }; 108 IUnknown *getObject() { return mObject; };109 bool associatedWith( IUnknown *object) { return mObject == object; };108 ComPtr<IUnknown> getObject() { return mObject; }; 109 bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; }; 110 110 111 111 protected: 112 CollectorHAL *mHAL; 113 unsigned long mPeriod; 114 unsigned long mLength; 115 const char *mName; 116 IUnknown *mObject; 112 CollectorHAL *mHAL; 113 unsigned long mPeriod; 114 unsigned long mLength; 115 const char *mName; 116 ComPtr<IUnknown> mObject; 117 uint64_t mLastSampleTaken; 118 bool mEnabled; 117 119 }; 118 120 … … 120 122 { 121 123 public: 122 HostCpuLoad(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)124 HostCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle) 123 125 : BaseMetric(hal, "CPU/Load", object), mUser(user), mKernel(kernel), mIdle(idle) {}; 124 126 void init(unsigned long period, unsigned long length); … … 138 140 { 139 141 public: 140 HostCpuLoadRaw(CollectorHAL *hal, IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle)142 HostCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle) 141 143 : HostCpuLoad(hal, object, user, kernel, idle), mUserPrev(0), mKernelPrev(0), mIdlePrev(0) {}; 142 144 … … 151 153 { 152 154 public: 153 HostCpuMhz(CollectorHAL *hal, IUnknown *object, SubMetric *mhz)155 HostCpuMhz(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *mhz) 154 156 : BaseMetric(hal, "CPU/MHz", object), mMHz(mhz) {}; 155 157 … … 166 168 { 167 169 public: 168 HostRamUsage(CollectorHAL *hal, IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available)170 HostRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available) 169 171 : BaseMetric(hal, "RAM/Usage", object), mTotal(total), mUsed(used), mAvailable(available) {}; 170 172 … … 183 185 { 184 186 public: 185 MachineCpuLoad(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)187 MachineCpuLoad(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel) 186 188 : BaseMetric(hal, "CPU/Load", object), mProcess(process), mUser(user), mKernel(kernel) {}; 187 189 … … 200 202 { 201 203 public: 202 MachineCpuLoadRaw(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel)204 MachineCpuLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel) 203 205 : MachineCpuLoad(hal, object, process, user, kernel), mHostTotalPrev(0), mProcessUserPrev(0), mProcessKernelPrev(0) {}; 204 206 … … 213 215 { 214 216 public: 215 MachineRamUsage(CollectorHAL *hal, IUnknown *object, RTPROCESS process, SubMetric *used)217 MachineRamUsage(CollectorHAL *hal, ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used) 216 218 : BaseMetric(hal, "RAM/Usage", object), mProcess(process), mUsed(used) {}; 217 219 … … 273 275 delete mAggregate; 274 276 } 275 bool associatedWith( IUnknown *object) { return getObject() == object; };277 bool associatedWith(ComPtr<IUnknown> object) { return getObject() == object; }; 276 278 277 279 const char *getName() { return mName.c_str(); }; 278 IUnknown *getObject() { return mBaseMetric->getObject(); };280 ComPtr<IUnknown> getObject() { return mBaseMetric->getObject(); }; 279 281 const char *getUnit() { return mBaseMetric->getUnit(); }; 280 282 unsigned long getMinValue() { return mBaseMetric->getMinValue(); }; … … 298 300 ~MetricFactory() { delete mHAL; }; 299 301 300 virtual BaseMetric *createHostCpuLoad( IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle);301 virtual BaseMetric *createHostCpuMHz( IUnknown *object, SubMetric *mhz);302 virtual BaseMetric *createHostRamUsage( IUnknown *object, SubMetric *total, SubMetric *used, SubMetric *available);303 virtual BaseMetric *createMachineCpuLoad( IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel);304 virtual BaseMetric *createMachineRamUsage( IUnknown *object, RTPROCESS process, SubMetric *used);302 virtual BaseMetric *createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle); 303 virtual BaseMetric *createHostCpuMHz(ComPtr<IUnknown> object, SubMetric *mhz); 304 virtual BaseMetric *createHostRamUsage(ComPtr<IUnknown> object, SubMetric *total, SubMetric *used, SubMetric *available); 305 virtual BaseMetric *createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel); 306 virtual BaseMetric *createMachineRamUsage(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *used); 305 307 protected: 306 308 CollectorHAL *mHAL; … … 312 314 public: 313 315 MetricFactoryLinux(); 314 virtual BaseMetric *createHostCpuLoad( IUnknown *object, SubMetric *user, SubMetric *kernel, SubMetric *idle);315 virtual BaseMetric *createMachineCpuLoad( IUnknown *object, RTPROCESS process, SubMetric *user, SubMetric *kernel);316 virtual BaseMetric *createHostCpuLoad(ComPtr<IUnknown> object, SubMetric *user, SubMetric *kernel, SubMetric *idle); 317 virtual BaseMetric *createMachineCpuLoad(ComPtr<IUnknown> object, RTPROCESS process, SubMetric *user, SubMetric *kernel); 316 318 }; 317 319 … … 319 321 { 320 322 public: 321 Filter(ComSafeArrayIn( constBSTR, 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;323 Filter(ComSafeArrayIn(INPTR BSTR, metricNames), 324 ComSafeArrayIn(IUnknown * , objects)); 325 bool match(const ComPtr<IUnknown> object, const std::string &name) const; 326 private: 327 typedef std::pair<const ComPtr<IUnknown>, const std::string> FilterElement; 326 328 std::list<FilterElement> mElements; 327 329 328 void processMetricList(const std::string &name, const IUnknown *object);330 void processMetricList(const std::string &name, const ComPtr<IUnknown> object); 329 331 }; 330 332 } -
trunk/src/VBox/Main/include/PerformanceImpl.h
r10679 r10713 205 205 ComSafeArrayIn (IUnknown *, objects), 206 206 ComSafeArrayOut (IPerformanceMetric *, metrics)); 207 STDMETHOD(SetupMetrics) (ComSafeArrayIn ( constBSTR, metricNames),207 STDMETHOD(SetupMetrics) (ComSafeArrayIn (INPTR BSTR, metricNames), 208 208 ComSafeArrayIn (IUnknown *, objects), 209 209 ULONG aPeriod, ULONG aCount); … … 243 243 typedef std::list<pm::BaseMetric*> BaseMetricList; 244 244 245 enum 246 { 247 MAGIC = 0xABBA1972u 248 }; 249 250 unsigned int mMagic; 251 245 252 struct Data { 246 253 Data() : mFactory(0) {}; -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r10679 r10713 921 921 #if 1 922 922 do { 923 Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg" };924 com::SafeArray<BSTR> metrics (1);925 metricNames[0].cloneTo (&metrics [0]);923 Bstr baseMetricNames[] = { L"CPU/Load,RAM/Usage" }; 924 com::SafeArray<BSTR> baseMetrics (1); 925 baseMetricNames[0].cloneTo (&baseMetrics [0]); 926 926 927 927 ComPtr <IHost> host; … … 933 933 com::SafeIfaceArray<IUnknown> objects(1); 934 934 host.queryInterfaceTo(&objects[0]); 935 CHECK_ERROR_BREAK (collector, SetupMetrics(ComSafeArrayAsInParam( metrics),935 CHECK_ERROR_BREAK (collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics), 936 936 ComSafeArrayAsInParam(objects), 1u, 10u) ); 937 937 RTThreadSleep(3000); /* Sleep 10 seconds. */ 938 939 Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total.RAM/Usage/Used:avg" }; 940 com::SafeArray<BSTR> metrics (1); 941 metricNames[0].cloneTo (&metrics [0]); 938 942 com::SafeArray<BSTR> retNames; 939 943 com::SafeIfaceArray<IUnknown> retObjects;
Note:
See TracChangeset
for help on using the changeset viewer.