Index: webkit/glue/memory_usage.cc |
diff --git a/webkit/glue/memory_usage.cc b/webkit/glue/memory_usage.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..19ac20f48d7473d8c55665f464ba2d65d202b337 |
--- /dev/null |
+++ b/webkit/glue/memory_usage.cc |
@@ -0,0 +1,54 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "webkit/glue/memory_usage.h" |
+ |
+#include "build/build_config.h" |
+ |
+#if defined(OS_LINUX) |
+#include <malloc.h> |
+#endif |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/process_util.h" |
+ |
+#if defined(OS_LINUX) |
+#include "v8/include/v8.h" |
+#endif |
+ |
+namespace webkit_glue { |
+ |
+#if defined(OS_LINUX) || defined(OS_ANDROID) |
+size_t memoryUsageKB() { |
+ struct mallinfo minfo = mallinfo(); |
+ uint64_t mem_usage = |
+#if defined(USE_TCMALLOC) |
+ minfo.uordblks |
+#else |
+ (minfo.hblkhd + minfo.arena) |
+#endif |
+ >> 10; |
+ |
+ v8::HeapStatistics stat; |
+ v8::V8::GetHeapStatistics(&stat); |
+ return mem_usage + (static_cast<uint64_t>(stat.total_heap_size()) >> 10); |
+} |
+#elif defined(OS_MACOSX) |
+size_t memoryUsageKB() { |
+ scoped_ptr<ProcessMetrics> process_metrics( |
+ // The default port provider is sufficient to get data for the current |
+ // process. |
+ ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(), |
+ NULL)); |
+ return process_metrics.GetWorkingSetSize() >> 10; |
+} |
+#else |
+size_t memoryUsageKB() { |
+ scoped_ptr<ProcessMetrics> process_metrics( |
+ ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle())); |
+ return process_metrics.GetPagefileUsage() >> 10; |
+} |
+#endif |
+ |
+} // namespace webkit_glue |