PerformanceWin.cpp revision e6e249a765867ec61336e3c64c3fee1845a67857
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/* $Id$ */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/** @file
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * VBox Windows-specific Performance Classes implementation.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync */
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync/*
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * available from http://www.virtualbox.org. This file is free software;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * General Public License (GPL) as published by the Free Software
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync * additional information or have any questions.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync */
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync#include <Wbemidl.h>
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncextern "C" {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync#include <powrprof.h>
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync#include <iprt/err.h>
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync#include <iprt/mp.h>
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync#include "Logging.h"
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync#include "Performance.h"
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncnamespace pm {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncclass CollectorWin : public CollectorHAL
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncpublic:
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync CollectorWin();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ~CollectorWin();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync virtual int getHostCpuMHz(ULONG *mhz);
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
43747b1f0bc8302a238fb35e55857a5e9aa1933dvboxsync virtual int getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncprivate:
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long getPropertyHandle(IWbemObjectAccess *objAccess, LPCWSTR name);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync int getObjects(IWbemHiPerfEnum *mEnum, IWbemObjectAccess ***objArray, DWORD *numReturned);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemRefresher *mRefresher;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemServices *mNameSpace;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemHiPerfEnum *mEnumProcessor;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mEnumProcessorID;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mHostCpuLoadNameHandle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mHostCpuLoadUserHandle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mHostCpuLoadKernelHandle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mHostCpuLoadIdleHandle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemHiPerfEnum *mEnumProcess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mEnumProcessID;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mProcessPIDHandle;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync long mProcessCpuLoadUserHandle;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync long mProcessCpuLoadKernelHandle;
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync long mProcessCpuLoadTimestampHandle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long mProcessMemoryUsedHandle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync};
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncMetricFactoryWin::MetricFactoryWin()
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync mHAL = new CollectorWin();
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync Assert(mHAL);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncCollectorWin::CollectorWin() : mRefresher(0), mNameSpace(0), mEnumProcessor(0), mEnumProcess(0)
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync HRESULT hr = S_OK;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemConfigureRefresher *pConfig = NULL;
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync IWbemLocator *pWbemLocator = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync BSTR bstrNameSpace = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (SUCCEEDED (hr = CoCreateInstance(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync CLSID_WbemLocator,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync CLSCTX_INPROC_SERVER,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IID_IWbemLocator,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync (void**) &pWbemLocator)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync // Connect to the desired namespace.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync bstrNameSpace = SysAllocString(L"\\\\.\\root\\cimv2");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (bstrNameSpace)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync hr = pWbemLocator->ConnectServer(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync bstrNameSpace,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL, // User name
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL, // Password
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL, // Locale
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync 0L, // Security flags
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL, // Authority
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL, // Wbem context
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &mNameSpace);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync pWbemLocator->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync SysFreeString(bstrNameSpace);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr)) {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to get namespace. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (SUCCEEDED (hr = CoCreateInstance(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync CLSID_WbemRefresher,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync CLSCTX_INPROC_SERVER,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IID_IWbemRefresher,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync (void**) &mRefresher)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (SUCCEEDED (hr = mRefresher->QueryInterface(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IID_IWbemConfigureRefresher,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync (void **)&pConfig)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync // Add an enumerator to the refresher.
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (SUCCEEDED (hr = pConfig->AddEnum(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mNameSpace,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync L"Win32_PerfRawData_PerfOS_Processor",
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync 0,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &mEnumProcessor,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &mEnumProcessorID)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync hr = pConfig->AddEnum(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mNameSpace,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync L"Win32_PerfRawData_PerfProc_Process",
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync 0,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync NULL,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &mEnumProcess,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &mEnumProcessID);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync pConfig->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync if (FAILED (hr)) {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to add enumerators. HR = %x\n", hr));
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync return;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync // Retrieve property handles
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = mRefresher->Refresh(0L)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Refresher failed. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemObjectAccess **apEnumAccess = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync DWORD dwNumReturned = 0;
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (RT_FAILURE(getObjects(mEnumProcessor, &apEnumAccess, &dwNumReturned)))
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync return;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadNameHandle = getPropertyHandle(apEnumAccess[0], L"Name");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadUserHandle = getPropertyHandle(apEnumAccess[0], L"PercentUserTime");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadKernelHandle = getPropertyHandle(apEnumAccess[0], L"PercentPrivilegedTime");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadIdleHandle = getPropertyHandle(apEnumAccess[0], L"PercentProcessorTime");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync delete [] apEnumAccess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (RT_FAILURE(getObjects(mEnumProcess, &apEnumAccess, &dwNumReturned)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mProcessPIDHandle = getPropertyHandle(apEnumAccess[0], L"IDProcess");
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync mProcessCpuLoadUserHandle = getPropertyHandle(apEnumAccess[0], L"PercentUserTime");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mProcessCpuLoadKernelHandle = getPropertyHandle(apEnumAccess[0], L"PercentPrivilegedTime");
25747178cb66800d8386c20b8ffd87f78f24f4e5vboxsync mProcessCpuLoadTimestampHandle = getPropertyHandle(apEnumAccess[0], L"Timestamp_Sys100NS");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mProcessMemoryUsedHandle = getPropertyHandle(apEnumAccess[0], L"WorkingSet");
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync delete [] apEnumAccess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncCollectorWin::~CollectorWin()
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (NULL != mNameSpace)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mNameSpace->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (NULL != mEnumProcessor)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mEnumProcessor->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (NULL != mEnumProcess)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mEnumProcess->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (NULL != mRefresher)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mRefresher->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsynclong CollectorWin::getPropertyHandle(IWbemObjectAccess *objAccess, LPCWSTR name)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync HRESULT hr;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync CIMTYPE tmp;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long handle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = objAccess->GetPropertyHandle(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync name,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &tmp,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &handle)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to get property handle for '%ls'. HR = %x\n", name, hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return 0; /// @todo use throw
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return handle;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsyncint CollectorWin::getObjects(IWbemHiPerfEnum *mEnum, IWbemObjectAccess ***objArray, DWORD *numReturned)
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync{
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync HRESULT hr;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync DWORD dwNumObjects = 0;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync *objArray = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *numReturned = 0;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync hr = mEnum->GetObjects(0L, dwNumObjects, *objArray, numReturned);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync // If the buffer was not big enough,
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync // allocate a bigger buffer and retry.
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync if (hr == WBEM_E_BUFFER_TOO_SMALL
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync && *numReturned > dwNumObjects)
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync {
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync *objArray = new IWbemObjectAccess*[*numReturned];
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync if (NULL == *objArray)
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync {
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync Log (("Could not allocate enumerator access objects\n"));
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync return VERR_NO_MEMORY;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync }
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync SecureZeroMemory(*objArray,
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync *numReturned*sizeof(IWbemObjectAccess*));
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync dwNumObjects = *numReturned;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync if (FAILED (hr = mEnum->GetObjects(0L,
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync dwNumObjects, *objArray, numReturned)))
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync {
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync delete [] objArray;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync Log (("Failed to get objects from enumerator. HR = %x\n", hr));
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync return VERR_INTERNAL_ERROR;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync }
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync else if (FAILED (hr))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync Log (("Failed to get objects from enumerator. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync }
4fcfe0bd966753617b7ab5fb81fb24709914fc1cvboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VINF_SUCCESS;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncint CollectorWin::getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_NOT_IMPLEMENTED;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncint CollectorWin::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync HRESULT hr;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemObjectAccess **apEnumAccess = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync DWORD dwNumReturned = 0;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFuncEnter();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = mRefresher->Refresh(0L)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Refresher failed. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync int rc = getObjects(mEnumProcessor, &apEnumAccess, &dwNumReturned);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (RT_FAILURE(rc))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return rc;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync for (unsigned i = 0; i < dwNumReturned; i++)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync long bytesRead = 0;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync WCHAR tmpBuf[200];
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = apEnumAccess[i]->ReadPropertyValue(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadNameHandle,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync sizeof(tmpBuf),
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync &bytesRead,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync (byte*)tmpBuf)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to read 'Name' property. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (wcscmp(tmpBuf, L"_Total") == 0)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadUserHandle,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync user)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to read 'PercentUserTime' property. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadKernelHandle,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync kernel)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to read 'PercentPrivilegedTime' property. HR = %x\n", hr));
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync return VERR_INTERNAL_ERROR;
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mHostCpuLoadIdleHandle,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync idle)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to read 'PercentProcessorTime' property. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = VINF_SUCCESS;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync apEnumAccess[i]->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync apEnumAccess[i] = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync delete [] apEnumAccess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFunc(("user=%lu kernel=%lu idle=%lu\n", *user, *kernel, *idle));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFuncLeave();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return rc;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsynctypedef struct _PROCESSOR_POWER_INFORMATION {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ULONG Number;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ULONG MaxMhz;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ULONG CurrentMhz;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ULONG MhzLimit;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ULONG MaxIdleState;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync ULONG CurrentIdleState;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync} PROCESSOR_POWER_INFORMATION , *PPROCESSOR_POWER_INFORMATION;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncint CollectorWin::getHostCpuMHz(ULONG *mhz)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync uint64_t uTotalMhz = 0;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync RTCPUID nProcessors = RTMpGetCount();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync PPROCESSOR_POWER_INFORMATION ppi = new PROCESSOR_POWER_INFORMATION[nProcessors];
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LONG ns = CallNtPowerInformation(ProcessorInformation, NULL, 0, ppi,
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync nProcessors * sizeof(PROCESSOR_POWER_INFORMATION));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (ns)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log(("CallNtPowerInformation() -> %x\n", ns));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync /* Compute an average over all CPUs */
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync for (unsigned i = 0; i < nProcessors; i++)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync uTotalMhz += ppi[i].CurrentMhz;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *mhz = (ULONG)(uTotalMhz / nProcessors);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFunc(("mhz=%u\n", *mhz));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFuncLeave();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VINF_SUCCESS;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncint CollectorWin::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync MEMORYSTATUSEX mstat;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mstat.dwLength = sizeof(mstat);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (GlobalMemoryStatusEx(&mstat))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *total = (ULONG)( mstat.ullTotalPhys / 1000 );
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *available = (ULONG)( mstat.ullAvailPhys / 1000 );
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync *used = *total - *available;
a7d402dcc23137e7b9527be6de80400043a5fbf4vboxsync }
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync else
a7d402dcc23137e7b9527be6de80400043a5fbf4vboxsync return RTErrConvertFromWin32(GetLastError());
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync return VINF_SUCCESS;
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync}
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsyncint CollectorWin::getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_NOT_IMPLEMENTED;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsyncint CollectorWin::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync HRESULT hr;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync IWbemObjectAccess **apEnumAccess = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync DWORD dwNumReturned = 0;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFuncEnter();
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = mRefresher->Refresh(0L)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync Log (("Refresher failed. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync int rc = getObjects(mEnumProcess, &apEnumAccess, &dwNumReturned);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync if (RT_FAILURE(rc))
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync return rc;
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync rc = VERR_NOT_FOUND;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync for (unsigned i = 0; i < dwNumReturned; i++)
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync DWORD dwIDProcess;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync if (FAILED (hr = apEnumAccess[i]->ReadDWORD(
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync mProcessPIDHandle,
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync &dwIDProcess)))
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync Log (("Failed to read 'IDProcess' property. HR = %x\n", hr));
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync return VERR_INTERNAL_ERROR;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync }
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync LogFlowThisFunc (("Matching machine process %x against %x...\n", process, dwIDProcess));
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync if (dwIDProcess == process)
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync LogFlowThisFunc (("Match found.\n"));
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync mProcessCpuLoadUserHandle,
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync user)))
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync Log (("Failed to read 'PercentUserTime' property. HR = %x\n", hr));
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync return VERR_INTERNAL_ERROR;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync }
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync mProcessCpuLoadKernelHandle,
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync kernel)))
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync Log (("Failed to read 'PercentPrivilegedTime' property. HR = %x\n", hr));
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync return VERR_INTERNAL_ERROR;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync }
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync mProcessCpuLoadTimestampHandle,
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync total)))
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync {
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync Log (("Failed to read 'Timestamp_Sys100NS' property. HR = %x\n", hr));
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync return VERR_INTERNAL_ERROR;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync }
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync rc = VINF_SUCCESS;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync }
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync apEnumAccess[i]->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync apEnumAccess[i] = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
cad8876b46f9e366c4a1007a40c27ca1df078950vboxsync delete [] apEnumAccess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFunc(("user=%lu kernel=%lu total=%lu\n", *user, *kernel, *total));
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync LogFlowThisFuncLeave();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return rc;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsyncint CollectorWin::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync{
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync HRESULT hr;
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync IWbemObjectAccess **apEnumAccess = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync DWORD dwNumReturned = 0;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFuncEnter();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync if (FAILED (hr = mRefresher->Refresh(0L)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Refresher failed. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync int rc = getObjects(mEnumProcess, &apEnumAccess, &dwNumReturned);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (RT_FAILURE(rc))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return rc;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = VERR_NOT_FOUND;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync for (unsigned i = 0; i < dwNumReturned; i++)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync DWORD dwIDProcess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = apEnumAccess[i]->ReadDWORD(
787c7e6ef15f993c455c374f5158e7bb753b1c33vboxsync mProcessPIDHandle,
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync &dwIDProcess)))
fbf08fabb4c4b383d6aa2830c2bd5b943a26f10cvboxsync {
a7d402dcc23137e7b9527be6de80400043a5fbf4vboxsync Log (("Failed to read 'IDProcess' property. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (dwIDProcess == process)
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync uint64_t u64used = 0;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync if (FAILED (hr = apEnumAccess[i]->ReadQWORD(
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync mProcessMemoryUsedHandle,
c28fa006ba669ad8f26ae31d00a338379c04ea1bvboxsync &u64used)))
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync {
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync Log (("Failed to read 'WorkingSet' property. HR = %x\n", hr));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return VERR_INTERNAL_ERROR;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync *used = (ULONG)(u64used / 1024);
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync rc = VINF_SUCCESS;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync apEnumAccess[i]->Release();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync apEnumAccess[i] = NULL;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync }
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync delete [] apEnumAccess;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFunc(("used=%lu\n", *used));
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync LogFlowThisFuncLeave();
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync return rc;
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync}
24ab761b2beb5af0393c6f2585b6351d8b3085f0vboxsync