Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: base/trace_event/heap_profiler_allocation_context_tracker_unittest.cc

Issue 2272843002: Heap Profiler: Add trace category group names as type names for allocations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_filter
Patch Set: Rebase. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Type should be category name of the last seen trace event, but the ones
282 // with "," should be ignored.
283 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("Testing"), kCupcake);
284 TRACE_EVENT0("Other," TRACE_DISABLED_BY_DEFAULT("Other"), kCupcake);
285 AllocationContext ctx2 =
286 AllocationContextTracker::GetInstanceForCurrentThread()
287 ->GetContextSnapshot();
288 ASSERT_EQ(TRACE_DISABLED_BY_DEFAULT("Testing"),
289 std::string(ctx2.type_name));
290 }
291
273 // Type should be nullptr without task event. 292 // Type should be nullptr without task event.
274 AllocationContext ctx = 293 AllocationContext ctx =
275 AllocationContextTracker::GetInstanceForCurrentThread() 294 AllocationContextTracker::GetInstanceForCurrentThread()
276 ->GetContextSnapshot(); 295 ->GetContextSnapshot();
277 ASSERT_FALSE(ctx.type_name); 296 ASSERT_FALSE(ctx.type_name);
278 } 297 }
279 298
280 TEST_F(AllocationContextTrackerTest, IgnoreAllocationTest) { 299 TEST_F(AllocationContextTrackerTest, IgnoreAllocationTest) {
281 TRACE_EVENT0("Testing", kCupcake); 300 TRACE_EVENT0("Testing", kCupcake);
282 TRACE_EVENT0("Testing", kDonut); 301 TRACE_EVENT0("Testing", kDonut);
283 HEAP_PROFILER_SCOPED_IGNORE; 302 HEAP_PROFILER_SCOPED_IGNORE;
284 AllocationContext ctx = 303 AllocationContext ctx =
285 AllocationContextTracker::GetInstanceForCurrentThread() 304 AllocationContextTracker::GetInstanceForCurrentThread()
286 ->GetContextSnapshot(); 305 ->GetContextSnapshot();
287 const StringPiece kTracingOverhead("tracing_overhead"); 306 const StringPiece kTracingOverhead("tracing_overhead");
288 ASSERT_EQ(kTracingOverhead, 307 ASSERT_EQ(kTracingOverhead,
289 static_cast<const char*>(ctx.backtrace.frames[0].value)); 308 static_cast<const char*>(ctx.backtrace.frames[0].value));
290 ASSERT_EQ(1u, ctx.backtrace.frame_count); 309 ASSERT_EQ(1u, ctx.backtrace.frame_count);
291 } 310 }
292 311
293 } // namespace trace_event 312 } // namespace trace_event
294 } // namespace base 313 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698