VirtualBox

Ignore:
Timestamp:
Oct 11, 2012 1:59:10 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81331
Message:

Main/Metrics: Fixes for Solaris network metrics (#6345)

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  
    4848#include <net/if.h>
    4949#include <sys/types.h>
     50#include <kstat.h>
    5051
    5152#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         else
    77             LogFlowFunc(("fgets returned nothing\n"));
    78         fclose(fp);
    79     }
    80     return uSpeed;
    81 }
    8253
    8354static uint32_t getInstance(const char *pszIfaceName, char *pszDevName)
     
    10374}
    10475
     76static 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
    105112static void queryIfaceSpeed(PNETIFINFO pInfo)
    106113{
    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 */
    123115}
    124116
  • trunk/src/VBox/Main/src-server/solaris/PerformanceSolaris.cpp

    r43538 r43618  
    289289{
    290290    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);
    292293    if (ksAdapter == 0)
    293294    {
    294295        char szModule[KSTAT_STRLEN];
    295296        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");
    297299        if (ksAdapter == 0)
    298300        {
    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            }
    301308        }
    302309    }
     
    309316    if ((kn = (kstat_named_t *)kstat_data_lookup(ksAdapter, (char *)"rbytes")) == 0)
    310317    {
    311         LogRel(("kstat_data_lookup(rbytes) -> %d\n", errno));
     318        LogRel(("kstat_data_lookup(rbytes) -> %d, name=%s\n", errno, name));
    312319        return VERR_INTERNAL_ERROR;
    313320    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette