From ed26d948be84443236a8a165ac2a3ccf63c2e02a Mon Sep 17 00:00:00 2001 From: "sgk@chromium.org" Date: Mon, 9 Nov 2009 06:57:28 +0000 Subject: 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 --- base/process_util_win.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'base/process_util_win.cc') 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( + 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 -- cgit v1.1