OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/pending_task.h" | |
11 #include "base/trace_event/heap_profiler_allocation_context.h" | 10 #include "base/trace_event/heap_profiler_allocation_context.h" |
12 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 11 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
13 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 namespace trace_event { | 16 namespace trace_event { |
18 | 17 |
19 // Define all strings once, because the pseudo stack requires pointer equality, | 18 // Define all strings once, because the pseudo stack requires pointer equality, |
20 // and string interning is unreliable. | 19 // and string interning is unreliable. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // Test if the thread name is reset. | 244 // Test if the thread name is reset. |
246 const char kThread2[] = "thread2"; | 245 const char kThread2[] = "thread2"; |
247 AllocationContextTracker::SetCurrentThreadName(kThread2); | 246 AllocationContextTracker::SetCurrentThreadName(kThread2); |
248 AllocationContext ctx2 = | 247 AllocationContext ctx2 = |
249 AllocationContextTracker::GetInstanceForCurrentThread() | 248 AllocationContextTracker::GetInstanceForCurrentThread() |
250 ->GetContextSnapshot(); | 249 ->GetContextSnapshot(); |
251 ASSERT_EQ(kThread2, ctx2.backtrace.frames[0]); | 250 ASSERT_EQ(kThread2, ctx2.backtrace.frames[0]); |
252 ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]); | 251 ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]); |
253 } | 252 } |
254 | 253 |
255 TEST_F(AllocationContextTrackerTest, TrackTaskContext) { | |
256 const char kContext1[] = "context1"; | |
257 const char kContext2[] = "context2"; | |
258 { | |
259 // The context from the scoped task event should be used as type name. | |
260 TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT event1(kContext1); | |
261 AllocationContext ctx1 = | |
262 AllocationContextTracker::GetInstanceForCurrentThread() | |
263 ->GetContextSnapshot(); | |
264 ASSERT_EQ(kContext1, ctx1.type_name); | |
265 | |
266 // In case of nested events, the last event's context should be used. | |
267 TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT event2(kContext2); | |
268 AllocationContext ctx2 = | |
269 AllocationContextTracker::GetInstanceForCurrentThread() | |
270 ->GetContextSnapshot(); | |
271 ASSERT_EQ(kContext2, ctx2.type_name); | |
272 } | |
273 | |
274 // Type should be nullptr without task event. | |
275 AllocationContext ctx = | |
276 AllocationContextTracker::GetInstanceForCurrentThread() | |
277 ->GetContextSnapshot(); | |
278 ASSERT_FALSE(ctx.type_name); | |
279 } | |
280 | |
281 } // namespace trace_event | 254 } // namespace trace_event |
282 } // namespace base | 255 } // namespace base |
OLD | NEW |