diff options
Diffstat (limited to 'base/allocator/allocator_shim.cc')
-rw-r--r-- | base/allocator/allocator_shim.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc index 9d3d932..bcc84aa 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); |