Chromium Code Reviews| 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 | 6 #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
| |
| 7 #if !defined(DART_USE_TCMALLOC) || defined(PRODUCT) || \ | |
| 8 defined(TARGET_ARCH_DBC) || defined(HOST_OS_FUCHSIA) | |
| 9 | 7 |
| 10 #include "vm/malloc_hooks.h" | 8 #include "vm/malloc_hooks.h" |
| 11 | 9 |
| 10 #include <jemalloc/jemalloc.h> | |
| 11 | |
| 12 #include "vm/json_stream.h" | |
| 13 | |
| 12 namespace dart { | 14 namespace dart { |
| 13 | 15 |
| 14 void MallocHooks::InitOnce() { | 16 void MallocHooks::InitOnce() { |
| 15 // Do nothing. | 17 // Do nothing. |
| 16 } | 18 } |
| 17 | 19 |
| 18 | 20 |
| 19 void MallocHooks::TearDown() { | 21 void MallocHooks::TearDown() { |
| 20 // Do nothing. | 22 // Do nothing. |
| 21 } | 23 } |
| 22 | 24 |
| 23 | 25 |
| 26 void MallocHooks::PrintToJSONObject(JSONObject* jsobj) { | |
| 27 // 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 | |
| 29 // malloc library. | |
| 30 jsobj->AddProperty("_heapAllocatedMemoryUsage", | |
| 31 heap_allocated_memory_in_bytes()); | |
| 32 jsobj->AddProperty("_heapAllocationCount", | |
| 33 allocation_count()); | |
| 34 } | |
| 35 | |
| 36 | |
| 37 intptr_t MallocHooks::heap_allocated_memory_in_bytes() { | |
| 38 uint64_t epoch = 1; | |
| 39 size_t epoch_sz = sizeof(epoch); | |
| 40 int result = mallctl("epoch", &epoch, &epoch_sz, &epoch, epoch_sz); | |
| 41 if (result != 0) { | |
| 42 return 0; | |
| 43 } | |
| 44 | |
| 45 intptr_t allocated; | |
| 46 size_t allocated_sz = sizeof(allocated); | |
| 47 result = mallctl("stats.allocated", &allocated, &allocated_sz, NULL, 0); | |
| 48 if (result != 0) { | |
| 49 return 0; | |
| 50 } | |
| 51 return allocated; | |
| 52 } | |
| 53 | |
| 54 | |
| 55 intptr_t MallocHooks::allocation_count() { | |
| 56 return 0; | |
| 57 } | |
| 58 | |
| 59 | |
| 24 bool MallocHooks::ProfilingEnabled() { | 60 bool MallocHooks::ProfilingEnabled() { |
| 25 return false; | 61 return false; |
| 26 } | 62 } |
| 27 | 63 |
| 28 | 64 |
| 29 bool MallocHooks::stack_trace_collection_enabled() { | 65 bool MallocHooks::stack_trace_collection_enabled() { |
| 30 return false; | 66 return false; |
| 31 } | 67 } |
| 32 | 68 |
| 33 | 69 |
| 34 void MallocHooks::set_stack_trace_collection_enabled(bool enabled) { | 70 void MallocHooks::set_stack_trace_collection_enabled(bool enabled) { |
| 35 // Do nothing. | 71 // Do nothing. |
| 36 } | 72 } |
| 37 | 73 |
| 38 | 74 |
| 39 void MallocHooks::ResetStats() { | 75 void MallocHooks::ResetStats() { |
| 40 // Do nothing. | 76 // Do nothing. |
| 41 } | 77 } |
| 42 | 78 |
| 43 | 79 |
| 44 bool MallocHooks::Active() { | 80 bool MallocHooks::Active() { |
| 45 return false; | 81 return false; |
| 46 } | 82 } |
| 47 | 83 |
| 48 | 84 |
| 49 void MallocHooks::PrintToJSONObject(JSONObject* jsobj) { | |
| 50 // Do nothing. | |
| 51 } | |
| 52 | |
| 53 | |
| 54 Sample* MallocHooks::GetSample(const void* ptr) { | 85 Sample* MallocHooks::GetSample(const void* ptr) { |
| 55 return NULL; | 86 return NULL; |
| 56 } | 87 } |
| 57 | 88 |
| 58 | |
| 59 intptr_t MallocHooks::allocation_count() { | |
| 60 return 0; | |
| 61 } | |
| 62 | |
| 63 | |
| 64 intptr_t MallocHooks::heap_allocated_memory_in_bytes() { | |
| 65 return 0; | |
| 66 } | |
| 67 | |
| 68 } // namespace dart | 89 } // namespace dart |
| 69 | 90 |
| 70 #endif // !defined(DART_USE_TCMALLOC) || defined(PRODUCT) || | 91 #endif // defined(DART_USE_JEMALLOC) && ... |
| 71 // defined(TARGET_ARCH_DBC) || defined(HOST_OS_FUCHSIA) | |
| OLD | NEW |