Index: base/allocator/tcmalloc_extension.cc |
diff --git a/base/allocator/tcmalloc_extension.cc b/base/allocator/tcmalloc_extension.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..80e37c3e96f3aba957e241c64c46ef6b1996595f |
--- /dev/null |
+++ b/base/allocator/tcmalloc_extension.cc |
@@ -0,0 +1,72 @@ |
+// Copyright 2015 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 "base/allocator/allocator_extension_thunks.h" |
+ |
+#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" |
+#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" |
+ |
+extern "C" { |
+int tc_set_new_mode(int mode); |
+} |
+ |
+namespace { |
+ |
+bool GetAllocatorWasteSizeHelper(size_t* size) { |
+ size_t heap_size, allocated_bytes, unmapped_bytes; |
+ MallocExtension* ext = MallocExtension::instance(); |
+ if (ext->GetNumericProperty("generic.heap_size", &heap_size) && |
+ ext->GetNumericProperty("generic.current_allocated_bytes", |
+ &allocated_bytes) && |
+ ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes", |
+ &unmapped_bytes)) { |
+ *size = heap_size - allocated_bytes - unmapped_bytes; |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+void GetStatsHelper(char* buffer, int buffer_length) { |
+ MallocExtension::instance()->GetStats(buffer, buffer_length); |
+} |
+ |
+bool GetNumericPropertyHelper(const char* name, size_t* value) { |
+ return MallocExtension::instance()->GetNumericProperty(name, value); |
+} |
+ |
+void ReleaseFreeMemoryHelper() { |
+ MallocExtension::instance()->ReleaseFreeMemory(); |
+} |
+ |
+unsigned int GetBytesAllocatedOnCurrentThreadHelper() { |
+ return MallocExtension::instance()->GetBytesAllocatedOnCurrentThread(); |
+} |
+ |
+bool IsHeapProfilerRunningHelper() { |
+ return IsHeapProfilerRunning(); |
+} |
+ |
+} // namespace |
+ |
+namespace base { |
+namespace allocator { |
+ |
+__attribute__((visibility("default"))) thunks::AllocatorExtensionFunctions |
+InitializeAllocatorWeak(); |
+ |
+thunks::AllocatorExtensionFunctions InitializeAllocatorWeak() { |
+ // For tcmalloc, we need to tell it to behave like new. |
+ tc_set_new_mode(1); |
+ |
+ thunks::AllocatorExtensionFunctions allocator_funtions = { |
+ GetAllocatorWasteSizeHelper, GetStatsHelper, |
+ ReleaseFreeMemoryHelper, GetBytesAllocatedOnCurrentThreadHelper, |
+ GetNumericPropertyHelper, ::HeapProfilerWithPseudoStackStart, |
+ ::HeapProfilerStop, ::GetHeapProfile, |
+ ::HeapProfilerDump, IsHeapProfilerRunningHelper}; |
+ return allocator_funtions; |
+} |
+ |
+} // namespace allocator |
+} // namespace base |