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/trace_event/heap_profiler_allocation_context.h" | 10 #include "base/trace_event/heap_profiler_allocation_context.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 222 |
223 { | 223 { |
224 AllocationContext ctx = | 224 AllocationContext ctx = |
225 AllocationContextTracker::GetInstanceForCurrentThread() | 225 AllocationContextTracker::GetInstanceForCurrentThread() |
226 ->GetContextSnapshot(); | 226 ->GetContextSnapshot(); |
227 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); | 227 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); |
228 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); | 228 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
| 232 TEST_F(AllocationContextTrackerTest, SetCurrentThreadName) { |
| 233 TRACE_EVENT0("Testing", kCupcake); |
| 234 |
| 235 // Test if the thread name is inserted into backtrace. |
| 236 const char kThread1[] = "thread1"; |
| 237 AllocationContextTracker::SetCurrentThreadName(kThread1); |
| 238 AllocationContext ctx1 = |
| 239 AllocationContextTracker::GetInstanceForCurrentThread() |
| 240 ->GetContextSnapshot(); |
| 241 ASSERT_EQ(kThread1, ctx1.backtrace.frames[0]); |
| 242 ASSERT_EQ(kCupcake, ctx1.backtrace.frames[1]); |
| 243 |
| 244 // Test if the thread name is reset. |
| 245 const char kThread2[] = "thread2"; |
| 246 AllocationContextTracker::SetCurrentThreadName(kThread2); |
| 247 AllocationContext ctx2 = |
| 248 AllocationContextTracker::GetInstanceForCurrentThread() |
| 249 ->GetContextSnapshot(); |
| 250 ASSERT_EQ(kThread2, ctx2.backtrace.frames[0]); |
| 251 ASSERT_EQ(kCupcake, ctx2.backtrace.frames[1]); |
| 252 } |
| 253 |
232 } // namespace trace_event | 254 } // namespace trace_event |
233 } // namespace base | 255 } // namespace base |
OLD | NEW |