Index: base/allocator/allocator_shim.cc |
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc |
index 9d3d932d59f2e80787a62c4c2af1565bfe43a2f4..769d6bb876b288dd663983caef9e6ff85b73e48f 100644 |
--- a/base/allocator/allocator_shim.cc |
+++ b/base/allocator/allocator_shim.cc |
@@ -231,6 +231,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()->GetNumerticProperty(name, value); |
+} |
+ |
static void get_stats_thunk(char* buffer, int buffer_length) { |
MallocExtension::instance()->GetStats(buffer, buffer_length); |
} |
@@ -284,6 +322,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); |