| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process/process_metrics.h" | 5 #include "base/process/process_metrics.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <psapi.h> | 8 #include <psapi.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <winternl.h> | 11 #include <winternl.h> |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/process/memory.h" | 17 #include "base/process/memory.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 | 19 |
| 20 #if defined(OS_WIN) |
| 21 #include <windows.h> |
| 22 #endif |
| 23 |
| 20 namespace base { | 24 namespace base { |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 // System pagesize. This value remains constant on x86/64 architectures. | 27 // System pagesize. This value remains constant on x86/64 architectures. |
| 24 const int PAGESIZE_KB = 4; | 28 const int PAGESIZE_KB = 4; |
| 25 | 29 |
| 26 typedef NTSTATUS(WINAPI* NTQUERYSYSTEMINFORMATION)( | 30 typedef NTSTATUS(WINAPI* NTQUERYSYSTEMINFORMATION)( |
| 27 SYSTEM_INFORMATION_CLASS SystemInformationClass, | 31 SYSTEM_INFORMATION_CLASS SystemInformationClass, |
| 28 PVOID SystemInformation, | 32 PVOID SystemInformation, |
| 29 ULONG SystemInformationLength, | 33 ULONG SystemInformationLength, |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return false; | 364 return false; |
| 361 | 365 |
| 362 meminfo->total = mem_status.ullTotalPhys / 1024; | 366 meminfo->total = mem_status.ullTotalPhys / 1024; |
| 363 meminfo->avail_phys = mem_status.ullAvailPhys / 1024; | 367 meminfo->avail_phys = mem_status.ullAvailPhys / 1024; |
| 364 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; | 368 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; |
| 365 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; | 369 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; |
| 366 | 370 |
| 367 return true; | 371 return true; |
| 368 } | 372 } |
| 369 | 373 |
| 374 size_t ProcessMetrics::GetMallocUsage() { |
| 375 // Iterate through whichever heap the CRT is using. |
| 376 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
| 377 if (crt_heap == NULL) |
| 378 return 0; |
| 379 if (!::HeapLock(crt_heap)) |
| 380 return 0; |
| 381 size_t malloc_usage = 0; |
| 382 PROCESS_HEAP_ENTRY heap_entry; |
| 383 heap_entry.lpData = NULL; |
| 384 while (::HeapWalk(crt_heap, &heap_entry) != 0) { |
| 385 if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) |
| 386 malloc_usage += heap_entry.cbData; |
| 387 } |
| 388 ::HeapUnlock(crt_heap); |
| 389 return malloc_usage; |
| 390 } |
| 391 |
| 370 } // namespace base | 392 } // namespace base |
| OLD | NEW |