Changeset 43507 in vbox for trunk/src/VBox
- Timestamp:
- Oct 2, 2012 1:22:31 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 81089
- Location:
- trunk/src/VBox/Main
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h
r43445 r43507 110 110 HostNetworkInterfaceMediumType_T mediumType; 111 111 HostNetworkInterfaceStatus_T status; 112 ULONG speedMbytes; 112 113 } m; 113 114 -
trunk/src/VBox/Main/include/Performance.h
r43456 r43507 361 361 /** Returns CPU usage counters in platform-specific units. */ 362 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);363 /** Returns received and transmitted bytes. */ 364 virtual int getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx); 365 365 /** Returns process' CPU usage counter in platform-specific units. */ 366 366 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); … … 496 496 { 497 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), mRc(VINF_SUCCESS) { };498 HostNetworkLoadRaw(CollectorHAL *hal, ComPtr<IUnknown> object, com::Utf8Str name, com::Utf8Str ifname, uint32_t speed, SubMetric *rx, SubMetric *tx) 499 : BaseMetric(hal, name, object), mInterfaceName(ifname), mRx(rx), mTx(tx), mRxPrev(0), mTxPrev(0), mRc(VINF_SUCCESS) { mSpeed = (uint64_t)speed * (1000000/8); /* Convert to bytes/sec */ }; 500 500 ~HostNetworkLoadRaw() { delete mRx; delete mTx; }; 501 501 … … 515 515 uint64_t mRxPrev; 516 516 uint64_t mTxPrev; 517 uint64_t mSpeed; 517 518 int mRc; 518 519 }; -
trunk/src/VBox/Main/include/netif.h
r36057 r43507 72 72 NETIFTYPE enmMediumType; 73 73 NETIFSTATUS enmStatus; 74 uint32_t uSpeedMbytes; 74 75 RTUUID Uuid; 75 76 char szShortName[VBOXNET_MAX_SHORT_NAME]; … … 92 93 int NetIfGetConfigByName(PNETIFINFO pInfo); 93 94 int NetIfDhcpRediscover(VirtualBox *pVbox, HostNetworkInterface * pIf); 95 int NetIfAdpCtlOut(const char * pcszName, const char * pcszCmd, char *pszBuffer, size_t cBufSize); 94 96 95 97 DECLINLINE(Bstr) composeIPv6Address(PRTNETADDRIPV6 aAddrPtr) -
trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp
r43453 r43507 100 100 101 101 /* Create and register base metrics */ 102 pm::BaseMetric *networkLoad = new pm::HostNetworkLoadRaw(hal, objptr, strName, Utf8Str(mInterfaceName), networkLoadRx, networkLoadTx);102 pm::BaseMetric *networkLoad = new pm::HostNetworkLoadRaw(hal, objptr, strName, Utf8Str(mInterfaceName), m.speedMbytes, networkLoadRx, networkLoadTx); 103 103 aCollector->registerBaseMetric(networkLoad); 104 104 … … 149 149 m.mediumType = info.enmMediumType; 150 150 m.status = info.enmStatus; 151 152 151 #endif /* !RT_OS_WINDOWS */ 152 m.speedMbytes = info.uSpeedMbytes; 153 153 return S_OK; 154 154 } … … 201 201 m.status = pIf->enmStatus; 202 202 #endif /* !RT_OS_WINDOWS */ 203 m.speedMbytes = pIf->uSpeedMbytes; 203 204 204 205 /* Confirm a successful initialization */ -
trunk/src/VBox/Main/src-server/Performance.cpp
r43456 r43507 59 59 } 60 60 61 int CollectorHAL::getRawHostNetworkLoad(const char * /* name */, uint64_t * /* rx */, uint64_t * /* tx */ , uint64_t */* speed */)61 int CollectorHAL::getRawHostNetworkLoad(const char * /* name */, uint64_t * /* rx */, uint64_t * /* tx */) 62 62 { 63 63 return E_NOTIMPL; … … 656 656 mRx->init(mLength); 657 657 mTx->init(mLength); 658 uint64_t speed; 659 int rc = mHAL->getRawHostNetworkLoad(mInterfaceName.c_str(), &mRxPrev, &mTxPrev, &speed); 658 int rc = mHAL->getRawHostNetworkLoad(mInterfaceName.c_str(), &mRxPrev, &mTxPrev); 660 659 AssertRC(rc); 661 660 } … … 670 669 if (SUCCEEDED(hrc)) 671 670 { 672 LogRel(("Failed to collect network metrics for %s: %Rrc (%d). ", mInterfaceName.c_str(), mRc, mRc));671 LogRel(("Failed to collect network metrics for %s: %Rrc (%d).\n", mInterfaceName.c_str(), mRc, mRc)); 673 672 mRc = VINF_SUCCESS; 674 673 } … … 678 677 void HostNetworkLoadRaw::collect() 679 678 { 680 uint64_t rx, tx , speed;681 682 mRc = mHAL->getRawHostNetworkLoad(mInterfaceName.c_str(), &rx, &tx , &speed);679 uint64_t rx, tx; 680 681 mRc = mHAL->getRawHostNetworkLoad(mInterfaceName.c_str(), &rx, &tx); 683 682 if (RT_SUCCESS(mRc)) 684 683 { … … 686 685 uint64_t txDiff = tx - mTxPrev; 687 686 688 if (RT_UNLIKELY( speed * getPeriod() == 0))689 { 690 Assert( speed * getPeriod());691 LogFlowThisFunc(("Impossible! speed=%llu period=%d.\n", speed, getPeriod()));687 if (RT_UNLIKELY(mSpeed * getPeriod() == 0)) 688 { 689 Assert(mSpeed * getPeriod()); 690 LogFlowThisFunc(("Impossible! speed=%llu period=%d.\n", mSpeed, getPeriod())); 692 691 mRx->put(0); 693 692 mTx->put(0); … … 695 694 else 696 695 { 697 mRx->put((ULONG)(PM_NETWORK_LOAD_MULTIPLIER * rxDiff / ( speed * getPeriod())));698 mTx->put((ULONG)(PM_NETWORK_LOAD_MULTIPLIER * txDiff / ( speed * getPeriod())));696 mRx->put((ULONG)(PM_NETWORK_LOAD_MULTIPLIER * rxDiff / (mSpeed * getPeriod()))); 697 mTx->put((ULONG)(PM_NETWORK_LOAD_MULTIPLIER * txDiff / (mSpeed * getPeriod()))); 699 698 } 700 699 -
trunk/src/VBox/Main/src-server/generic/NetIf-generic.cpp
r42994 r43507 77 77 Utf8Str strName(interfaceName); 78 78 return NetIfAdpCtl(strName.c_str(), pszAddr, pszOption, pszMask); 79 } 80 81 int NetIfAdpCtlOut(const char * pcszName, const char * pcszCmd, char *pszBuffer, size_t cBufSize) 82 { 83 char szAdpCtl[RTPATH_MAX]; 84 int rc = RTPathExecDir(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME " ") - strlen(pcszCmd)); 85 if (RT_FAILURE(rc)) 86 { 87 LogRel(("NetIfAdpCtlStream: Failed to get program path, rc=%Rrc\n", rc)); 88 return VERR_INVALID_PARAMETER; 89 } 90 strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " "); 91 if (pcszName && strlen(pcszName) <= RTPATH_MAX - strlen(szAdpCtl) - 1 - strlen(pcszCmd)) 92 { 93 strcat(szAdpCtl, pcszName); 94 strcat(szAdpCtl, " "); 95 strcat(szAdpCtl, pcszCmd); 96 } 97 else 98 { 99 LogRel(("NetIfAdpCtlStream: Command line is too long: %s%s %s\n", szAdpCtl, pcszName, pcszCmd)); 100 return VERR_INVALID_PARAMETER; 101 } 102 if (strlen(szAdpCtl) < RTPATH_MAX - sizeof(" 2>&1")) 103 strcat(szAdpCtl, " 2>&1"); 104 FILE *fp = popen(szAdpCtl, "r"); 105 if (fp) 106 { 107 if (fgets(pszBuffer, cBufSize, fp)) 108 { 109 if (!strncmp(VBOXNETADPCTL_NAME ":", pszBuffer, sizeof(VBOXNETADPCTL_NAME))) 110 { 111 LogRel(("NetIfAdpCtlStream: %s", pszBuffer)); 112 rc = VERR_INTERNAL_ERROR; 113 } 114 } 115 else 116 { 117 LogRel(("NetIfAdpCtlStream: No output from " VBOXNETADPCTL_NAME)); 118 rc = VERR_INTERNAL_ERROR; 119 } 120 pclose(fp); 121 } 122 return rc; 79 123 } 80 124 -
trunk/src/VBox/Main/src-server/linux/NetIf-linux.cpp
r33540 r43507 149 149 fclose(fp); 150 150 } 151 /* 152 * I wish I could do simple ioctl here, but older kernels require root 153 * privileges for any ethtool commands. 154 */ 155 char szBuf[256]; 156 /* First, we try to retrieve the speed via sysfs. */ 157 RTStrPrintf(szBuf, sizeof(szBuf), "/sys/class/net/%s/speed", pszName); 158 fp = fopen(szBuf, "r"); 159 if (fp && fscanf(fp, "%u", &pInfo->uSpeedMbytes) == 1) 160 fclose(fp); 161 else 162 { 163 /* Failed to get speed via sysfs, go to plan B. */ 164 int rc = NetIfAdpCtlOut(pszName, "info", szBuf, sizeof(szBuf)); 165 if (RT_SUCCESS(rc)) 166 { 167 pInfo->uSpeedMbytes = RTStrToUInt32(szBuf); 168 } 169 else 170 return rc; 171 } 151 172 } 152 173 return VINF_SUCCESS; -
trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp
r43445 r43507 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 virtual int getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx); 43 43 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total); 44 44 private: … … 218 218 } 219 219 220 int CollectorLinux::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx , uint64_t *speed)220 int CollectorLinux::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx) 221 221 { 222 222 int rc = VINF_SUCCESS; … … 242 242 rc = VERR_FILE_IO_ERROR; 243 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 else251 rc = VERR_FILE_IO_ERROR;252 fclose(f);253 }254 else255 rc = VERR_ACCESS_DENIED;256 244 } 257 245 else -
trunk/src/VBox/Main/testcase/tstCollector.cpp
r43445 r43507 145 145 { 146 146 pm::CollectorHints hints; 147 uint64_t hostRxStart, hostTxStart , speedStart;148 uint64_t hostRxStop, hostTxStop, speed Stop;147 uint64_t hostRxStart, hostTxStart; 148 uint64_t hostRxStop, hostTxStop, speed = 125000000; /* Assume 1Gbit/s */ 149 149 150 150 RTPrintf("\ntstCollector: TESTING - Network load, sleeping for 5 sec...\n"); … … 156 156 return 1; 157 157 } 158 rc = collector->getRawHostNetworkLoad("eth0", &hostRxStart, &hostTxStart , &speedStart);158 rc = collector->getRawHostNetworkLoad("eth0", &hostRxStart, &hostTxStart); 159 159 if (RT_FAILURE(rc)) 160 160 { … … 171 171 return 1; 172 172 } 173 rc = collector->getRawHostNetworkLoad("eth0", &hostRxStop, &hostTxStop , &speedStop);173 rc = collector->getRawHostNetworkLoad("eth0", &hostRxStop, &hostTxStop); 174 174 if (RT_FAILURE(rc)) 175 175 { … … 177 177 return 1; 178 178 } 179 if (speedStart != speedStop)180 RTPrintf("tstCollector: getRawHostNetworkLoad() returned different bandwidth (%llu != %llu)\n", speedStart, speedStop);181 179 RTPrintf("tstCollector: host network speed = %llu bytes/sec (%llu mbit/sec)\n", 182 speed Stop, speedStop/(1000000/8));180 speed, speed/(1000000/8)); 183 181 RTPrintf("tstCollector: host network rx = %llu bytes/sec (%llu mbit/sec, %d %%*100)\n", 184 182 (hostRxStop - hostRxStart)/5, (hostRxStop - hostRxStart)/(5000000/8), 185 (hostRxStop - hostRxStart) * 10000 / (speed Stop* 5));183 (hostRxStop - hostRxStart) * 10000 / (speed * 5)); 186 184 RTPrintf("tstCollector: host network tx = %llu bytes/sec (%llu mbit/sec, %d %%*100)\n", 187 185 (hostTxStop - hostTxStart)/5, (hostTxStop - hostTxStart)/(5000000/8), 188 (hostTxStop - hostTxStart) * 10000 / (speed Stop* 5));186 (hostTxStop - hostTxStart) * 10000 / (speed * 5)); 189 187 190 188 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.