diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-06 19:43:29 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-06 19:43:29 +0000 |
commit | a4930c88e7fb14ba66340cbe393fcdf4c668e41c (patch) | |
tree | 061aae4a4bd9d784ac4d93896dc45c8efd7d6471 /chrome | |
parent | 19094aa357eae51bf7e5a8664092d9b8efd289fa (diff) | |
download | chromium_src-a4930c88e7fb14ba66340cbe393fcdf4c668e41c.zip chromium_src-a4930c88e7fb14ba66340cbe393fcdf4c668e41c.tar.gz chromium_src-a4930c88e7fb14ba66340cbe393fcdf4c668e41c.tar.bz2 |
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
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/test/perf/mem_usage.cc | 33 |
1 files changed, 29 insertions, 4 deletions
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<GetPerformanceInfoFunction>( + 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; } |