Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Side by Side Diff: base/process/process_metrics_win.cc

Issue 2925073002: Move malloc/partition_alloc memory usage functions to base (Closed)
Patch Set: Moved to ProcessMetrics method, etc Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/process/process_metrics_posix.cc ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/process/process_metrics_posix.cc ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698