diff options
author | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-09 06:57:28 +0000 |
---|---|---|
committer | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-09 06:57:28 +0000 |
commit | ed26d948be84443236a8a165ac2a3ccf63c2e02a (patch) | |
tree | a41de5ad3954557cbf9a7b0e1bc61c923fc05269 /base/process_util_win.cc | |
parent | ad33fd4bdd8b7117e2644b34f553a2f14faea653 (diff) | |
download | chromium_src-ed26d948be84443236a8a165ac2a3ccf63c2e02a.zip chromium_src-ed26d948be84443236a8a165ac2a3ccf63c2e02a.tar.gz chromium_src-ed26d948be84443236a8a165ac2a3ccf63c2e02a.tar.bz2 |
More memory stats code cleanup:
Move GetSystemCommitCharge() into bsae\process_util*.
Kill PrintChromeMemoryUsageInfo(), which was only used by
reliability_tests.exe on Windows and whose stats are obsolete.
Delete the now-unnecessary chrome\test\perf\mem_usage* files.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/371025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31423 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_win.cc')
-rw-r--r-- | base/process_util_win.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/base/process_util_win.cc b/base/process_util_win.cc index f6157db..18de37f 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -799,4 +799,43 @@ void RaiseProcessToHighPriority() { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); } +// 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); + +// Beware of races if called concurrently from multiple threads. +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); + + PERFORMANCE_INFORMATION info; + if (! InternalGetPerformanceInfo(&info, sizeof(info))) { + LOG(ERROR) << "Failed to fetch internal performance info."; + return 0; + } + return (info.CommitTotal * system_info.dwPageSize) / 1024; +} + } // namespace base |