| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(DART_USE_JEMALLOC) && !defined(PRODUCT) | 6 #if defined(DART_USE_JEMALLOC) && !defined(PRODUCT) |
| 7 | 7 |
| 8 #include "vm/malloc_hooks.h" | 8 #include "vm/malloc_hooks.h" |
| 9 | 9 |
| 10 #include <jemalloc/jemalloc.h> | 10 #include <jemalloc/jemalloc.h> |
| 11 | 11 |
| 12 #include "vm/json_stream.h" | 12 #include "vm/json_stream.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 void MallocHooks::InitOnce() { | 16 void MallocHooks::InitOnce() { |
| 17 // Do nothing. | 17 // Do nothing. |
| 18 } | 18 } |
| 19 | 19 |
| 20 | |
| 21 void MallocHooks::TearDown() { | 20 void MallocHooks::TearDown() { |
| 22 // Do nothing. | 21 // Do nothing. |
| 23 } | 22 } |
| 24 | 23 |
| 25 | |
| 26 void MallocHooks::PrintToJSONObject(JSONObject* jsobj) { | 24 void MallocHooks::PrintToJSONObject(JSONObject* jsobj) { |
| 27 // Here, we ignore the value of FLAG_profiler_native_memory because we can | 25 // Here, we ignore the value of FLAG_profiler_native_memory because we can |
| 28 // gather this information cheaply without hooking into every call to the | 26 // gather this information cheaply without hooking into every call to the |
| 29 // malloc library. | 27 // malloc library. |
| 30 jsobj->AddProperty("_heapAllocatedMemoryUsage", | 28 jsobj->AddProperty("_heapAllocatedMemoryUsage", |
| 31 heap_allocated_memory_in_bytes()); | 29 heap_allocated_memory_in_bytes()); |
| 32 jsobj->AddProperty("_heapAllocationCount", allocation_count()); | 30 jsobj->AddProperty("_heapAllocationCount", allocation_count()); |
| 33 } | 31 } |
| 34 | 32 |
| 35 | |
| 36 intptr_t MallocHooks::heap_allocated_memory_in_bytes() { | 33 intptr_t MallocHooks::heap_allocated_memory_in_bytes() { |
| 37 uint64_t epoch = 1; | 34 uint64_t epoch = 1; |
| 38 size_t epoch_sz = sizeof(epoch); | 35 size_t epoch_sz = sizeof(epoch); |
| 39 int result = mallctl("epoch", &epoch, &epoch_sz, &epoch, epoch_sz); | 36 int result = mallctl("epoch", &epoch, &epoch_sz, &epoch, epoch_sz); |
| 40 if (result != 0) { | 37 if (result != 0) { |
| 41 return 0; | 38 return 0; |
| 42 } | 39 } |
| 43 | 40 |
| 44 intptr_t allocated; | 41 intptr_t allocated; |
| 45 size_t allocated_sz = sizeof(allocated); | 42 size_t allocated_sz = sizeof(allocated); |
| 46 result = mallctl("stats.allocated", &allocated, &allocated_sz, NULL, 0); | 43 result = mallctl("stats.allocated", &allocated, &allocated_sz, NULL, 0); |
| 47 if (result != 0) { | 44 if (result != 0) { |
| 48 return 0; | 45 return 0; |
| 49 } | 46 } |
| 50 return allocated; | 47 return allocated; |
| 51 } | 48 } |
| 52 | 49 |
| 53 | |
| 54 intptr_t MallocHooks::allocation_count() { | 50 intptr_t MallocHooks::allocation_count() { |
| 55 return 0; | 51 return 0; |
| 56 } | 52 } |
| 57 | 53 |
| 58 | |
| 59 bool MallocHooks::ProfilingEnabled() { | 54 bool MallocHooks::ProfilingEnabled() { |
| 60 return false; | 55 return false; |
| 61 } | 56 } |
| 62 | 57 |
| 63 | |
| 64 bool MallocHooks::stack_trace_collection_enabled() { | 58 bool MallocHooks::stack_trace_collection_enabled() { |
| 65 return false; | 59 return false; |
| 66 } | 60 } |
| 67 | 61 |
| 68 | |
| 69 void MallocHooks::set_stack_trace_collection_enabled(bool enabled) { | 62 void MallocHooks::set_stack_trace_collection_enabled(bool enabled) { |
| 70 // Do nothing. | 63 // Do nothing. |
| 71 } | 64 } |
| 72 | 65 |
| 73 | |
| 74 void MallocHooks::ResetStats() { | 66 void MallocHooks::ResetStats() { |
| 75 // Do nothing. | 67 // Do nothing. |
| 76 } | 68 } |
| 77 | 69 |
| 78 | |
| 79 bool MallocHooks::Active() { | 70 bool MallocHooks::Active() { |
| 80 return false; | 71 return false; |
| 81 } | 72 } |
| 82 | 73 |
| 83 | |
| 84 Sample* MallocHooks::GetSample(const void* ptr) { | 74 Sample* MallocHooks::GetSample(const void* ptr) { |
| 85 return NULL; | 75 return NULL; |
| 86 } | 76 } |
| 87 | 77 |
| 88 } // namespace dart | 78 } // namespace dart |
| 89 | 79 |
| 90 #endif // defined(DART_USE_JEMALLOC) && ... | 80 #endif // defined(DART_USE_JEMALLOC) && ... |
| OLD | NEW |