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

Side by Side Diff: base/debug/activity_analyzer_unittest.cc

Issue 2235273002: Refactor embedded structures to top-level scope. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed new ResourceData class (for later CL) Created 4 years, 4 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
« no previous file with comments | « base/debug/activity_analyzer.h ('k') | base/debug/activity_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/activity_tracker.h" 10 #include "base/debug/activity_tracker.h"
(...skipping 30 matching lines...) Expand all
41 }; 41 };
42 42
43 } // namespace 43 } // namespace
44 44
45 45
46 class ActivityAnalyzerTest : public testing::Test { 46 class ActivityAnalyzerTest : public testing::Test {
47 public: 47 public:
48 const int kMemorySize = 1 << 10; // 1MiB 48 const int kMemorySize = 1 << 10; // 1MiB
49 const int kStackSize = 1 << 10; // 1KiB 49 const int kStackSize = 1 << 10; // 1KiB
50 50
51 using Activity = ThreadActivityAnalyzer::Activity;
52
53 ActivityAnalyzerTest() {} 51 ActivityAnalyzerTest() {}
54 52
55 ~ActivityAnalyzerTest() override { 53 ~ActivityAnalyzerTest() override {
56 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get(); 54 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get();
57 if (global_tracker) { 55 if (global_tracker) {
58 global_tracker->ReleaseTrackerForCurrentThreadForTesting(); 56 global_tracker->ReleaseTrackerForCurrentThreadForTesting();
59 delete global_tracker; 57 delete global_tracker;
60 } 58 }
61 } 59 }
62 60
(...skipping 16 matching lines...) Expand all
79 // TODO(bcwhite): More tests once Analyzer does more. 77 // TODO(bcwhite): More tests once Analyzer does more.
80 } 78 }
81 79
82 80
83 // GlobalActivityAnalyzer tests below. 81 // GlobalActivityAnalyzer tests below.
84 82
85 class SimpleActivityThread : public SimpleThread { 83 class SimpleActivityThread : public SimpleThread {
86 public: 84 public:
87 SimpleActivityThread(const std::string& name, 85 SimpleActivityThread(const std::string& name,
88 const void* source, 86 const void* source,
89 ThreadActivityTracker::ActivityType activity, 87 Activity::Type activity,
90 const ThreadActivityTracker::ActivityData& data) 88 const ActivityData& data)
91 : SimpleThread(name, Options()), 89 : SimpleThread(name, Options()),
92 source_(source), 90 source_(source),
93 activity_(activity), 91 activity_(activity),
94 data_(data), 92 data_(data),
95 exit_condition_(&lock_) {} 93 exit_condition_(&lock_) {}
96 94
97 ~SimpleActivityThread() override {} 95 ~SimpleActivityThread() override {}
98 96
99 void Run() override { 97 void Run() override {
100 GlobalActivityTracker::Get() 98 GlobalActivityTracker::Get()
(...skipping 17 matching lines...) Expand all
118 exit_ = true; 116 exit_ = true;
119 exit_condition_.Signal(); 117 exit_condition_.Signal();
120 } 118 }
121 119
122 void WaitReady() { 120 void WaitReady() {
123 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(ready_); 121 SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(ready_);
124 } 122 }
125 123
126 private: 124 private:
127 const void* source_; 125 const void* source_;
128 ThreadActivityTracker::ActivityType activity_; 126 Activity::Type activity_;
129 ThreadActivityTracker::ActivityData data_; 127 ActivityData data_;
130 128
131 bool ready_ = false; 129 bool ready_ = false;
132 bool exit_ = false; 130 bool exit_ = false;
133 Lock lock_; 131 Lock lock_;
134 ConditionVariable exit_condition_; 132 ConditionVariable exit_condition_;
135 133
136 DISALLOW_COPY_AND_ASSIGN(SimpleActivityThread); 134 DISALLOW_COPY_AND_ASSIGN(SimpleActivityThread);
137 }; 135 };
138 136
139 TEST_F(ActivityAnalyzerTest, GlobalAnalyzerConstruction) { 137 TEST_F(ActivityAnalyzerTest, GlobalAnalyzerConstruction) {
140 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3); 138 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3);
141 139
142 PersistentMemoryAllocator* allocator = 140 PersistentMemoryAllocator* allocator =
143 GlobalActivityTracker::Get()->allocator(); 141 GlobalActivityTracker::Get()->allocator();
144 GlobalActivityAnalyzer analyzer(WrapUnique( 142 GlobalActivityAnalyzer analyzer(WrapUnique(
145 new PersistentMemoryAllocator(const_cast<void*>(allocator->data()), 143 new PersistentMemoryAllocator(const_cast<void*>(allocator->data()),
146 allocator->size(), 0, 0, "", true))); 144 allocator->size(), 0, 0, "", true)));
147 145
148 // The only thread at thois point is the test thread. 146 // The only thread at thois point is the test thread.
149 ThreadActivityAnalyzer* ta1 = analyzer.GetFirstAnalyzer(); 147 ThreadActivityAnalyzer* ta1 = analyzer.GetFirstAnalyzer();
150 ASSERT_TRUE(ta1); 148 ASSERT_TRUE(ta1);
151 EXPECT_FALSE(analyzer.GetNextAnalyzer()); 149 EXPECT_FALSE(analyzer.GetNextAnalyzer());
152 ThreadActivityAnalyzer::ThreadKey tk1 = ta1->GetThreadKey(); 150 ThreadActivityAnalyzer::ThreadKey tk1 = ta1->GetThreadKey();
153 EXPECT_EQ(ta1, analyzer.GetAnalyzerForThread(tk1)); 151 EXPECT_EQ(ta1, analyzer.GetAnalyzerForThread(tk1));
154 152
155 // Create a second thread that will do something. 153 // Create a second thread that will do something.
156 SimpleActivityThread t2("t2", nullptr, ThreadActivityTracker::ACT_TASK, 154 SimpleActivityThread t2("t2", nullptr, Activity::ACT_TASK,
157 ThreadActivityTracker::ActivityData::ForTask(11)); 155 ActivityData::ForTask(11));
158 t2.Start(); 156 t2.Start();
159 t2.WaitReady(); 157 t2.WaitReady();
160 158
161 // Now there should be two. 159 // Now there should be two.
162 EXPECT_TRUE(analyzer.GetFirstAnalyzer()); 160 EXPECT_TRUE(analyzer.GetFirstAnalyzer());
163 EXPECT_TRUE(analyzer.GetNextAnalyzer()); 161 EXPECT_TRUE(analyzer.GetNextAnalyzer());
164 EXPECT_FALSE(analyzer.GetNextAnalyzer()); 162 EXPECT_FALSE(analyzer.GetNextAnalyzer());
165 163
166 // Let thread exit. 164 // Let thread exit.
167 t2.Exit(); 165 t2.Exit();
168 t2.Join(); 166 t2.Join();
169 167
170 // Now there should be only one again. Calling GetFirstAnalyzer invalidates 168 // Now there should be only one again. Calling GetFirstAnalyzer invalidates
171 // any previously returned analyzer pointers. 169 // any previously returned analyzer pointers.
172 ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer(); 170 ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer();
173 ASSERT_TRUE(ta2); 171 ASSERT_TRUE(ta2);
174 EXPECT_FALSE(analyzer.GetNextAnalyzer()); 172 EXPECT_FALSE(analyzer.GetNextAnalyzer());
175 ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey(); 173 ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey();
176 EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2)); 174 EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2));
177 EXPECT_EQ(tk1, tk2); 175 EXPECT_EQ(tk1, tk2);
178 } 176 }
179 177
180 } // namespace debug 178 } // namespace debug
181 } // namespace base 179 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/activity_analyzer.h ('k') | base/debug/activity_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698