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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 { | 244 { |
245 AllocationContext ctx = | 245 AllocationContext ctx = |
246 AllocationContextTracker::GetInstanceForCurrentThread() | 246 AllocationContextTracker::GetInstanceForCurrentThread() |
247 ->GetContextSnapshot(); | 247 ->GetContextSnapshot(); |
248 ASSERT_EQ(t, ctx.backtrace.frames[0]); | 248 ASSERT_EQ(t, ctx.backtrace.frames[0]); |
249 ASSERT_EQ(c, ctx.backtrace.frames[1]); | 249 ASSERT_EQ(c, ctx.backtrace.frames[1]); |
250 ASSERT_EQ(f, ctx.backtrace.frames[11]); | 250 ASSERT_EQ(f, ctx.backtrace.frames[11]); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 TEST_F(AllocationContextTrackerTest, TrackTaskContext) { | 254 TEST_F(AllocationContextTrackerTest, TrackCategoryName) { |
255 const char kContext1[] = "context1"; | 255 const char kContext1[] = "context1"; |
256 const char kContext2[] = "context2"; | 256 const char kContext2[] = "context2"; |
257 { | 257 { |
258 // The context from the scoped task event should be used as type name. | 258 // The context from the scoped task event should be used as type name. |
259 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event1(kContext1); | 259 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event1(kContext1); |
260 AllocationContext ctx1 = | 260 AllocationContext ctx1 = |
261 AllocationContextTracker::GetInstanceForCurrentThread() | 261 AllocationContextTracker::GetInstanceForCurrentThread() |
262 ->GetContextSnapshot(); | 262 ->GetContextSnapshot(); |
263 ASSERT_EQ(kContext1, ctx1.type_name); | 263 ASSERT_EQ(kContext1, ctx1.type_name); |
264 | 264 |
265 // In case of nested events, the last event's context should be used. | 265 // In case of nested events, the last event's context should be used. |
266 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event2(kContext2); | 266 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event2(kContext2); |
267 AllocationContext ctx2 = | 267 AllocationContext ctx2 = |
268 AllocationContextTracker::GetInstanceForCurrentThread() | 268 AllocationContextTracker::GetInstanceForCurrentThread() |
269 ->GetContextSnapshot(); | 269 ->GetContextSnapshot(); |
270 ASSERT_EQ(kContext2, ctx2.type_name); | 270 ASSERT_EQ(kContext2, ctx2.type_name); |
271 } | 271 } |
272 | 272 |
| 273 { |
| 274 // Type should be category name of the last seen trace event. |
| 275 TRACE_EVENT0("Testing", kCupcake); |
| 276 AllocationContext ctx1 = |
| 277 AllocationContextTracker::GetInstanceForCurrentThread() |
| 278 ->GetContextSnapshot(); |
| 279 ASSERT_EQ("Testing", std::string(ctx1.type_name)); |
| 280 |
| 281 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("Testing"), kCupcake); |
| 282 AllocationContext ctx2 = |
| 283 AllocationContextTracker::GetInstanceForCurrentThread() |
| 284 ->GetContextSnapshot(); |
| 285 ASSERT_EQ(TRACE_DISABLED_BY_DEFAULT("Testing"), |
| 286 std::string(ctx2.type_name)); |
| 287 } |
| 288 |
273 // Type should be nullptr without task event. | 289 // Type should be nullptr without task event. |
274 AllocationContext ctx = | 290 AllocationContext ctx = |
275 AllocationContextTracker::GetInstanceForCurrentThread() | 291 AllocationContextTracker::GetInstanceForCurrentThread() |
276 ->GetContextSnapshot(); | 292 ->GetContextSnapshot(); |
277 ASSERT_FALSE(ctx.type_name); | 293 ASSERT_FALSE(ctx.type_name); |
278 } | 294 } |
279 | 295 |
280 TEST_F(AllocationContextTrackerTest, IgnoreAllocationTest) { | 296 TEST_F(AllocationContextTrackerTest, IgnoreAllocationTest) { |
281 TRACE_EVENT0("Testing", kCupcake); | 297 TRACE_EVENT0("Testing", kCupcake); |
282 TRACE_EVENT0("Testing", kDonut); | 298 TRACE_EVENT0("Testing", kDonut); |
283 HEAP_PROFILER_SCOPED_IGNORE; | 299 HEAP_PROFILER_SCOPED_IGNORE; |
284 AllocationContext ctx = | 300 AllocationContext ctx = |
285 AllocationContextTracker::GetInstanceForCurrentThread() | 301 AllocationContextTracker::GetInstanceForCurrentThread() |
286 ->GetContextSnapshot(); | 302 ->GetContextSnapshot(); |
287 const StringPiece kTracingOverhead("tracing_overhead"); | 303 const StringPiece kTracingOverhead("tracing_overhead"); |
288 ASSERT_EQ(kTracingOverhead, | 304 ASSERT_EQ(kTracingOverhead, |
289 static_cast<const char*>(ctx.backtrace.frames[0].value)); | 305 static_cast<const char*>(ctx.backtrace.frames[0].value)); |
290 ASSERT_EQ(1u, ctx.backtrace.frame_count); | 306 ASSERT_EQ(1u, ctx.backtrace.frame_count); |
291 } | 307 } |
292 | 308 |
293 } // namespace trace_event | 309 } // namespace trace_event |
294 } // namespace base | 310 } // namespace base |
OLD | NEW |