Changeset 43618 in vbox for trunk/src/VBox/Main/src-server/solaris
- Timestamp:
- Oct 11, 2012 1:59:10 PM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 81331
- Location:
- trunk/src/VBox/Main/src-server/solaris
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/solaris/NetIf-solaris.cpp
r43541 r43618 48 48 #include <net/if.h> 49 49 #include <sys/types.h> 50 #include <kstat.h> 50 51 51 52 #include "DynLoadLibSolaris.h" 52 53 static uint64_t kstatGet(const char *pszMask)54 {55 char szBuf[RTPATH_MAX];56 RTStrPrintf(szBuf, sizeof(szBuf),57 "/usr/bin/kstat -c net -p %s", pszMask);58 uint64_t uSpeed = 0;59 FILE *fp = popen(szBuf, "r");60 LogFlowFunc(("popen(%s) returned %p\n", szBuf, fp));61 if (fp)62 {63 if (fgets(szBuf, sizeof(szBuf), fp))64 {65 LogFlowFunc(("fgets returned %s\n", szBuf));66 char *pszDigit = szBuf;67 /* Skip the id string */68 int i = 0;69 while (i++ < sizeof(szBuf) && *pszDigit && !RT_C_IS_SPACE(*pszDigit))70 pszDigit++;71 while (i++ < sizeof(szBuf) && *pszDigit && !RT_C_IS_DIGIT(*pszDigit))72 pszDigit++;73 LogFlowFunc(("located number %s\n", pszDigit));74 uSpeed = RTStrToUInt64(pszDigit);75 }76 else77 LogFlowFunc(("fgets returned nothing\n"));78 fclose(fp);79 }80 return uSpeed;81 }82 53 83 54 static uint32_t getInstance(const char *pszIfaceName, char *pszDevName) … … 103 74 } 104 75 76 static uint64_t kstatGet(const char *name) 77 { 78 kstat_ctl_t *kc; 79 uint64_t uSpeed = 0; 80 81 if ((kc = kstat_open()) == 0) 82 { 83 LogRel(("kstat_open() -> %d\n", errno)); 84 return 0; 85 } 86 87 kstat_t *ksAdapter = kstat_lookup(kc, "link", -1, (char *)name); 88 if (ksAdapter == 0) 89 { 90 char szModule[KSTAT_STRLEN]; 91 uint32_t uInstance = getInstance(name, szModule); 92 ksAdapter = kstat_lookup(kc, szModule, uInstance, "phys"); 93 if (ksAdapter == 0) 94 ksAdapter = kstat_lookup(kc, szModule, uInstance, name); 95 } 96 if (ksAdapter == 0) 97 LogRel(("Failed to get network statistics for %s\n", name)); 98 else if (kstat_read(kc, ksAdapter, 0) == -1) 99 LogRel(("kstat_read(%s) -> %d\n", name, errno)); 100 else 101 { 102 kstat_named_t *kn; 103 if ((kn = (kstat_named_t *)kstat_data_lookup(ksAdapter, (char *)"ifspeed")) == 0) 104 LogRel(("kstat_data_lookup(ifspeed) -> %d, name=%s\n", errno, name)); 105 else 106 uSpeed = kn->value.ul; 107 } 108 kstat_close(kc); 109 return uSpeed; 110 } 111 105 112 static void queryIfaceSpeed(PNETIFINFO pInfo) 106 113 { 107 char szMask[RTPATH_MAX]; 108 RTStrPrintf(szMask, sizeof(szMask), "*:*:%s:ifspeed", pInfo->szShortName); 109 uint64_t uSpeed = kstatGet(szMask); 110 if (uSpeed == 0) 111 { 112 Log(("queryIfaceSpeed: failed to get speed for %s via kstat(%s)\n", pInfo->szShortName, szMask)); 113 /* Lets try module:instance approach */ 114 char szDevName[sizeof(pInfo->szShortName)]; 115 uint32_t uInstance = getInstance(pInfo->szShortName, szDevName); 116 RTStrPrintf(szMask, sizeof(szMask), "%s:%u:*:ifspeed", 117 szDevName, uInstance); 118 uSpeed = kstatGet(szMask); 119 if (uSpeed == 0) 120 LogRel(("queryIfaceSpeed: failed to get speed for %s(instance=%u) via kstat\n", szDevName, uInstance)); 121 } 122 pInfo->uSpeedMbits = uSpeed / 1000000; /* bits -> Mbits */ 114 pInfo->uSpeedMbits = kstatGet(pInfo->szShortName) / 1000000; /* bits -> Mbits */ 123 115 } 124 116 -
trunk/src/VBox/Main/src-server/solaris/PerformanceSolaris.cpp
r43538 r43618 289 289 { 290 290 AssertReturn(strlen(name) < KSTAT_STRLEN, VERR_INVALID_PARAMETER); 291 kstat_t *ksAdapter = kstat_lookup(mKC, NULL, -1, (char *)name); 291 LogFlowThisFunc(("m=%s i=%d n=%s\n", "link", -1, name)); 292 kstat_t *ksAdapter = kstat_lookup(mKC, "link", -1, (char *)name); 292 293 if (ksAdapter == 0) 293 294 { 294 295 char szModule[KSTAT_STRLEN]; 295 296 uint32_t uInstance = getInstance(name, szModule); 296 ksAdapter = kstat_lookup(mKC, szModule, uInstance, NULL); 297 LogFlowThisFunc(("m=%s i=%u n=%s\n", szModule, uInstance, "phys")); 298 ksAdapter = kstat_lookup(mKC, szModule, uInstance, "phys"); 297 299 if (ksAdapter == 0) 298 300 { 299 LogRel(("Failed to get network statistics for %s\n", name)); 300 return VERR_INTERNAL_ERROR; 301 LogFlowThisFunc(("m=%s i=%u n=%s\n", szModule, uInstance, name)); 302 ksAdapter = kstat_lookup(mKC, szModule, uInstance, name); 303 if (ksAdapter == 0) 304 { 305 LogRel(("Failed to get network statistics for %s\n", name)); 306 return VERR_INTERNAL_ERROR; 307 } 301 308 } 302 309 } … … 309 316 if ((kn = (kstat_named_t *)kstat_data_lookup(ksAdapter, (char *)"rbytes")) == 0) 310 317 { 311 LogRel(("kstat_data_lookup(rbytes) -> %d \n", errno));318 LogRel(("kstat_data_lookup(rbytes) -> %d, name=%s\n", errno, name)); 312 319 return VERR_INTERNAL_ERROR; 313 320 }
Note:
See TracChangeset
for help on using the changeset viewer.