| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/debug/activity_analyzer.h" | 5 #include "base/debug/activity_analyzer.h" |
| 6 | 6 |
| 7 #include <atomic> | 7 #include <atomic> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 ~ActivityAnalyzerTest() override { | 54 ~ActivityAnalyzerTest() override { |
| 55 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get(); | 55 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get(); |
| 56 if (global_tracker) { | 56 if (global_tracker) { |
| 57 global_tracker->ReleaseTrackerForCurrentThreadForTesting(); | 57 global_tracker->ReleaseTrackerForCurrentThreadForTesting(); |
| 58 delete global_tracker; | 58 delete global_tracker; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 std::unique_ptr<ThreadActivityTracker> CreateActivityTracker() { | 62 std::unique_ptr<ThreadActivityTracker> CreateActivityTracker() { |
| 63 std::unique_ptr<char[]> memory(new char[kStackSize]); | 63 std::unique_ptr<char[]> memory(new char[kStackSize]); |
| 64 return WrapUnique(new TestActivityTracker(std::move(memory), kStackSize)); | 64 return MakeUnique<TestActivityTracker>(std::move(memory), kStackSize); |
| 65 } | 65 } |
| 66 | 66 |
| 67 static void DoNothing() {} | 67 static void DoNothing() {} |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TEST_F(ActivityAnalyzerTest, ThreadAnalyzerConstruction) { | 70 TEST_F(ActivityAnalyzerTest, ThreadAnalyzerConstruction) { |
| 71 std::unique_ptr<ThreadActivityTracker> tracker = CreateActivityTracker(); | 71 std::unique_ptr<ThreadActivityTracker> tracker = CreateActivityTracker(); |
| 72 { | 72 { |
| 73 ThreadActivityAnalyzer analyzer(*tracker); | 73 ThreadActivityAnalyzer analyzer(*tracker); |
| 74 EXPECT_TRUE(analyzer.IsValid()); | 74 EXPECT_TRUE(analyzer.IsValid()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ConditionVariable exit_condition_; | 135 ConditionVariable exit_condition_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(SimpleActivityThread); | 137 DISALLOW_COPY_AND_ASSIGN(SimpleActivityThread); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 TEST_F(ActivityAnalyzerTest, GlobalAnalyzerConstruction) { | 140 TEST_F(ActivityAnalyzerTest, GlobalAnalyzerConstruction) { |
| 141 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3); | 141 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3); |
| 142 | 142 |
| 143 PersistentMemoryAllocator* allocator = | 143 PersistentMemoryAllocator* allocator = |
| 144 GlobalActivityTracker::Get()->allocator(); | 144 GlobalActivityTracker::Get()->allocator(); |
| 145 GlobalActivityAnalyzer analyzer(WrapUnique( | 145 GlobalActivityAnalyzer analyzer(MakeUnique<PersistentMemoryAllocator>( |
| 146 new PersistentMemoryAllocator(const_cast<void*>(allocator->data()), | 146 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true)); |
| 147 allocator->size(), 0, 0, "", true))); | |
| 148 | 147 |
| 149 // The only thread at thois point is the test thread. | 148 // The only thread at thois point is the test thread. |
| 150 ThreadActivityAnalyzer* ta1 = analyzer.GetFirstAnalyzer(); | 149 ThreadActivityAnalyzer* ta1 = analyzer.GetFirstAnalyzer(); |
| 151 ASSERT_TRUE(ta1); | 150 ASSERT_TRUE(ta1); |
| 152 EXPECT_FALSE(analyzer.GetNextAnalyzer()); | 151 EXPECT_FALSE(analyzer.GetNextAnalyzer()); |
| 153 ThreadActivityAnalyzer::ThreadKey tk1 = ta1->GetThreadKey(); | 152 ThreadActivityAnalyzer::ThreadKey tk1 = ta1->GetThreadKey(); |
| 154 EXPECT_EQ(ta1, analyzer.GetAnalyzerForThread(tk1)); | 153 EXPECT_EQ(ta1, analyzer.GetAnalyzerForThread(tk1)); |
| 155 | 154 |
| 156 // Create a second thread that will do something. | 155 // Create a second thread that will do something. |
| 157 SimpleActivityThread t2("t2", nullptr, Activity::ACT_TASK, | 156 SimpleActivityThread t2("t2", nullptr, Activity::ACT_TASK, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer(); | 172 ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer(); |
| 174 ASSERT_TRUE(ta2); | 173 ASSERT_TRUE(ta2); |
| 175 EXPECT_FALSE(analyzer.GetNextAnalyzer()); | 174 EXPECT_FALSE(analyzer.GetNextAnalyzer()); |
| 176 ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey(); | 175 ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey(); |
| 177 EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2)); | 176 EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2)); |
| 178 EXPECT_EQ(tk1, tk2); | 177 EXPECT_EQ(tk1, tk2); |
| 179 } | 178 } |
| 180 | 179 |
| 181 } // namespace debug | 180 } // namespace debug |
| 182 } // namespace base | 181 } // namespace base |
| OLD | NEW |