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

Unified Diff: base/allocator/allocator_shim.cc

Issue 10825250: Expose memory allocator internal stats and properties. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add jemalloc.h include Created 8 years, 3 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/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/allocator_shim.cc
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc
index 9d3d932d59f2e80787a62c4c2af1565bfe43a2f4..bcc84aac984b25ffad8a97e7e3c52a2cdd42cc0a 100644
--- a/base/allocator/allocator_shim.cc
+++ b/base/allocator/allocator_shim.cc
@@ -8,6 +8,7 @@
#include "base/allocator/allocator_extension_thunks.h"
#include "base/profiler/alternate_timer.h"
#include "base/sysinfo.h"
+#include "jemalloc.h"
// When defined, different heap allocators can be used via an environment
// variable set before running the program. This may reduce the amount
@@ -231,6 +232,44 @@ extern "C" intptr_t _get_heap_handle() {
return 0;
}
+static bool get_jemalloc_property_thunk(const char* name, size_t* value) {
+ jemalloc_stats_t stats;
+ jemalloc_stats(&stats);
+#define EXTRACT_JEMALLOC_PROPERTY(property) \
+ if (strcmp(name, "jemalloc." #property) == 0) \
+ return *value = stats.property, true;
+ EXTRACT_JEMALLOC_PROPERTY(narenas);
+ EXTRACT_JEMALLOC_PROPERTY(balance_threshold);
+ EXTRACT_JEMALLOC_PROPERTY(quantum);
+ EXTRACT_JEMALLOC_PROPERTY(small_max);
+ EXTRACT_JEMALLOC_PROPERTY(large_max);
+ EXTRACT_JEMALLOC_PROPERTY(chunksize);
+ EXTRACT_JEMALLOC_PROPERTY(dirty_max);
+ EXTRACT_JEMALLOC_PROPERTY(reserve_min);
+ EXTRACT_JEMALLOC_PROPERTY(reserve_max);
+ EXTRACT_JEMALLOC_PROPERTY(mapped);
+ EXTRACT_JEMALLOC_PROPERTY(committed);
+ EXTRACT_JEMALLOC_PROPERTY(allocated);
+ EXTRACT_JEMALLOC_PROPERTY(dirty);
+ EXTRACT_JEMALLOC_PROPERTY(reserve_cur);
+#undef EXTRACT_JEMALLOC_PROPERTY
+ return false;
+}
+
+static bool get_property_thunk(const char* name, size_t* value) {
+#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
+ switch (allocator) {
+ case JEMALLOC:
+ return get_jemalloc_property_thunk(name, value);
+ case WINHEAP:
+ case WINLFH:
+ // TODO(alexeif): Implement for other allocators.
+ return false;
+ }
+#endif
+ return MallocExtension::instance()->GetNumericProperty(name, value);
+}
+
static void get_stats_thunk(char* buffer, int buffer_length) {
MallocExtension::instance()->GetStats(buffer, buffer_length);
}
@@ -284,6 +323,7 @@ extern "C" int _heap_init() {
tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
}
+ base::allocator::thunks::SetGetPropertyFunction(get_property_thunk);
base::allocator::thunks::SetGetStatsFunction(get_stats_thunk);
base::allocator::thunks::SetReleaseFreeMemoryFunction(
release_free_memory_thunk);
« no previous file with comments | « base/allocator/allocator_extension_thunks.cc ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698