VirtualBox

Changeset 11467 in vbox for trunk/src/VBox/Main/win


Ignore:
Timestamp:
Aug 18, 2008 2:52:12 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
34921
Message:

Perf API: CPU/MHz counter re-introduced (Win implementation).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/win/PerformanceWin.cpp

    r11180 r11467  
    2323
    2424#include <Wbemidl.h>
     25extern "C" {
     26#include <powrprof.h>
     27}
    2528#include <iprt/err.h>
     29#include <iprt/mp.h>
    2630
    2731#include "Logging.h"
     
    334338}
    335339
     340typedef struct _PROCESSOR_POWER_INFORMATION {
     341  ULONG  Number;
     342  ULONG  MaxMhz;
     343  ULONG  CurrentMhz;
     344  ULONG  MhzLimit;
     345  ULONG  MaxIdleState;
     346  ULONG  CurrentIdleState;
     347} PROCESSOR_POWER_INFORMATION , *PPROCESSOR_POWER_INFORMATION;
     348
    336349int CollectorWin::getHostCpuMHz(ULONG *mhz)
    337350{
    338     return VERR_NOT_IMPLEMENTED;
     351    uint64_t uTotalMhz   = 0;
     352    RTCPUID  nProcessors = RTMpGetCount();
     353    PPROCESSOR_POWER_INFORMATION ppi = new PROCESSOR_POWER_INFORMATION[nProcessors];
     354    LONG ns = CallNtPowerInformation(ProcessorInformation, NULL, 0, ppi,
     355        nProcessors * sizeof(PROCESSOR_POWER_INFORMATION));
     356    if (ns)
     357    {
     358        Log(("CallNtPowerInformation() -> %x\n", ns));
     359        return VERR_INTERNAL_ERROR;
     360    }
     361
     362    /* Compute an average over all CPUs */
     363    for (unsigned i = 0; i < nProcessors;  i++)
     364        uTotalMhz += ppi[i].CurrentMhz;
     365    *mhz = (ULONG)(uTotalMhz / nProcessors);
     366
     367    LogFlowThisFunc(("mhz=%u\n", *mhz));
     368    LogFlowThisFuncLeave();
     369
     370    return VINF_SUCCESS;
    339371}
    340372
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