Chromium Code Reviews| 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/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 " \"included_categories\": [\"disabled-by-default-memory-infra\"]" | |
|
Primiano Tucci (use gerrit)
2016/10/12 17:50:17
should this be: -*, disabled-....
otherwise all th
ssid
2016/10/12 19:04:43
Actually I think the SetEnabled must not have RECO
| |
| 41 "}"; | |
| 42 | |
| 30 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace | 43 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace |
| 31 // in |AllocationContextTracker::GetContextSnapshot|. | 44 // in |AllocationContextTracker::GetContextSnapshot|. |
| 32 template <size_t N> | 45 template <size_t N> |
| 33 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) { | 46 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) { |
| 34 AllocationContext ctx = | 47 AllocationContext ctx = |
| 35 AllocationContextTracker::GetInstanceForCurrentThread() | 48 AllocationContextTracker::GetInstanceForCurrentThread() |
| 36 ->GetContextSnapshot(); | 49 ->GetContextSnapshot(); |
| 37 | 50 |
| 38 auto* actual = std::begin(ctx.backtrace.frames); | 51 auto* actual = std::begin(ctx.backtrace.frames); |
| 39 auto* actual_bottom = actual + ctx.backtrace.frame_count; | 52 auto* actual_bottom = actual + ctx.backtrace.frame_count; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 61 ASSERT_EQ(t, ctx.backtrace.frames[0]); | 74 ASSERT_EQ(t, ctx.backtrace.frames[0]); |
| 62 } | 75 } |
| 63 | 76 |
| 64 class AllocationContextTrackerTest : public testing::Test { | 77 class AllocationContextTrackerTest : public testing::Test { |
| 65 public: | 78 public: |
| 66 void SetUp() override { | 79 void SetUp() override { |
| 67 AllocationContextTracker::SetCaptureMode( | 80 AllocationContextTracker::SetCaptureMode( |
| 68 AllocationContextTracker::CaptureMode::PSEUDO_STACK); | 81 AllocationContextTracker::CaptureMode::PSEUDO_STACK); |
| 69 // Enabling memory-infra category sets default memory dump config which | 82 // Enabling memory-infra category sets default memory dump config which |
| 70 // includes filters for capturing pseudo stack. | 83 // includes filters for capturing pseudo stack. |
| 71 TraceConfig config(MemoryDumpManager::kTraceCategory, ""); | 84 TraceConfig config(kFilteringTraceConfig); |
| 72 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); | 85 TraceLog::GetInstance()->SetEnabled( |
| 86 config, TraceLog::RECORDING_MODE | TraceLog::FILTERING_MODE); | |
| 73 AllocationContextTracker::SetCurrentThreadName(kThreadName); | 87 AllocationContextTracker::SetCurrentThreadName(kThreadName); |
| 74 } | 88 } |
| 75 | 89 |
| 76 void TearDown() override { | 90 void TearDown() override { |
| 77 AllocationContextTracker::SetCaptureMode( | 91 AllocationContextTracker::SetCaptureMode( |
| 78 AllocationContextTracker::CaptureMode::DISABLED); | 92 AllocationContextTracker::CaptureMode::DISABLED); |
| 79 TraceLog::GetInstance()->SetDisabled(); | 93 TraceLog::GetInstance()->SetDisabled(TraceLog::RECORDING_MODE | |
| 94 TraceLog::FILTERING_MODE); | |
| 80 } | 95 } |
| 81 }; | 96 }; |
| 82 | 97 |
| 83 // Check that |TRACE_EVENT| macros push and pop to the pseudo stack correctly. | 98 // Check that |TRACE_EVENT| macros push and pop to the pseudo stack correctly. |
| 84 TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) { | 99 TEST_F(AllocationContextTrackerTest, PseudoStackScopedTrace) { |
| 85 StackFrame t = StackFrame::FromThreadName(kThreadName); | 100 StackFrame t = StackFrame::FromThreadName(kThreadName); |
| 86 StackFrame c = StackFrame::FromTraceEventName(kCupcake); | 101 StackFrame c = StackFrame::FromTraceEventName(kCupcake); |
| 87 StackFrame d = StackFrame::FromTraceEventName(kDonut); | 102 StackFrame d = StackFrame::FromTraceEventName(kDonut); |
| 88 StackFrame e = StackFrame::FromTraceEventName(kEclair); | 103 StackFrame e = StackFrame::FromTraceEventName(kEclair); |
| 89 StackFrame f = StackFrame::FromTraceEventName(kFroyo); | 104 StackFrame f = StackFrame::FromTraceEventName(kFroyo); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 AllocationContextTracker::GetInstanceForCurrentThread() | 316 AllocationContextTracker::GetInstanceForCurrentThread() |
| 302 ->GetContextSnapshot(); | 317 ->GetContextSnapshot(); |
| 303 const StringPiece kTracingOverhead("tracing_overhead"); | 318 const StringPiece kTracingOverhead("tracing_overhead"); |
| 304 ASSERT_EQ(kTracingOverhead, | 319 ASSERT_EQ(kTracingOverhead, |
| 305 static_cast<const char*>(ctx.backtrace.frames[0].value)); | 320 static_cast<const char*>(ctx.backtrace.frames[0].value)); |
| 306 ASSERT_EQ(1u, ctx.backtrace.frame_count); | 321 ASSERT_EQ(1u, ctx.backtrace.frame_count); |
| 307 } | 322 } |
| 308 | 323 |
| 309 } // namespace trace_event | 324 } // namespace trace_event |
| 310 } // namespace base | 325 } // namespace base |
| OLD | NEW |