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

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

Issue 2415183004: Revert of [tracing] Add filtering mode in TraceLog (Closed)
Patch Set: Created 4 years, 2 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"
11 #include "base/trace_event/heap_profiler.h" 11 #include "base/trace_event/heap_profiler.h"
12 #include "base/trace_event/heap_profiler_allocation_context.h" 12 #include "base/trace_event/heap_profiler_allocation_context.h"
13 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 13 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
14 #include "base/trace_event/memory_dump_manager.h" 14 #include "base/trace_event/memory_dump_manager.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace base { 18 namespace base {
19 namespace trace_event { 19 namespace trace_event {
20 20
21 // Define all strings once, because the pseudo stack requires pointer equality, 21 // Define all strings once, because the pseudo stack requires pointer equality,
22 // and string interning is unreliable. 22 // and string interning is unreliable.
23 const char kThreadName[] = "TestThread"; 23 const char kThreadName[] = "TestThread";
24 const char kCupcake[] = "Cupcake"; 24 const char kCupcake[] = "Cupcake";
25 const char kDonut[] = "Donut"; 25 const char kDonut[] = "Donut";
26 const char kEclair[] = "Eclair"; 26 const char kEclair[] = "Eclair";
27 const char kFroyo[] = "Froyo"; 27 const char kFroyo[] = "Froyo";
28 const char kGingerbread[] = "Gingerbread"; 28 const char kGingerbread[] = "Gingerbread";
29 29
30 const char kFilteringTraceConfig[] =
31 "{"
32 " \"event_filters\": ["
33 " {"
34 " \"excluded_categories\": [],"
35 " \"filter_args\": {},"
36 " \"filter_predicate\": \"heap_profiler_predicate\","
37 " \"included_categories\": [\"*\"]"
38 " }"
39 " ]"
40 "}";
41
42 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace 30 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace
43 // in |AllocationContextTracker::GetContextSnapshot|. 31 // in |AllocationContextTracker::GetContextSnapshot|.
44 template <size_t N> 32 template <size_t N>
45 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) { 33 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) {
46 AllocationContext ctx = 34 AllocationContext ctx =
47 AllocationContextTracker::GetInstanceForCurrentThread() 35 AllocationContextTracker::GetInstanceForCurrentThread()
48 ->GetContextSnapshot(); 36 ->GetContextSnapshot();
49 37
50 auto* actual = std::begin(ctx.backtrace.frames); 38 auto* actual = std::begin(ctx.backtrace.frames);
51 auto* actual_bottom = actual + ctx.backtrace.frame_count; 39 auto* actual_bottom = actual + ctx.backtrace.frame_count;
(...skipping 21 matching lines...) Expand all
73 ASSERT_EQ(t, ctx.backtrace.frames[0]); 61 ASSERT_EQ(t, ctx.backtrace.frames[0]);
74 } 62 }
75 63
76 class AllocationContextTrackerTest : public testing::Test { 64 class AllocationContextTrackerTest : public testing::Test {
77 public: 65 public:
78 void SetUp() override { 66 void SetUp() override {
79 AllocationContextTracker::SetCaptureMode( 67 AllocationContextTracker::SetCaptureMode(
80 AllocationContextTracker::CaptureMode::PSEUDO_STACK); 68 AllocationContextTracker::CaptureMode::PSEUDO_STACK);
81 // Enabling memory-infra category sets default memory dump config which 69 // Enabling memory-infra category sets default memory dump config which
82 // includes filters for capturing pseudo stack. 70 // includes filters for capturing pseudo stack.
83 TraceConfig config(kFilteringTraceConfig); 71 TraceConfig config(MemoryDumpManager::kTraceCategory, "");
84 TraceLog::GetInstance()->SetEnabled(config, TraceLog::FILTERING_MODE); 72 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE);
85 AllocationContextTracker::SetCurrentThreadName(kThreadName); 73 AllocationContextTracker::SetCurrentThreadName(kThreadName);
86 } 74 }
87 75
88 void TearDown() override { 76 void TearDown() override {
89 AllocationContextTracker::SetCaptureMode( 77 AllocationContextTracker::SetCaptureMode(
90 AllocationContextTracker::CaptureMode::DISABLED); 78 AllocationContextTracker::CaptureMode::DISABLED);
91 TraceLog::GetInstance()->SetDisabled(TraceLog::FILTERING_MODE); 79 TraceLog::GetInstance()->SetDisabled();
92 } 80 }
93 }; 81 };
94 82
95 // Check that |TRACE_EVENT| macros push and pop to the pseudo stack correctly. 83 // Check that |TRACE_EVENT| macros push and pop to the pseudo stack correctly.
96 TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) { 84 TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) {
97 StackFrame t = StackFrame::FromThreadName(kThreadName); 85 StackFrame t = StackFrame::FromThreadName(kThreadName);
98 StackFrame c = StackFrame::FromTraceEventName(kCupcake); 86 StackFrame c = StackFrame::FromTraceEventName(kCupcake);
99 StackFrame d = StackFrame::FromTraceEventName(kDonut); 87 StackFrame d = StackFrame::FromTraceEventName(kDonut);
100 StackFrame e = StackFrame::FromTraceEventName(kEclair); 88 StackFrame e = StackFrame::FromTraceEventName(kEclair);
101 StackFrame f = StackFrame::FromTraceEventName(kFroyo); 89 StackFrame f = StackFrame::FromTraceEventName(kFroyo);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 AllocationContextTracker::GetInstanceForCurrentThread() 301 AllocationContextTracker::GetInstanceForCurrentThread()
314 ->GetContextSnapshot(); 302 ->GetContextSnapshot();
315 const StringPiece kTracingOverhead("tracing_overhead"); 303 const StringPiece kTracingOverhead("tracing_overhead");
316 ASSERT_EQ(kTracingOverhead, 304 ASSERT_EQ(kTracingOverhead,
317 static_cast<const char*>(ctx.backtrace.frames[0].value)); 305 static_cast<const char*>(ctx.backtrace.frames[0].value));
318 ASSERT_EQ(1u, ctx.backtrace.frame_count); 306 ASSERT_EQ(1u, ctx.backtrace.frame_count);
319 } 307 }
320 308
321 } // namespace trace_event 309 } // namespace trace_event
322 } // namespace base 310 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_context_tracker.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698