VirtualBox

Ignore:
Timestamp:
Oct 2, 2012 1:22:31 PM (12 years ago)
Author:
vboxsync
Message:

Main/Metrics: Alternative way to get link speed for old kernels (#6345)

Location:
trunk/src/VBox/Main/src-server/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/NetIf-linux.cpp

    r33540 r43507  
    149149            fclose(fp);
    150150        }
     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        }
    151172    }
    152173    return VINF_SUCCESS;
  • trunk/src/VBox/Main/src-server/linux/PerformanceLinux.cpp

    r43445 r43507  
    4040
    4141    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);
    4343    virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
    4444private:
     
    218218}
    219219
    220 int CollectorLinux::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx, uint64_t *speed)
     220int CollectorLinux::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx)
    221221{
    222222    int rc = VINF_SUCCESS;
     
    242242                rc = VERR_FILE_IO_ERROR;
    243243            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;
    256244        }
    257245        else
Note: See TracChangeset for help on using the changeset viewer.

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