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" |
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/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 namespace trace_event { | 19 namespace trace_event { |
19 | 20 |
20 // Define all strings once, because the pseudo stack requires pointer equality, | 21 // Define all strings once, because the pseudo stack requires pointer equality, |
21 // and string interning is unreliable. | 22 // and string interning is unreliable. |
22 const char kThreadName[] = "TestThread"; | 23 const char kThreadName[] = "TestThread"; |
23 const char kCupcake[] = "Cupcake"; | 24 const char kCupcake[] = "Cupcake"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 AllocationContextTracker::GetInstanceForCurrentThread() | 57 AllocationContextTracker::GetInstanceForCurrentThread() |
57 ->GetContextSnapshot(); | 58 ->GetContextSnapshot(); |
58 | 59 |
59 ASSERT_EQ(1u, ctx.backtrace.frame_count); | 60 ASSERT_EQ(1u, ctx.backtrace.frame_count); |
60 ASSERT_EQ(t, ctx.backtrace.frames[0]); | 61 ASSERT_EQ(t, ctx.backtrace.frames[0]); |
61 } | 62 } |
62 | 63 |
63 class AllocationContextTrackerTest : public testing::Test { | 64 class AllocationContextTrackerTest : public testing::Test { |
64 public: | 65 public: |
65 void SetUp() override { | 66 void SetUp() override { |
66 TraceConfig config(""); | |
67 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); | |
68 AllocationContextTracker::SetCaptureMode( | 67 AllocationContextTracker::SetCaptureMode( |
69 AllocationContextTracker::CaptureMode::PSEUDO_STACK); | 68 AllocationContextTracker::CaptureMode::PSEUDO_STACK); |
| 69 // Enabling memory-infra category sets default memory dump config which |
| 70 // includes filters for capturing pseudo stack. |
| 71 TraceConfig config(MemoryDumpManager::kTraceCategory, ""); |
| 72 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); |
70 AllocationContextTracker::SetCurrentThreadName(kThreadName); | 73 AllocationContextTracker::SetCurrentThreadName(kThreadName); |
71 } | 74 } |
72 | 75 |
73 void TearDown() override { | 76 void TearDown() override { |
74 AllocationContextTracker::SetCaptureMode( | 77 AllocationContextTracker::SetCaptureMode( |
75 AllocationContextTracker::CaptureMode::DISABLED); | 78 AllocationContextTracker::CaptureMode::DISABLED); |
76 TraceLog::GetInstance()->SetDisabled(); | 79 TraceLog::GetInstance()->SetDisabled(); |
77 } | 80 } |
78 }; | 81 }; |
79 | 82 |
(...skipping 19 matching lines...) Expand all Loading... |
99 } | 102 } |
100 | 103 |
101 AssertBacktraceEquals(frame_c); | 104 AssertBacktraceEquals(frame_c); |
102 | 105 |
103 { | 106 { |
104 TRACE_EVENT0("Testing", kEclair); | 107 TRACE_EVENT0("Testing", kEclair); |
105 StackFrame frame_ce[] = {t, c, e}; | 108 StackFrame frame_ce[] = {t, c, e}; |
106 AssertBacktraceEquals(frame_ce); | 109 AssertBacktraceEquals(frame_ce); |
107 } | 110 } |
108 | 111 |
| 112 { |
| 113 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("Testing"), kCupcake); |
| 114 StackFrame frame_cc[] = {t, c, c}; |
| 115 AssertBacktraceEquals(frame_cc); |
| 116 } |
| 117 |
109 AssertBacktraceEquals(frame_c); | 118 AssertBacktraceEquals(frame_c); |
110 } | 119 } |
111 | 120 |
112 AssertBacktraceContainsOnlyThreadName(); | 121 AssertBacktraceContainsOnlyThreadName(); |
113 | 122 |
114 { | 123 { |
115 TRACE_EVENT0("Testing", kFroyo); | 124 TRACE_EVENT0("Testing", kFroyo); |
116 StackFrame frame_f[] = {t, f}; | 125 StackFrame frame_f[] = {t, f}; |
117 AssertBacktraceEquals(frame_f); | 126 AssertBacktraceEquals(frame_f); |
118 } | 127 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 AllocationContextTracker::GetInstanceForCurrentThread() | 285 AllocationContextTracker::GetInstanceForCurrentThread() |
277 ->GetContextSnapshot(); | 286 ->GetContextSnapshot(); |
278 const StringPiece kTracingOverhead("tracing_overhead"); | 287 const StringPiece kTracingOverhead("tracing_overhead"); |
279 ASSERT_EQ(kTracingOverhead, | 288 ASSERT_EQ(kTracingOverhead, |
280 static_cast<const char*>(ctx.backtrace.frames[0].value)); | 289 static_cast<const char*>(ctx.backtrace.frames[0].value)); |
281 ASSERT_EQ(1u, ctx.backtrace.frame_count); | 290 ASSERT_EQ(1u, ctx.backtrace.frame_count); |
282 } | 291 } |
283 | 292 |
284 } // namespace trace_event | 293 } // namespace trace_event |
285 } // namespace base | 294 } // namespace base |
OLD | NEW |