| 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\"]" |
| 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(config, TraceLog::RECORDING_MODE); |
| 73 AllocationContextTracker::SetCurrentThreadName(kThreadName); | 86 AllocationContextTracker::SetCurrentThreadName(kThreadName); |
| 74 } | 87 } |
| 75 | 88 |
| 76 void TearDown() override { | 89 void TearDown() override { |
| 77 AllocationContextTracker::SetCaptureMode( | 90 AllocationContextTracker::SetCaptureMode( |
| 78 AllocationContextTracker::CaptureMode::DISABLED); | 91 AllocationContextTracker::CaptureMode::DISABLED); |
| 79 TraceLog::GetInstance()->SetDisabled(); | 92 TraceLog::GetInstance()->SetDisabled(); |
| 80 } | 93 } |
| 81 }; | 94 }; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 AllocationContextTracker::GetInstanceForCurrentThread() | 314 AllocationContextTracker::GetInstanceForCurrentThread() |
| 302 ->GetContextSnapshot(); | 315 ->GetContextSnapshot(); |
| 303 const StringPiece kTracingOverhead("tracing_overhead"); | 316 const StringPiece kTracingOverhead("tracing_overhead"); |
| 304 ASSERT_EQ(kTracingOverhead, | 317 ASSERT_EQ(kTracingOverhead, |
| 305 static_cast<const char*>(ctx.backtrace.frames[0].value)); | 318 static_cast<const char*>(ctx.backtrace.frames[0].value)); |
| 306 ASSERT_EQ(1u, ctx.backtrace.frame_count); | 319 ASSERT_EQ(1u, ctx.backtrace.frame_count); |
| 307 } | 320 } |
| 308 | 321 |
| 309 } // namespace trace_event | 322 } // namespace trace_event |
| 310 } // namespace base | 323 } // namespace base |
| OLD | NEW |