VirtualBox

Changeset 56457 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Jun 16, 2015 4:03:13 PM (10 years ago)
Author:
vboxsync
Message:

Additions/VBoxService: properly report the CPU load of each VCPU

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp

    r56390 r56457  
    214214
    215215    /* Unfortunately GetSystemTimes is XP SP1 and up only, so we need to use the semi-undocumented NtQuerySystemInformation */
     216    bool fCpuInfoAvail = false;
    216217    NTSTATUS rc = gCtx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned);
    217218    if (    !rc
    218219        &&  cbReturned == cbStruct)
    219220    {
    220         for (uint32_t i = 0; i < systemInfo.dwNumberOfProcessors && i < VMM_MAX_CPU_COUNT; i++)
    221         {
     221        for (uint32_t i = 0; i < systemInfo.dwNumberOfProcessors; i++)
     222        {
     223            if (i >= VMM_MAX_CPU_COUNT)
     224            {
     225                VBoxServiceVerbose(3, "VBoxStatsReportStatistics: skipping information for CPU%u\n", i);
     226                continue;
     227            }
     228
    222229            if (gCtx.au64LastCpuLoad_Kernel[i] == 0)
    223230            {
     
    246253
    247254            req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER;
    248 
    249             gCtx.au64LastCpuLoad_Idle[i]   = pProcInfo[i].IdleTime.QuadPart;
    250             gCtx.au64LastCpuLoad_Kernel[i] = pProcInfo[i].KernelTime.QuadPart;
    251             gCtx.au64LastCpuLoad_User[i]   = pProcInfo[i].UserTime.QuadPart;
    252         }
    253     }
    254     RTMemFree(pProcInfo);
    255 
    256     for (uint32_t i = 0; i < systemInfo.dwNumberOfProcessors; i++)
    257     {
    258         if (i < VMM_MAX_CPU_COUNT)
    259         {
    260255            req.guestStats.u32CpuId = i;
    261256            rc = VbglR3StatReport(&req);
     
    264259            else
    265260                VBoxServiceVerbose(3, "VBoxStatsReportStatistics: DeviceIoControl (stats report) failed with %d\n", GetLastError());
    266         }
    267         else
    268             VBoxServiceVerbose(3, "VBoxStatsReportStatistics: skipping information for CPU%u\n", i);
     261
     262            gCtx.au64LastCpuLoad_Idle[i]   = pProcInfo[i].IdleTime.QuadPart;
     263            gCtx.au64LastCpuLoad_Kernel[i] = pProcInfo[i].KernelTime.QuadPart;
     264            gCtx.au64LastCpuLoad_User[i]   = pProcInfo[i].UserTime.QuadPart;
     265        }
     266    }
     267    RTMemFree(pProcInfo);
     268
     269    if (!fCpuInfoAvail)
     270    {
     271        VBoxServiceVerbose(3, "VBoxStatsReportStatistics: CPU info not available!\n");
     272        rc = VbglR3StatReport(&req);
    269273    }
    270274
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