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

Unified Diff: webkit/glue/webkit_glue.cc

Issue 11829032: Add a histogram for renderer memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar build fixes Created 7 years, 11 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 | « webkit/glue/webkit_glue.h ('k') | webkit/glue/webkitplatformsupport_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/webkit_glue.cc
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index 6dcca02e885a00c08069ea7e4acbc703ddb2a7af..a5174f5680c6b6dd73d315ee31e38c90ea554a62 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -11,11 +11,16 @@
#include <sys/utsname.h>
#endif
+#if defined(OS_LINUX)
+#include <malloc.h>
+#endif
+
#include <limits>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
+#include "base/process_util.h"
#include "base/string_piece.h"
#include "base/string_tokenizer.h"
#include "base/string_util.h"
@@ -334,4 +339,37 @@ void ConfigureURLRequestForReferrerPolicy(
COMPILE_ASSERT(std::numeric_limits<double>::has_quiet_NaN, has_quiet_NaN);
+#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<base::ProcessMetrics> process_metrics(
+ // The default port provider is sufficient to get data for the current
+ // process.
+ base::ProcessMetrics::CreateProcessMetrics(
+ base::GetCurrentProcessHandle(), NULL));
+ return process_metrics->GetWorkingSetSize() >> 10;
+}
+#else
+size_t MemoryUsageKB() {
+ scoped_ptr<base::ProcessMetrics> process_metrics(
+ base::ProcessMetrics::CreateProcessMetrics(
+ base::GetCurrentProcessHandle()));
+ return process_metrics->GetPagefileUsage() >> 10;
+}
+#endif
+
} // namespace webkit_glue
« no previous file with comments | « webkit/glue/webkit_glue.h ('k') | webkit/glue/webkitplatformsupport_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698