Index: runtime/vm/malloc_hooks_jemalloc.cc |
diff --git a/runtime/vm/malloc_hooks_unsupported.cc b/runtime/vm/malloc_hooks_jemalloc.cc |
similarity index 52% |
copy from runtime/vm/malloc_hooks_unsupported.cc |
copy to runtime/vm/malloc_hooks_jemalloc.cc |
index 2f84af464d1491e639f1de0e6170473564925647..20fc00e223f638f373f3aeca35223bf2e88dbdd6 100644 |
--- a/runtime/vm/malloc_hooks_unsupported.cc |
+++ b/runtime/vm/malloc_hooks_jemalloc.cc |
@@ -3,12 +3,14 @@ |
// BSD-style license that can be found in the LICENSE file. |
#include "platform/globals.h" |
- |
-#if !defined(DART_USE_TCMALLOC) || defined(PRODUCT) || \ |
- defined(TARGET_ARCH_DBC) || defined(HOST_OS_FUCHSIA) |
+#if defined(DART_USE_JEMALLOC) && !defined(PRODUCT) && !defined(TARGET_ARCH_DBC) |
rmacnak
2017/04/19 22:43:59
Not part of your change, but I don't see any reaso
|
#include "vm/malloc_hooks.h" |
+#include <jemalloc/jemalloc.h> |
+ |
+#include "vm/json_stream.h" |
+ |
namespace dart { |
void MallocHooks::InitOnce() { |
@@ -21,6 +23,40 @@ void MallocHooks::TearDown() { |
} |
+void MallocHooks::PrintToJSONObject(JSONObject* jsobj) { |
+ // Here, we ignore the value of FLAG_profiler_native_memory because we can |
+ // gather this information cheaply without hooking into every call to the |
+ // malloc library. |
+ jsobj->AddProperty("_heapAllocatedMemoryUsage", |
+ heap_allocated_memory_in_bytes()); |
+ jsobj->AddProperty("_heapAllocationCount", |
+ allocation_count()); |
+} |
+ |
+ |
+intptr_t MallocHooks::heap_allocated_memory_in_bytes() { |
+ uint64_t epoch = 1; |
+ size_t epoch_sz = sizeof(epoch); |
+ int result = mallctl("epoch", &epoch, &epoch_sz, &epoch, epoch_sz); |
+ if (result != 0) { |
+ return 0; |
+ } |
+ |
+ intptr_t allocated; |
+ size_t allocated_sz = sizeof(allocated); |
+ result = mallctl("stats.allocated", &allocated, &allocated_sz, NULL, 0); |
+ if (result != 0) { |
+ return 0; |
+ } |
+ return allocated; |
+} |
+ |
+ |
+intptr_t MallocHooks::allocation_count() { |
+ return 0; |
+} |
+ |
+ |
bool MallocHooks::ProfilingEnabled() { |
return false; |
} |
@@ -46,26 +82,10 @@ bool MallocHooks::Active() { |
} |
-void MallocHooks::PrintToJSONObject(JSONObject* jsobj) { |
- // Do nothing. |
-} |
- |
- |
Sample* MallocHooks::GetSample(const void* ptr) { |
return NULL; |
} |
- |
-intptr_t MallocHooks::allocation_count() { |
- return 0; |
-} |
- |
- |
-intptr_t MallocHooks::heap_allocated_memory_in_bytes() { |
- return 0; |
-} |
- |
} // namespace dart |
-#endif // !defined(DART_USE_TCMALLOC) || defined(PRODUCT) || |
- // defined(TARGET_ARCH_DBC) || defined(HOST_OS_FUCHSIA) |
+#endif // defined(DART_USE_JEMALLOC) && ... |