| 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/pending_task.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 ->GetContextSnapshot(); | 253 ->GetContextSnapshot(); |
| 254 ASSERT_EQ(StackFrame::FromThreadName(kThread2), ctx2.backtrace.frames[0]); | 254 ASSERT_EQ(StackFrame::FromThreadName(kThread2), ctx2.backtrace.frames[0]); |
| 255 ASSERT_EQ(StackFrame::FromTraceEventName(kCupcake), ctx2.backtrace.frames[1]); | 255 ASSERT_EQ(StackFrame::FromTraceEventName(kCupcake), ctx2.backtrace.frames[1]); |
| 256 } | 256 } |
| 257 | 257 |
| 258 TEST_F(AllocationContextTrackerTest, TrackTaskContext) { | 258 TEST_F(AllocationContextTrackerTest, TrackTaskContext) { |
| 259 const char kContext1[] = "context1"; | 259 const char kContext1[] = "context1"; |
| 260 const char kContext2[] = "context2"; | 260 const char kContext2[] = "context2"; |
| 261 { | 261 { |
| 262 // The context from the scoped task event should be used as type name. | 262 // The context from the scoped task event should be used as type name. |
| 263 TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT event1(kContext1); | 263 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event1(kContext1); |
| 264 AllocationContext ctx1 = | 264 AllocationContext ctx1 = |
| 265 AllocationContextTracker::GetInstanceForCurrentThread() | 265 AllocationContextTracker::GetInstanceForCurrentThread() |
| 266 ->GetContextSnapshot(); | 266 ->GetContextSnapshot(); |
| 267 ASSERT_EQ(kContext1, ctx1.type_name); | 267 ASSERT_EQ(kContext1, ctx1.type_name); |
| 268 | 268 |
| 269 // In case of nested events, the last event's context should be used. | 269 // In case of nested events, the last event's context should be used. |
| 270 TRACE_EVENT_API_SCOPED_TASK_EXECUTION_EVENT event2(kContext2); | 270 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event2(kContext2); |
| 271 AllocationContext ctx2 = | 271 AllocationContext ctx2 = |
| 272 AllocationContextTracker::GetInstanceForCurrentThread() | 272 AllocationContextTracker::GetInstanceForCurrentThread() |
| 273 ->GetContextSnapshot(); | 273 ->GetContextSnapshot(); |
| 274 ASSERT_EQ(kContext2, ctx2.type_name); | 274 ASSERT_EQ(kContext2, ctx2.type_name); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Type should be nullptr without task event. | 277 // Type should be nullptr without task event. |
| 278 AllocationContext ctx = | 278 AllocationContext ctx = |
| 279 AllocationContextTracker::GetInstanceForCurrentThread() | 279 AllocationContextTracker::GetInstanceForCurrentThread() |
| 280 ->GetContextSnapshot(); | 280 ->GetContextSnapshot(); |
| 281 ASSERT_FALSE(ctx.type_name); | 281 ASSERT_FALSE(ctx.type_name); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(AllocationContextTrackerTest, IgnoreAllocationTest) { | 284 TEST_F(AllocationContextTrackerTest, IgnoreAllocationTest) { |
| 285 TRACE_EVENT0("Testing", kCupcake); | 285 TRACE_EVENT0("Testing", kCupcake); |
| 286 TRACE_EVENT0("Testing", kDonut); | 286 TRACE_EVENT0("Testing", kDonut); |
| 287 HEAP_PROFILER_SCOPED_IGNORE; | 287 HEAP_PROFILER_SCOPED_IGNORE; |
| 288 AllocationContext ctx = | 288 AllocationContext ctx = |
| 289 AllocationContextTracker::GetInstanceForCurrentThread() | 289 AllocationContextTracker::GetInstanceForCurrentThread() |
| 290 ->GetContextSnapshot(); | 290 ->GetContextSnapshot(); |
| 291 const StringPiece kTracingOverhead("tracing_overhead"); | 291 const StringPiece kTracingOverhead("tracing_overhead"); |
| 292 ASSERT_EQ(kTracingOverhead, | 292 ASSERT_EQ(kTracingOverhead, |
| 293 static_cast<const char*>(ctx.backtrace.frames[0].value)); | 293 static_cast<const char*>(ctx.backtrace.frames[0].value)); |
| 294 ASSERT_EQ(1u, ctx.backtrace.frame_count); | 294 ASSERT_EQ(1u, ctx.backtrace.frame_count); |
| 295 } | 295 } |
| 296 | 296 |
| 297 } // namespace trace_event | 297 } // namespace trace_event |
| 298 } // namespace base | 298 } // namespace base |
| OLD | NEW |