Changeset 43445 in vbox
- Timestamp:
- Sep 27, 2012 8:28:59 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 80964
- Location:
- trunk/src/VBox/Main
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostImpl.h
r36615 r43445 145 145 #endif 146 146 147 HRESULT updateNetIfList(); 148 147 149 #ifdef VBOX_WITH_RESOURCE_USAGE_API 148 150 void registerMetrics(PerformanceCollector *aCollector); -
trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h
r42551 r43445 79 79 80 80 HRESULT setVirtualBox(VirtualBox *pVBox); 81 void registerMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr); 82 void unregisterMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr); 81 83 82 84 private: … … 112 114 }; 113 115 116 typedef std::list<ComObjPtr<HostNetworkInterface> > HostNetworkInterfaceList; 117 114 118 #endif // ____H_H_HOSTNETWORKINTERFACEIMPL 115 119 /* vi: set tabstop=4 shiftwidth=4 expandtab: */ -
trunk/src/VBox/Main/include/Performance.h
r40358 r43445 40 40 /* CPU load is measured in 1/1000 of per cent. */ 41 41 const uint64_t PM_CPU_LOAD_MULTIPLIER = UINT64_C(100000); 42 /* Network load is measured in 1/1000 of per cent. */ 43 const uint64_t PM_NETWORK_LOAD_MULTIPLIER = UINT64_C(100000); 44 /* Sampler precision in milliseconds. */ 45 const uint64_t PM_SAMPLER_PRECISION_MS = 50; 42 46 43 47 /* Sub Metrics **********************************************************/ … … 63 67 { 64 68 public: 65 SubMetric(co nst char *name, const char *description)69 SubMetric(com::Utf8Str name, const char *description) 66 70 : mName(name), mDescription(description) {}; 67 71 void query(ULONG *data); 68 const char *getName() { return mName ; };72 const char *getName() { return mName.c_str(); }; 69 73 const char *getDescription() { return mDescription; }; 70 74 private: 71 const c har *mName;75 const com::Utf8Str mName; 72 76 const char *mDescription; 73 77 }; … … 357 361 /** Returns CPU usage counters in platform-specific units. */ 358 362 virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle); 363 /** Returns received and transmitted bytes as well as link speed. */ 364 virtual int getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx, uint64_t *speed); 359 365 /** Returns process' CPU usage counter in platform-specific units. */ 360 366 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); … … 367 373 { 368 374 public: 369 BaseMetric(CollectorHAL *hal, const c har *name, ComPtr<IUnknown> object)375 BaseMetric(CollectorHAL *hal, const com::Utf8Str name, ComPtr<IUnknown> object) 370 376 : mPeriod(0), mLength(0), mHAL(hal), mName(name), mObject(object), 371 377 mLastSampleTaken(0), mEnabled(false), mUnregistered(false) {}; … … 390 396 ULONG getPeriod() { return mPeriod; }; 391 397 ULONG getLength() { return mLength; }; 392 const char *getName() { return mName ; };398 const char *getName() { return mName.c_str(); }; 393 399 ComPtr<IUnknown> getObject() { return mObject; }; 394 400 bool associatedWith(ComPtr<IUnknown> object) { return mObject == object; }; … … 398 404 ULONG mLength; 399 405 CollectorHAL *mHAL; 400 const c har *mName;406 const com::Utf8Str mName; 401 407 ComPtr<IUnknown> mObject; 402 408 uint64_t mLastSampleTaken; … … 486 492 SubMetric *mAvailable; 487 493 }; 494 495 class HostNetworkLoadRaw : public BaseMetric 496 { 497 public: 498 HostNetworkLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, com::Utf8Str name, com::Utf8Str ifname, SubMetric *rx, SubMetric *tx) 499 : BaseMetric(hal, name, object), mInterfaceName(ifname), mRx(rx), mTx(tx), mRxPrev(0), mTxPrev(0) {}; 500 ~HostNetworkLoadRaw() { delete mRx; delete mTx; }; 501 502 void init(ULONG period, ULONG length); 503 504 void preCollect(CollectorHints& hints, uint64_t iTick); 505 void collect(); 506 const char *getUnit() { return "%"; }; 507 ULONG getMinValue() { return 0; }; 508 ULONG getMaxValue() { return PM_NETWORK_LOAD_MULTIPLIER; }; 509 ULONG getScale() { return PM_NETWORK_LOAD_MULTIPLIER / 100; } 510 511 private: 512 com::Utf8Str mInterfaceName; 513 SubMetric *mRx; 514 SubMetric *mTx; 515 uint64_t mRxPrev; 516 uint64_t mTxPrev; 517 }; 518 488 519 489 520 #ifndef VBOX_COLLECTOR_TEST_CASE -
trunk/src/VBox/Main/src-server/HostImpl.cpp
r43387 r43445 179 179 VirtualBox *pParent; 180 180 181 HostNetworkInterfaceList llNetIfs; // list of network interfaces 182 181 183 #ifdef VBOX_WITH_USB 182 184 USBDeviceFilterList llChildren; // all USB device filters … … 272 274 registerMetrics(aParent->performanceCollector()); 273 275 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 276 /* Create the list of network interfaces so their metrics get registered. */ 277 updateNetIfList(); 274 278 275 279 #if defined (RT_OS_WINDOWS) … … 437 441 438 442 #ifdef VBOX_WITH_RESOURCE_USAGE_API 439 unregisterMetrics (m->pParent->performanceCollector()); 443 PerformanceCollector *aCollector = m->pParent->performanceCollector(); 444 unregisterMetrics (aCollector); 445 HostNetworkInterfaceList::iterator it; 446 for (it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it) 447 (*it)->unregisterMetrics(aCollector, this); 440 448 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 449 m->llNetIfs.clear(); 441 450 442 451 #ifdef VBOX_WITH_USB … … 584 593 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 585 594 595 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 596 # ifdef VBOX_WITH_HOSTNETIF_API 597 int rc = updateNetIfList(); 598 if (rc) 599 { 600 Log(("Failed to get host network interface list with rc=%Rrc\n", rc)); 601 } 602 603 SafeIfaceArray<IHostNetworkInterface> networkInterfaces (m->llNetIfs); 604 networkInterfaces.detachTo(ComSafeArrayOutArg(aNetworkInterfaces)); 605 606 return S_OK; 607 608 # else 586 609 std::list<ComObjPtr<HostNetworkInterface> > list; 587 588 # ifdef VBOX_WITH_HOSTNETIF_API589 int rc = NetIfList(list);590 if (rc)591 {592 Log(("Failed to get host network interface list with rc=%Rrc\n", rc));593 }594 # else595 610 596 611 # if defined(RT_OS_DARWIN) … … 739 754 } 740 755 # endif /* RT_OS_LINUX */ 741 # endif742 743 std::list <ComObjPtr<HostNetworkInterface> >::iterator it;744 for (it = list.begin(); it != list.end(); ++it)745 {746 (*it)->setVirtualBox(m->pParent);747 }748 756 749 757 SafeIfaceArray<IHostNetworkInterface> networkInterfaces (list); … … 752 760 return S_OK; 753 761 762 # endif 754 763 #else 755 764 /* Not implemented / supported on this platform. */ … … 1391 1400 return E_POINTER; 1392 1401 1402 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1403 1393 1404 *networkInterface = NULL; 1394 1405 ComObjPtr<HostNetworkInterface> found; 1395 std::list <ComObjPtr<HostNetworkInterface> > list; 1396 int rc = NetIfList(list); 1406 int rc = updateNetIfList(); 1397 1407 if (RT_FAILURE(rc)) 1398 1408 { … … 1400 1410 return E_FAIL; 1401 1411 } 1402 std::list <ComObjPtr<HostNetworkInterface> >::iterator it;1403 for (it = list.begin(); it != list.end(); ++it)1412 HostNetworkInterfaceList::iterator it; 1413 for (it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it) 1404 1414 { 1405 1415 Bstr n; … … 1412 1422 return setError(E_INVALIDARG, 1413 1423 HostNetworkInterface::tr("The host network interface with the given name could not be found")); 1414 1415 found->setVirtualBox(m->pParent);1416 1424 1417 1425 return found.queryInterfaceTo(networkInterface); … … 1429 1437 return E_POINTER; 1430 1438 1439 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1440 1431 1441 *networkInterface = NULL; 1432 1442 ComObjPtr<HostNetworkInterface> found; 1433 std::list <ComObjPtr<HostNetworkInterface> > list; 1434 int rc = NetIfList(list); 1443 int rc = updateNetIfList(); 1435 1444 if (RT_FAILURE(rc)) 1436 1445 { … … 1438 1447 return E_FAIL; 1439 1448 } 1440 std::list <ComObjPtr<HostNetworkInterface> >::iterator it;1441 for (it = list.begin(); it != list.end(); ++it)1449 HostNetworkInterfaceList::iterator it; 1450 for (it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it) 1442 1451 { 1443 1452 Bstr g; … … 1451 1460 HostNetworkInterface::tr("The host network interface with the given GUID could not be found")); 1452 1461 1453 found->setVirtualBox(m->pParent);1454 1455 1462 return found.queryInterfaceTo(networkInterface); 1456 1463 #endif … … 1461 1468 { 1462 1469 #ifdef VBOX_WITH_HOSTNETIF_API 1463 std::list <ComObjPtr<HostNetworkInterface> > allList; 1464 int rc = NetIfList(allList); 1470 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1471 1472 int rc = updateNetIfList(); 1465 1473 if (RT_FAILURE(rc)) 1466 1474 return E_FAIL; 1467 1475 1468 std::list <ComObjPtr<HostNetworkInterface> >resultList;1469 1470 std::list <ComObjPtr<HostNetworkInterface> >::iterator it;1471 for (it = allList.begin(); it != allList.end(); ++it)1476 HostNetworkInterfaceList resultList; 1477 1478 HostNetworkInterfaceList::iterator it; 1479 for (it = m->llNetIfs.begin(); it != m->llNetIfs.end(); ++it) 1472 1480 { 1473 1481 HostNetworkInterfaceType_T t; … … 1477 1485 1478 1486 if (t == type) 1479 {1480 (*it)->setVirtualBox(m->pParent);1481 1487 resultList.push_back (*it); 1482 }1483 1488 } 1484 1489 … … 2811 2816 #endif /* VBOX_WITH_USB */ 2812 2817 2818 HRESULT Host::updateNetIfList() 2819 { 2820 #ifdef VBOX_WITH_HOSTNETIF_API 2821 AssertReturn(AutoCaller(this).state() == InInit || 2822 isWriteLockOnCurrentThread(), E_FAIL); 2823 2824 HostNetworkInterfaceList list, listCopy; 2825 int rc = NetIfList(list); 2826 if (rc) 2827 { 2828 Log(("Failed to get host network interface list with rc=%Rrc\n", rc)); 2829 return E_FAIL; 2830 } 2831 AssertReturn(m->pParent, E_FAIL); 2832 /* Make a copy as the original may be partially destroyed later. */ 2833 listCopy = list; 2834 HostNetworkInterfaceList::iterator itOld, itNew; 2835 PerformanceCollector *aCollector = m->pParent->performanceCollector(); 2836 for (itOld = m->llNetIfs.begin(); itOld != m->llNetIfs.end(); ++itOld) 2837 { 2838 bool fGone = true; 2839 Bstr nameOld; 2840 (*itOld)->COMGETTER(Name) (nameOld.asOutParam()); 2841 for (itNew = listCopy.begin(); itNew != listCopy.end(); ++itNew) 2842 { 2843 Bstr nameNew; 2844 (*itNew)->COMGETTER(Name) (nameNew.asOutParam()); 2845 if (nameNew == nameOld) 2846 { 2847 fGone = false; 2848 listCopy.erase(itNew); 2849 break; 2850 } 2851 } 2852 if (fGone) 2853 (*itOld)->unregisterMetrics(aCollector, this); 2854 } 2855 /* At this point listCopy will contain newly discovered interfaces only. */ 2856 for (itNew = listCopy.begin(); itNew != listCopy.end(); ++itNew) 2857 { 2858 (*itNew)->setVirtualBox(m->pParent); 2859 (*itNew)->registerMetrics(aCollector, this); 2860 } 2861 m->llNetIfs = list; 2862 return S_OK; 2863 #else 2864 return E_NOTIMPL; 2865 #endif 2866 } 2867 2813 2868 #ifdef VBOX_WITH_RESOURCE_USAGE_API 2814 2869 … … 2842 2897 2843 2898 /* Create and register base metrics */ 2844 IUnknown *objptr; 2845 ComObjPtr<Host> tmp = this; 2846 tmp.queryInterfaceTo(&objptr); 2847 pm::BaseMetric *cpuLoad = new pm::HostCpuLoadRaw(hal, objptr, cpuLoadUser, cpuLoadKernel, 2899 pm::BaseMetric *cpuLoad = new pm::HostCpuLoadRaw(hal, this, cpuLoadUser, cpuLoadKernel, 2848 2900 cpuLoadIdle); 2849 2901 aCollector->registerBaseMetric (cpuLoad); 2850 pm::BaseMetric *cpuMhz = new pm::HostCpuMhz(hal, objptr, cpuMhzSM);2902 pm::BaseMetric *cpuMhz = new pm::HostCpuMhz(hal, this, cpuMhzSM); 2851 2903 aCollector->registerBaseMetric (cpuMhz); 2852 pm::BaseMetric *ramUsage = new pm::HostRamUsage(hal, objptr,2904 pm::BaseMetric *ramUsage = new pm::HostRamUsage(hal, this, 2853 2905 ramUsageTotal, 2854 2906 ramUsageUsed, 2855 2907 ramUsageFree); 2856 2908 aCollector->registerBaseMetric (ramUsage); 2857 pm::BaseMetric *ramVmm = new pm::HostRamVmm(aCollector->getGuestManager(), objptr,2909 pm::BaseMetric *ramVmm = new pm::HostRamVmm(aCollector->getGuestManager(), this, 2858 2910 ramVMMUsed, 2859 2911 ramVMMFree, -
trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp
r42551 r43445 22 22 #include "Logging.h" 23 23 #include "netif.h" 24 #include "Performance.h" 25 #include "PerformanceImpl.h" 24 26 25 27 #include <iprt/cpp/utils.h> … … 83 85 84 86 return S_OK; 87 } 88 89 void HostNetworkInterface::registerMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr) 90 { 91 LogFlowThisFunc(("mInterfaceName={%ls}, mGuid={%s}\n", 92 mInterfaceName.raw(), mGuid.toString().c_str())); 93 pm::CollectorHAL *hal = aCollector->getHAL(); 94 /* Create sub metrics */ 95 Utf8StrFmt strName("Net/%ls/Load", mInterfaceName.raw()); 96 pm::SubMetric *networkLoadRx = new pm::SubMetric(strName + "/Rx", 97 "Percentage of network interface bandwidth used."); 98 pm::SubMetric *networkLoadTx = new pm::SubMetric(strName + "/Tx", 99 "Percentage of network interface bandwidth used."); 100 101 /* Create and register base metrics */ 102 pm::BaseMetric *networkLoad = new pm::HostNetworkLoadRaw(hal, objptr, strName, Utf8Str(mInterfaceName), networkLoadRx, networkLoadTx); 103 aCollector->registerBaseMetric(networkLoad); 104 105 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx, 0)); 106 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx, 107 new pm::AggregateAvg())); 108 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx, 109 new pm::AggregateMin())); 110 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadRx, 111 new pm::AggregateMax())); 112 113 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx, 0)); 114 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx, 115 new pm::AggregateAvg())); 116 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx, 117 new pm::AggregateMin())); 118 aCollector->registerMetric(new pm::Metric(networkLoad, networkLoadTx, 119 new pm::AggregateMax())); 120 } 121 122 void HostNetworkInterface::unregisterMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr) 123 { 124 LogFlowThisFunc(("mInterfaceName={%ls}, mGuid={%s}\n", 125 mInterfaceName.raw(), mGuid.toString().c_str())); 126 aCollector->unregisterMetricsFor(objptr); 127 aCollector->unregisterBaseMetricsFor(objptr); 85 128 } 86 129 … … 553 596 AutoCaller autoCaller(this); 554 597 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 598 AssertReturn(mVBox != pVBox, S_OK); 599 555 600 unconst(mVBox) = pVBox; 556 601 -
trunk/src/VBox/Main/src-server/Performance.cpp
r40568 r43445 55 55 56 56 int CollectorHAL::getRawHostCpuLoad(uint64_t * /* user */, uint64_t * /* kernel */, uint64_t * /* idle */) 57 { 58 return E_NOTIMPL; 59 } 60 61 int CollectorHAL::getRawHostNetworkLoad(const char * /* name */, uint64_t * /* rx */, uint64_t * /* tx */, uint64_t */* speed */) 57 62 { 58 63 return E_NOTIMPL; … … 554 559 if (isEnabled()) 555 560 { 556 if ( nowAt - mLastSampleTaken >= mPeriod * 1000)561 if (mLastSampleTaken == 0) 557 562 { 558 563 mLastSampleTaken = nowAt; … … 561 566 return true; 562 567 } 568 /* 569 * We use low resolution timers which may fire just a little bit early. 570 * We compensate for that by jumping into the future by several 571 * milliseconds (see @bugref{6345}). 572 */ 573 if (nowAt - mLastSampleTaken + PM_SAMPLER_PRECISION_MS >= mPeriod * 1000) 574 { 575 /* 576 * We don't want the beat to drift. This is why the timestamp of 577 * the last taken sample is not the actual time but the time we 578 * should have taken the measurement at. 579 */ 580 mLastSampleTaken += mPeriod * 1000; 581 Log4(("{%p} " LOG_FN_FMT ": Collecting %s for obj(%p)...\n", 582 this, __PRETTY_FUNCTION__, getName(), (void *)mObject)); 583 return true; 584 } 585 Log4(("{%p} " LOG_FN_FMT ": Enabled but too early to collect %s for obj(%p)\n", 586 this, __PRETTY_FUNCTION__, getName(), (void *)mObject)); 563 587 } 564 588 return false; … … 623 647 mKernelPrev = kernel; 624 648 mIdlePrev = idle; 649 } 650 } 651 652 void HostNetworkLoadRaw::init(ULONG period, ULONG length) 653 { 654 mPeriod = period; 655 mLength = length; 656 mRx->init(mLength); 657 mTx->init(mLength); 658 uint64_t speed; 659 int rc = mHAL->getRawHostNetworkLoad(mInterfaceName.c_str(), &mRxPrev, &mTxPrev, &speed); 660 AssertRC(rc); 661 } 662 663 void HostNetworkLoadRaw::preCollect(CollectorHints& /* hints */, uint64_t /* iTick */) 664 { 665 } 666 667 void HostNetworkLoadRaw::collect() 668 { 669 uint64_t rx, tx, speed; 670 671 int rc = mHAL->getRawHostNetworkLoad(mInterfaceName.c_str(), &rx, &tx, &speed); 672 if (RT_SUCCESS(rc)) 673 { 674 uint64_t rxDiff = rx - mRxPrev; 675 uint64_t txDiff = tx - mTxPrev; 676 677 if (RT_UNLIKELY(speed * getPeriod() == 0)) 678 { 679 Assert(speed * getPeriod()); 680 LogFlowThisFunc(("Impossible! speed=%llu period=%d.\n", speed, getPeriod())); 681 mRx->put(0); 682 mTx->put(0); 683 } 684 else 685 { 686 mRx->put((ULONG)(PM_NETWORK_LOAD_MULTIPLIER * rxDiff / (speed * getPeriod()))); 687 mTx->put((ULONG)(PM_NETWORK_LOAD_MULTIPLIER * txDiff / (speed * getPeriod()))); 688 } 689 690 mRxPrev = rx; 691 mTxPrev = tx; 625 692 } 626 693 } -
trunk/src/VBox/Main/src-server/PerformanceImpl.cpp
r40358 r43445 66 66 "CPU/MHz:min", 67 67 "CPU/MHz:max", 68 "Net/*/Load/Rx", 69 "Net/*/Load/Rx:avg", 70 "Net/*/Load/Rx:min", 71 "Net/*/Load/Rx:max", 72 "Net/*/Load/Tx", 73 "Net/*/Load/Tx:avg", 74 "Net/*/Load/Tx:min", 75 "Net/*/Load/Tx:max", 68 76 "RAM/Usage/Total", 69 77 "RAM/Usage/Total:avg", -
trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp
r37713 r43445 40 40 41 41 virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle); 42 virtual int getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx, uint64_t *speed); 42 43 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 43 44 private: … … 217 218 } 218 219 219 } 220 220 int CollectorLinux::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx, uint64_t *speed) 221 { 222 int rc = VINF_SUCCESS; 223 char szIfName[/*IFNAMSIZ*/ 16 + 36]; 224 long long unsigned int u64Rx, u64Tx, u64Speed; 225 226 RTStrPrintf(szIfName, sizeof(szIfName), "/sys/class/net/%s/statistics/rx_bytes", name); 227 FILE *f = fopen(szIfName, "r"); 228 if (f) 229 { 230 if (fscanf(f, "%llu", &u64Rx) == 1) 231 *rx = u64Rx; 232 else 233 rc = VERR_FILE_IO_ERROR; 234 fclose(f); 235 RTStrPrintf(szIfName, sizeof(szIfName), "/sys/class/net/%s/statistics/tx_bytes", name); 236 f = fopen(szIfName, "r"); 237 if (f) 238 { 239 if (fscanf(f, "%llu", &u64Tx) == 1) 240 *tx = u64Tx; 241 else 242 rc = VERR_FILE_IO_ERROR; 243 fclose(f); 244 RTStrPrintf(szIfName, sizeof(szIfName), "/sys/class/net/%s/speed", name); 245 f = fopen(szIfName, "r"); 246 if (f) 247 { 248 if (fscanf(f, "%llu", &u64Speed) == 1) 249 *speed = u64Speed * (1000000/8); /* Convert to bytes/sec */ 250 else 251 rc = VERR_FILE_IO_ERROR; 252 fclose(f); 253 } 254 else 255 rc = VERR_ACCESS_DENIED; 256 } 257 else 258 rc = VERR_ACCESS_DENIED; 259 } 260 else 261 rc = VERR_ACCESS_DENIED; 262 263 return rc; 264 } 265 266 } 267 -
trunk/src/VBox/Main/testcase/tstAPI.cpp
r42261 r43445 1187 1187 networkInterface->COMGETTER(Name)(interfaceName.asOutParam()); 1188 1188 RTPrintf("Found %d network interfaces, testing with %ls...\n", hostNetworkInterfaces.size(), interfaceName.raw()); 1189 GuidinterfaceGuid;1189 Bstr interfaceGuid; 1190 1190 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam()); 1191 1191 // Find the interface by its name 1192 1192 networkInterface.setNull(); 1193 1193 CHECK_ERROR_BREAK(host, 1194 FindHostNetworkInterfaceByName(interfaceName , networkInterface.asOutParam()));1195 GuidinterfaceGuid2;1194 FindHostNetworkInterfaceByName(interfaceName.raw(), networkInterface.asOutParam())); 1195 Bstr interfaceGuid2; 1196 1196 networkInterface->COMGETTER(Id)(interfaceGuid2.asOutParam()); 1197 1197 if (interfaceGuid2 != interfaceGuid) … … 1200 1200 networkInterface.setNull(); 1201 1201 CHECK_ERROR_BREAK(host, 1202 FindHostNetworkInterfaceById(interfaceGuid , networkInterface.asOutParam()));1202 FindHostNetworkInterfaceById(interfaceGuid.raw(), networkInterface.asOutParam())); 1203 1203 Bstr interfaceName2; 1204 1204 networkInterface->COMGETTER(Name)(interfaceName2.asOutParam()); 1205 1205 if (interfaceName != interfaceName2) 1206 RTPrintf("Failed to retrieve an interface by GUID %ls.\n", Bstr(interfaceGuid.toString()).raw());1206 RTPrintf("Failed to retrieve an interface by GUID %ls.\n", interfaceGuid.raw()); 1207 1207 } 1208 1208 else … … 1213 1213 #endif 1214 1214 1215 #if 0 && defined(VBOX_WITH_RESOURCE_USAGE_API) 1216 do { 1217 // Get collector 1218 ComPtr<IPerformanceCollector> collector; 1219 CHECK_ERROR_BREAK(virtualBox, 1220 COMGETTER(PerformanceCollector)(collector.asOutParam())); 1221 1222 1223 // Fill base metrics array 1224 Bstr baseMetricNames[] = { L"Net/eth0/Load" }; 1225 com::SafeArray<BSTR> baseMetrics(1); 1226 baseMetricNames[0].cloneTo(&baseMetrics[0]); 1227 1228 // Get host 1229 ComPtr<IHost> host; 1230 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam())); 1231 1232 // Get host network interfaces 1233 // com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces; 1234 // CHECK_ERROR_BREAK(host, 1235 // COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces))); 1236 1237 // Setup base metrics 1238 // Note that one needs to set up metrics after a session is open for a machine. 1239 com::SafeIfaceArray<IPerformanceMetric> affectedMetrics; 1240 com::SafeIfaceArray<IUnknown> objects(1); 1241 host.queryInterfaceTo(&objects[0]); 1242 CHECK_ERROR_BREAK(collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics), 1243 ComSafeArrayAsInParam(objects), 1u, 10u, 1244 ComSafeArrayAsOutParam(affectedMetrics))); 1245 listAffectedMetrics(virtualBox, 1246 ComSafeArrayAsInParam(affectedMetrics)); 1247 affectedMetrics.setNull(); 1248 1249 RTPrintf("Sleeping for 5 seconds...\n"); 1250 RTThreadSleep(5000); // Sleep for 5 seconds 1251 1252 RTPrintf("\nMetrics collected: --------------------\n"); 1253 queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects)); 1254 } while (false); 1255 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 1215 1256 #if 0 && defined(VBOX_WITH_RESOURCE_USAGE_API) 1216 1257 do { … … 1426 1467 RTPrintf("\n"); 1427 1468 #endif 1428 #if 11469 #if 0 1429 1470 // check of network bandwidth control 1430 1471 /////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/testcase/tstCollector.cpp
r38636 r43445 142 142 } 143 143 144 int testNetwork(pm::CollectorHAL *collector) 145 { 146 pm::CollectorHints hints; 147 uint64_t hostRxStart, hostTxStart, speedStart; 148 uint64_t hostRxStop, hostTxStop, speedStop; 149 150 RTPrintf("\ntstCollector: TESTING - Network load, sleeping for 5 sec...\n"); 151 152 int rc = collector->preCollect(hints, 0); 153 if (RT_FAILURE(rc)) 154 { 155 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 156 return 1; 157 } 158 rc = collector->getRawHostNetworkLoad("eth0", &hostRxStart, &hostTxStart, &speedStart); 159 if (RT_FAILURE(rc)) 160 { 161 RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc); 162 return 1; 163 } 164 165 RTThreadSleep(5000); // Sleep for five seconds 166 167 rc = collector->preCollect(hints, 0); 168 if (RT_FAILURE(rc)) 169 { 170 RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc); 171 return 1; 172 } 173 rc = collector->getRawHostNetworkLoad("eth0", &hostRxStop, &hostTxStop, &speedStop); 174 if (RT_FAILURE(rc)) 175 { 176 RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc); 177 return 1; 178 } 179 if (speedStart != speedStop) 180 RTPrintf("tstCollector: getRawHostNetworkLoad() returned different bandwidth (%llu != %llu)\n", speedStart, speedStop); 181 RTPrintf("tstCollector: host network speed = %llu bytes/sec (%llu mbit/sec)\n", 182 speedStop, speedStop/(1000000/8)); 183 RTPrintf("tstCollector: host network rx = %llu bytes/sec (%llu mbit/sec, %d %%*100)\n", 184 (hostRxStop - hostRxStart)/5, (hostRxStop - hostRxStart)/(5000000/8), 185 (hostRxStop - hostRxStart) * 10000 / (speedStop * 5)); 186 RTPrintf("tstCollector: host network tx = %llu bytes/sec (%llu mbit/sec, %d %%*100)\n", 187 (hostTxStop - hostTxStart)/5, (hostTxStop - hostTxStart)/(5000000/8), 188 (hostTxStop - hostTxStart) * 10000 / (speedStop * 5)); 189 190 return 0; 191 } 192 144 193 int main(int argc, char *argv[]) 145 194 { … … 320 369 RTPrintf("tstCollector: process mem used = %lu kB\n", processUsed); 321 370 #endif 371 #if 1 372 rc = testNetwork(collector); 373 #endif 374 #if 0 322 375 RTPrintf("\ntstCollector: TESTING - Performance\n\n"); 323 376 324 377 measurePerformance(collector, argv[0], 100); 378 #endif 325 379 326 380 delete collector;
Note:
See TracChangeset
for help on using the changeset viewer.