From a4930c88e7fb14ba66340cbe393fcdf4c668e41c Mon Sep 17 00:00:00 2001 From: "mbelshe@google.com" Date: Wed, 6 Aug 2008 19:43:29 +0000 Subject: Don't link directly against GetPerformanceInfo so that win2k can be happy. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@449 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/test/perf/mem_usage.cc | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'chrome') diff --git a/chrome/test/perf/mem_usage.cc b/chrome/test/perf/mem_usage.cc index c0c4e4d..a10e7cb 100644 --- a/chrome/test/perf/mem_usage.cc +++ b/chrome/test/perf/mem_usage.cc @@ -66,15 +66,40 @@ bool GetMemoryInfo(uint32 process_id, return result; } +// GetPerformanceInfo is not available on WIN2K. So we'll +// load it on-the-fly. +const wchar_t kPsapiDllName[] = L"psapi.dll"; +typedef BOOL (WINAPI *GetPerformanceInfoFunction) ( + PPERFORMANCE_INFORMATION pPerformanceInformation, + DWORD cb); + +static BOOL InternalGetPerformanceInfo( + PPERFORMANCE_INFORMATION pPerformanceInformation, DWORD cb) { + static GetPerformanceInfoFunction GetPerformanceInfo_func = NULL; + if (!GetPerformanceInfo_func) { + HMODULE psapi_dll = ::GetModuleHandle(kPsapiDllName); + if (psapi_dll) + GetPerformanceInfo_func = reinterpret_cast( + GetProcAddress(psapi_dll, "GetPerformanceInfo")); + + if (!GetPerformanceInfo_func) { + // The function could be loaded! + memset(pPerformanceInformation, 0, cb); + return FALSE; + } + } + return GetPerformanceInfo_func(pPerformanceInformation, cb); +} + + size_t GetSystemCommitCharge() { // Get the System Page Size. SYSTEM_INFO system_info; GetSystemInfo(&system_info); - // TODO(mbelshe): This does not work on win2k. - // PERFORMANCE_INFORMATION info; - // if (GetPerformanceInfo(&info, sizeof(info))) - // return info.CommitTotal * system_info.dwPageSize; + PERFORMANCE_INFORMATION info; + if (InternalGetPerformanceInfo(&info, sizeof(info))) + return info.CommitTotal * system_info.dwPageSize; return -1; } -- cgit v1.1