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" |
10 #include "base/trace_event/heap_profiler_allocation_context.h" | 11 #include "base/trace_event/heap_profiler_allocation_context.h" |
11 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 12 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 namespace trace_event { | 17 namespace trace_event { |
17 | 18 |
18 // Define all strings once, because the pseudo stack requires pointer equality, | 19 // Define all strings once, because the pseudo stack requires pointer equality, |
19 // and string interning is unreliable. | 20 // and string interning is unreliable. |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // Test if the thread name is reset. | 245 // Test if the thread name is reset. |
245 const char kThread2[] = "thread2"; | 246 const char kThread2[] = "thread2"; |
246 AllocationContextTracker::SetCurrentThreadName(kThread2); | 247 AllocationContextTracker::SetCurrentThreadName(kThread2); |
247 AllocationContext ctx2 = | 248 AllocationContext ctx2 = |
248 AllocationContextTracker::GetInstanceForCurrentThread() | 249 AllocationContextTracker::GetInstanceForCurrentThread() |
249 ->GetContextSnapshot(); | 250 ->GetContextSnapshot(); |
250 ASSERT_EQ(kThread2, ctx2.backtrace.frames[0]); | 251 ASSERT_EQ(kThread2, ctx2.backtrace.frames[0]); |
251 ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]); | 252 ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]); |
252 } | 253 } |
253 | 254 |
| 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 |
254 } // namespace trace_event | 281 } // namespace trace_event |
255 } // namespace base | 282 } // namespace base |
OLD | NEW |