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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_win.cc
diff --git a/base/process/process_metrics_win.cc b/base/process/process_metrics_win.cc
index f5b191dfc08325f39a19b6f7331ae3c7e93a089a..8a278998043dbc4c8da7e083585c670f2fe48f20 100644
--- a/base/process/process_metrics_win.cc
+++ b/base/process/process_metrics_win.cc
@@ -17,6 +17,10 @@
#include "base/process/memory.h"
#include "base/sys_info.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
namespace base {
namespace {
@@ -367,4 +371,22 @@ bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
return true;
}
+size_t ProcessMetrics::GetMallocUsage() {
+ // Iterate through whichever heap the CRT is using.
+ HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle());
+ if (crt_heap == NULL)
+ return 0;
+ if (!::HeapLock(crt_heap))
+ return 0;
+ size_t malloc_usage = 0;
+ PROCESS_HEAP_ENTRY heap_entry;
+ heap_entry.lpData = NULL;
+ while (::HeapWalk(crt_heap, &heap_entry) != 0) {
+ if ((heap_entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0)
+ malloc_usage += heap_entry.cbData;
+ }
+ ::HeapUnlock(crt_heap);
+ return malloc_usage;
+}
+
} // namespace base
« 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