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 |
7 #if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && !defined(TARGET_ARCH_DBC) | 7 #if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && !defined(TARGET_ARCH_DBC) |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // in buffer isn't touched, the tcmalloc hooks won't be called. | 22 // in buffer isn't touched, the tcmalloc hooks won't be called. |
23 for (uintptr_t i = 0; i < size; ++i) { | 23 for (uintptr_t i = 0; i < size; ++i) { |
24 buffer[i] = i; | 24 buffer[i] = i; |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 | 28 |
29 UNIT_TEST_CASE(BasicMallocHookTest) { | 29 UNIT_TEST_CASE(BasicMallocHookTest) { |
30 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; | 30 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; |
31 FLAG_profiler_native_memory = true; | 31 FLAG_profiler_native_memory = true; |
| 32 Profiler::InitAllocationSampleBuffer(); |
32 | 33 |
33 MallocHooks::InitOnce(); | 34 MallocHooks::InitOnce(); |
34 MallocHooks::ResetStats(); | 35 MallocHooks::ResetStats(); |
35 EXPECT_EQ(0L, MallocHooks::allocation_count()); | 36 EXPECT_EQ(0L, MallocHooks::allocation_count()); |
36 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); | 37 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); |
37 const intptr_t buffer_size = 10; | 38 const intptr_t buffer_size = 10; |
38 char* buffer = new char[buffer_size]; | 39 char* buffer = new char[buffer_size]; |
39 MallocHookTestBufferInitializer(buffer, buffer_size); | 40 MallocHookTestBufferInitializer(buffer, buffer_size); |
40 | 41 |
41 EXPECT_EQ(1L, MallocHooks::allocation_count()); | 42 EXPECT_EQ(1L, MallocHooks::allocation_count()); |
42 EXPECT_EQ(static_cast<intptr_t>(sizeof(char) * buffer_size), | 43 EXPECT_EQ(static_cast<intptr_t>(sizeof(char) * buffer_size), |
43 MallocHooks::heap_allocated_memory_in_bytes()); | 44 MallocHooks::heap_allocated_memory_in_bytes()); |
44 | 45 |
45 delete[] buffer; | 46 delete[] buffer; |
46 EXPECT_EQ(0L, MallocHooks::allocation_count()); | 47 EXPECT_EQ(0L, MallocHooks::allocation_count()); |
47 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); | 48 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); |
48 MallocHooks::TearDown(); | 49 MallocHooks::TearDown(); |
49 | 50 |
50 FLAG_profiler_native_memory = enable_malloc_hooks_saved; | 51 FLAG_profiler_native_memory = enable_malloc_hooks_saved; |
51 } | 52 } |
52 | 53 |
53 | 54 |
54 UNIT_TEST_CASE(FreeUnseenMemoryMallocHookTest) { | 55 UNIT_TEST_CASE(FreeUnseenMemoryMallocHookTest) { |
55 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; | 56 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; |
56 FLAG_profiler_native_memory = true; | 57 FLAG_profiler_native_memory = true; |
| 58 Profiler::InitAllocationSampleBuffer(); |
57 | 59 |
58 MallocHooks::InitOnce(); | 60 MallocHooks::InitOnce(); |
59 const intptr_t pre_hook_buffer_size = 3; | 61 const intptr_t pre_hook_buffer_size = 3; |
60 char* pre_hook_buffer = new char[pre_hook_buffer_size]; | 62 char* pre_hook_buffer = new char[pre_hook_buffer_size]; |
61 MallocHookTestBufferInitializer(pre_hook_buffer, pre_hook_buffer_size); | 63 MallocHookTestBufferInitializer(pre_hook_buffer, pre_hook_buffer_size); |
62 | 64 |
63 MallocHooks::ResetStats(); | 65 MallocHooks::ResetStats(); |
64 EXPECT_EQ(0L, MallocHooks::allocation_count()); | 66 EXPECT_EQ(0L, MallocHooks::allocation_count()); |
65 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); | 67 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); |
66 | 68 |
(...skipping 16 matching lines...) Expand all Loading... |
83 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); | 85 EXPECT_EQ(0L, MallocHooks::heap_allocated_memory_in_bytes()); |
84 MallocHooks::TearDown(); | 86 MallocHooks::TearDown(); |
85 | 87 |
86 FLAG_profiler_native_memory = enable_malloc_hooks_saved; | 88 FLAG_profiler_native_memory = enable_malloc_hooks_saved; |
87 } | 89 } |
88 | 90 |
89 | 91 |
90 VM_UNIT_TEST_CASE(StackTraceMallocHookSimpleTest) { | 92 VM_UNIT_TEST_CASE(StackTraceMallocHookSimpleTest) { |
91 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; | 93 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; |
92 FLAG_profiler_native_memory = true; | 94 FLAG_profiler_native_memory = true; |
| 95 Profiler::InitAllocationSampleBuffer(); |
93 | 96 |
94 MallocHooks::InitOnce(); | 97 MallocHooks::InitOnce(); |
95 MallocHooks::ResetStats(); | 98 MallocHooks::ResetStats(); |
96 | 99 |
97 bool enable_stack_traces_saved = | 100 bool enable_stack_traces_saved = |
98 MallocHooks::stack_trace_collection_enabled(); | 101 MallocHooks::stack_trace_collection_enabled(); |
99 MallocHooks::set_stack_trace_collection_enabled(true); | 102 MallocHooks::set_stack_trace_collection_enabled(true); |
100 | 103 |
101 char* var = static_cast<char*>(malloc(16 * sizeof(char))); | 104 char* var = static_cast<char*>(malloc(16 * sizeof(char))); |
102 Sample* sample = MallocHooks::GetSample(var); | 105 Sample* sample = MallocHooks::GetSample(var); |
(...skipping 11 matching lines...) Expand all Loading... |
114 static char* DART_NOINLINE StackTraceLengthHelper(uintptr_t* end_address) { | 117 static char* DART_NOINLINE StackTraceLengthHelper(uintptr_t* end_address) { |
115 char* var = static_cast<char*>(malloc(16 * sizeof(char))); | 118 char* var = static_cast<char*>(malloc(16 * sizeof(char))); |
116 *end_address = OS::GetProgramCounter(); | 119 *end_address = OS::GetProgramCounter(); |
117 return var; | 120 return var; |
118 } | 121 } |
119 | 122 |
120 | 123 |
121 VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) { | 124 VM_UNIT_TEST_CASE(StackTraceMallocHookLengthTest) { |
122 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; | 125 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; |
123 FLAG_profiler_native_memory = true; | 126 FLAG_profiler_native_memory = true; |
| 127 Profiler::InitAllocationSampleBuffer(); |
124 | 128 |
125 uintptr_t test_start_address = | 129 uintptr_t test_start_address = |
126 reinterpret_cast<uintptr_t>(Dart_TestStackTraceMallocHookLengthTest); | 130 reinterpret_cast<uintptr_t>(Dart_TestStackTraceMallocHookLengthTest); |
127 uintptr_t helper_start_address = | 131 uintptr_t helper_start_address = |
128 reinterpret_cast<uintptr_t>(StackTraceLengthHelper); | 132 reinterpret_cast<uintptr_t>(StackTraceLengthHelper); |
129 uintptr_t helper_end_address = 0; | 133 uintptr_t helper_end_address = 0; |
130 | 134 |
131 MallocHooks::InitOnce(); | 135 MallocHooks::InitOnce(); |
132 MallocHooks::ResetStats(); | 136 MallocHooks::ResetStats(); |
133 | 137 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 free(var); | 172 free(var); |
169 MallocHooks::TearDown(); | 173 MallocHooks::TearDown(); |
170 MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved); | 174 MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved); |
171 FLAG_profiler_native_memory = enable_malloc_hooks_saved; | 175 FLAG_profiler_native_memory = enable_malloc_hooks_saved; |
172 } | 176 } |
173 | 177 |
174 | 178 |
175 ISOLATE_UNIT_TEST_CASE(StackTraceMallocHookSimpleJSONTest) { | 179 ISOLATE_UNIT_TEST_CASE(StackTraceMallocHookSimpleJSONTest) { |
176 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; | 180 bool enable_malloc_hooks_saved = FLAG_profiler_native_memory; |
177 FLAG_profiler_native_memory = true; | 181 FLAG_profiler_native_memory = true; |
| 182 Profiler::InitAllocationSampleBuffer(); |
178 | 183 |
179 MallocHooks::InitOnce(); | 184 MallocHooks::InitOnce(); |
180 MallocHooks::ResetStats(); | 185 MallocHooks::ResetStats(); |
181 | 186 |
182 bool enable_stack_traces_saved = | 187 bool enable_stack_traces_saved = |
183 MallocHooks::stack_trace_collection_enabled(); | 188 MallocHooks::stack_trace_collection_enabled(); |
184 MallocHooks::set_stack_trace_collection_enabled(true); | 189 MallocHooks::set_stack_trace_collection_enabled(true); |
185 | 190 |
186 ClearProfileVisitor cpv(Isolate::Current()); | 191 ClearProfileVisitor cpv(Isolate::Current()); |
187 Profiler::sample_buffer()->VisitSamples(&cpv); | 192 Profiler::sample_buffer()->VisitSamples(&cpv); |
(...skipping 15 matching lines...) Expand all Loading... |
203 | 208 |
204 free(var); | 209 free(var); |
205 MallocHooks::TearDown(); | 210 MallocHooks::TearDown(); |
206 MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved); | 211 MallocHooks::set_stack_trace_collection_enabled(enable_stack_traces_saved); |
207 FLAG_profiler_native_memory = enable_malloc_hooks_saved; | 212 FLAG_profiler_native_memory = enable_malloc_hooks_saved; |
208 } | 213 } |
209 | 214 |
210 }; // namespace dart | 215 }; // namespace dart |
211 | 216 |
212 #endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) | 217 #endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) |
OLD | NEW |