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 "base/trace_event/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, | 85 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, |
86 Closure closure, | 86 Closure closure, |
87 uint64 dump_guid, | 87 uint64 dump_guid, |
88 bool success) { | 88 bool success) { |
89 last_callback_success_ = success; | 89 last_callback_success_ = success; |
90 task_runner->PostTask(FROM_HERE, closure); | 90 task_runner->PostTask(FROM_HERE, closure); |
91 } | 91 } |
92 | 92 |
93 protected: | 93 protected: |
94 void InitializeMemoryDumpManager(bool is_coordinator) { | 94 void InitializeMemoryDumpManager(bool is_coordinator) { |
95 mdm_->set_dumper_registrations_ignored_for_testing(true); | |
95 mdm_->Initialize(delegate_.get(), is_coordinator); | 96 mdm_->Initialize(delegate_.get(), is_coordinator); |
96 } | 97 } |
97 | 98 |
98 void EnableTracingWithLegacyCategories(const char* category) { | 99 void EnableTracingWithLegacyCategories(const char* category) { |
99 TraceLog::GetInstance()->SetEnabled(TraceConfig(category, ""), | 100 TraceLog::GetInstance()->SetEnabled(TraceConfig(category, ""), |
100 TraceLog::RECORDING_MODE); | 101 TraceLog::RECORDING_MODE); |
101 } | 102 } |
102 | 103 |
103 void EnableTracingWithTraceConfig(const std::string& trace_config) { | 104 void EnableTracingWithTraceConfig(const std::string& trace_config) { |
104 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), | 105 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), |
105 TraceLog::RECORDING_MODE); | 106 TraceLog::RECORDING_MODE); |
106 } | 107 } |
107 | 108 |
108 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } | 109 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } |
109 | 110 |
111 void RegisterDumpProvider(MemoryDumpProvider* mdp) { | |
Primiano Tucci (use gerrit)
2015/10/13 13:35:50
This could be made a standalone method in the anon
Ruud van Asseldonk
2015/10/13 13:55:41
As you wish.
| |
112 mdm_->set_dumper_registrations_ignored_for_testing(false); | |
Primiano Tucci (use gerrit)
2015/10/13 13:35:50
you can just call RegisterDumpProvider(mdp, nullpt
Ruud van Asseldonk
2015/10/13 13:55:41
Done.
| |
113 mdm_->RegisterDumpProvider(mdp); | |
114 mdm_->set_dumper_registrations_ignored_for_testing(true); | |
115 } | |
116 | |
117 void RegisterDumpProvider( | |
118 MemoryDumpProvider* mdp, | |
119 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | |
120 mdm_->set_dumper_registrations_ignored_for_testing(false); | |
121 mdm_->RegisterDumpProvider(mdp, task_runner); | |
122 mdm_->set_dumper_registrations_ignored_for_testing(true); | |
123 } | |
124 | |
110 bool IsPeriodicDumpingEnabled() const { | 125 bool IsPeriodicDumpingEnabled() const { |
111 return mdm_->periodic_dump_timer_.IsRunning(); | 126 return mdm_->periodic_dump_timer_.IsRunning(); |
112 } | 127 } |
113 | 128 |
114 int GetMaxConsecutiveFailuresCount() const { | 129 int GetMaxConsecutiveFailuresCount() const { |
115 return MemoryDumpManager::kMaxConsecutiveFailuresCount; | 130 return MemoryDumpManager::kMaxConsecutiveFailuresCount; |
116 } | 131 } |
117 | 132 |
118 scoped_ptr<MemoryDumpManager> mdm_; | 133 scoped_ptr<MemoryDumpManager> mdm_; |
119 scoped_ptr<MemoryDumpManagerDelegateForTesting> delegate_; | 134 scoped_ptr<MemoryDumpManagerDelegateForTesting> delegate_; |
120 bool last_callback_success_; | 135 bool last_callback_success_; |
121 | 136 |
122 private: | 137 private: |
123 scoped_ptr<MessageLoop> message_loop_; | 138 scoped_ptr<MessageLoop> message_loop_; |
124 | 139 |
125 // We want our singleton torn down after each test. | 140 // We want our singleton torn down after each test. |
126 ShadowingAtExitManager at_exit_manager_; | 141 ShadowingAtExitManager at_exit_manager_; |
127 }; | 142 }; |
128 | 143 |
129 // Basic sanity checks. Registers a memory dump provider and checks that it is | 144 // Basic sanity checks. Registers a memory dump provider and checks that it is |
130 // called, but only when memory-infra is enabled. | 145 // called, but only when memory-infra is enabled. |
131 TEST_F(MemoryDumpManagerTest, SingleDumper) { | 146 TEST_F(MemoryDumpManagerTest, SingleDumper) { |
132 InitializeMemoryDumpManager(false /* is_coordinator */); | 147 InitializeMemoryDumpManager(false /* is_coordinator */); |
133 MockMemoryDumpProvider mdp; | 148 MockMemoryDumpProvider mdp; |
134 mdm_->RegisterDumpProvider(&mdp); | 149 RegisterDumpProvider(&mdp); |
135 | 150 |
136 // Check that the dumper is not called if the memory category is not enabled. | 151 // Check that the dumper is not called if the memory category is not enabled. |
137 EnableTracingWithLegacyCategories("foobar-but-not-memory"); | 152 EnableTracingWithLegacyCategories("foobar-but-not-memory"); |
138 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 153 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
139 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 154 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
140 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 155 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
141 MemoryDumpLevelOfDetail::DETAILED); | 156 MemoryDumpLevelOfDetail::DETAILED); |
142 DisableTracing(); | 157 DisableTracing(); |
143 | 158 |
144 // Now repeat enabling the memory category and check that the dumper is | 159 // Now repeat enabling the memory category and check that the dumper is |
(...skipping 17 matching lines...) Expand all Loading... | |
162 MemoryDumpLevelOfDetail::DETAILED); | 177 MemoryDumpLevelOfDetail::DETAILED); |
163 TraceLog::GetInstance()->SetDisabled(); | 178 TraceLog::GetInstance()->SetDisabled(); |
164 } | 179 } |
165 | 180 |
166 // Checks that requesting dumps with high level of detail actually propagates | 181 // Checks that requesting dumps with high level of detail actually propagates |
167 // the level of the detail properly to OnMemoryDump() call on dump providers. | 182 // the level of the detail properly to OnMemoryDump() call on dump providers. |
168 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 183 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
169 InitializeMemoryDumpManager(false /* is_coordinator */); | 184 InitializeMemoryDumpManager(false /* is_coordinator */); |
170 MockMemoryDumpProvider mdp; | 185 MockMemoryDumpProvider mdp; |
171 | 186 |
172 mdm_->RegisterDumpProvider(&mdp); | 187 RegisterDumpProvider(&mdp); |
173 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 188 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
174 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 189 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
175 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); | 190 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true)); |
176 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 191 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
177 MemoryDumpLevelOfDetail::DETAILED); | 192 MemoryDumpLevelOfDetail::DETAILED); |
178 DisableTracing(); | 193 DisableTracing(); |
179 mdm_->UnregisterDumpProvider(&mdp); | 194 mdm_->UnregisterDumpProvider(&mdp); |
180 | 195 |
181 // Check that requesting dumps with low level of detail actually propagates to | 196 // Check that requesting dumps with low level of detail actually propagates to |
182 // OnMemoryDump() call on dump providers. | 197 // OnMemoryDump() call on dump providers. |
183 mdm_->RegisterDumpProvider(&mdp); | 198 RegisterDumpProvider(&mdp); |
184 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 199 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
185 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 200 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
186 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); | 201 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); |
187 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 202 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
188 MemoryDumpLevelOfDetail::LIGHT); | 203 MemoryDumpLevelOfDetail::LIGHT); |
189 DisableTracing(); | 204 DisableTracing(); |
190 mdm_->UnregisterDumpProvider(&mdp); | 205 mdm_->UnregisterDumpProvider(&mdp); |
191 } | 206 } |
192 | 207 |
193 // Checks that the SharedSessionState object is acqually shared over time. | 208 // Checks that the SharedSessionState object is acqually shared over time. |
194 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 209 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
195 InitializeMemoryDumpManager(false /* is_coordinator */); | 210 InitializeMemoryDumpManager(false /* is_coordinator */); |
196 MockMemoryDumpProvider mdp1; | 211 MockMemoryDumpProvider mdp1; |
197 MockMemoryDumpProvider mdp2; | 212 MockMemoryDumpProvider mdp2; |
198 mdm_->RegisterDumpProvider(&mdp1); | 213 RegisterDumpProvider(&mdp1); |
199 mdm_->RegisterDumpProvider(&mdp2); | 214 RegisterDumpProvider(&mdp2); |
200 | 215 |
201 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 216 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
202 const MemoryDumpSessionState* session_state = mdm_->session_state().get(); | 217 const MemoryDumpSessionState* session_state = mdm_->session_state().get(); |
203 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); | 218 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(2); |
204 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 219 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
205 .Times(2) | 220 .Times(2) |
206 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 221 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, |
207 ProcessMemoryDump* pmd) -> bool { | 222 ProcessMemoryDump* pmd) -> bool { |
208 EXPECT_EQ(session_state, pmd->session_state().get()); | 223 EXPECT_EQ(session_state, pmd->session_state().get()); |
209 return true; | 224 return true; |
(...skipping 13 matching lines...) Expand all Loading... | |
223 DisableTracing(); | 238 DisableTracing(); |
224 } | 239 } |
225 | 240 |
226 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. | 241 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. |
227 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { | 242 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
228 InitializeMemoryDumpManager(false /* is_coordinator */); | 243 InitializeMemoryDumpManager(false /* is_coordinator */); |
229 MockMemoryDumpProvider mdp1; | 244 MockMemoryDumpProvider mdp1; |
230 MockMemoryDumpProvider mdp2; | 245 MockMemoryDumpProvider mdp2; |
231 | 246 |
232 // Enable only mdp1. | 247 // Enable only mdp1. |
233 mdm_->RegisterDumpProvider(&mdp1); | 248 RegisterDumpProvider(&mdp1); |
234 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 249 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
235 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 250 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
236 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 251 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
237 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 252 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
238 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 253 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
239 MemoryDumpLevelOfDetail::DETAILED); | 254 MemoryDumpLevelOfDetail::DETAILED); |
240 DisableTracing(); | 255 DisableTracing(); |
241 | 256 |
242 // Invert: enable mdp1 and disable mdp2. | 257 // Invert: enable mdp1 and disable mdp2. |
243 mdm_->UnregisterDumpProvider(&mdp1); | 258 mdm_->UnregisterDumpProvider(&mdp1); |
244 mdm_->RegisterDumpProvider(&mdp2); | 259 RegisterDumpProvider(&mdp2); |
245 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 260 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
246 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 261 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
247 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 262 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
248 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 263 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
249 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 264 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
250 MemoryDumpLevelOfDetail::DETAILED); | 265 MemoryDumpLevelOfDetail::DETAILED); |
251 DisableTracing(); | 266 DisableTracing(); |
252 | 267 |
253 // Enable both mdp1 and mdp2. | 268 // Enable both mdp1 and mdp2. |
254 mdm_->RegisterDumpProvider(&mdp1); | 269 RegisterDumpProvider(&mdp1); |
255 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 270 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
256 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 271 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
257 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); | 272 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); |
258 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); | 273 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); |
259 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 274 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
260 MemoryDumpLevelOfDetail::DETAILED); | 275 MemoryDumpLevelOfDetail::DETAILED); |
261 DisableTracing(); | 276 DisableTracing(); |
262 } | 277 } |
263 | 278 |
264 // Checks that the dump provider invocations depend only on the current | 279 // Checks that the dump provider invocations depend only on the current |
265 // registration state and not on previous registrations and dumps. | 280 // registration state and not on previous registrations and dumps. |
266 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { | 281 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { |
267 InitializeMemoryDumpManager(false /* is_coordinator */); | 282 InitializeMemoryDumpManager(false /* is_coordinator */); |
268 MockMemoryDumpProvider mdp; | 283 MockMemoryDumpProvider mdp; |
269 | 284 |
270 mdm_->RegisterDumpProvider(&mdp); | 285 RegisterDumpProvider(&mdp); |
271 | 286 |
272 { | 287 { |
273 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 288 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
274 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 289 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
275 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 290 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
276 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 291 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
277 MemoryDumpLevelOfDetail::DETAILED); | 292 MemoryDumpLevelOfDetail::DETAILED); |
278 DisableTracing(); | 293 DisableTracing(); |
279 } | 294 } |
280 | 295 |
281 mdm_->UnregisterDumpProvider(&mdp); | 296 mdm_->UnregisterDumpProvider(&mdp); |
282 | 297 |
283 { | 298 { |
284 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 299 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
285 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 300 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
286 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 301 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
287 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 302 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
288 MemoryDumpLevelOfDetail::DETAILED); | 303 MemoryDumpLevelOfDetail::DETAILED); |
289 DisableTracing(); | 304 DisableTracing(); |
290 } | 305 } |
291 | 306 |
292 mdm_->RegisterDumpProvider(&mdp); | 307 RegisterDumpProvider(&mdp); |
293 mdm_->UnregisterDumpProvider(&mdp); | 308 mdm_->UnregisterDumpProvider(&mdp); |
294 | 309 |
295 { | 310 { |
296 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 311 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
297 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 312 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
298 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 313 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
299 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 314 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
300 MemoryDumpLevelOfDetail::DETAILED); | 315 MemoryDumpLevelOfDetail::DETAILED); |
301 DisableTracing(); | 316 DisableTracing(); |
302 } | 317 } |
303 | 318 |
304 mdm_->RegisterDumpProvider(&mdp); | 319 RegisterDumpProvider(&mdp); |
305 mdm_->UnregisterDumpProvider(&mdp); | 320 mdm_->UnregisterDumpProvider(&mdp); |
306 mdm_->RegisterDumpProvider(&mdp); | 321 RegisterDumpProvider(&mdp); |
307 | 322 |
308 { | 323 { |
309 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); | 324 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
310 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); | 325 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); |
311 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 326 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
312 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 327 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
313 MemoryDumpLevelOfDetail::DETAILED); | 328 MemoryDumpLevelOfDetail::DETAILED); |
314 DisableTracing(); | 329 DisableTracing(); |
315 } | 330 } |
316 } | 331 } |
(...skipping 12 matching lines...) Expand all Loading... | |
329 // Create the threads and setup the expectations. Given that at each iteration | 344 // Create the threads and setup the expectations. Given that at each iteration |
330 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be | 345 // we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be |
331 // invoked a number of times equal to its index. | 346 // invoked a number of times equal to its index. |
332 for (uint32 i = kNumInitialThreads; i > 0; --i) { | 347 for (uint32 i = kNumInitialThreads; i > 0; --i) { |
333 Thread* thread = new Thread("test thread"); | 348 Thread* thread = new Thread("test thread"); |
334 threads.push_back(thread); | 349 threads.push_back(thread); |
335 threads.back()->Start(); | 350 threads.back()->Start(); |
336 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); | 351 scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner(); |
337 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider(); | 352 MockMemoryDumpProvider* mdp = new MockMemoryDumpProvider(); |
338 mdps.push_back(mdp); | 353 mdps.push_back(mdp); |
339 mdm_->RegisterDumpProvider(mdp, task_runner); | 354 RegisterDumpProvider(mdp, task_runner); |
340 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) | 355 EXPECT_CALL(*mdp, OnMemoryDump(_, _)) |
341 .Times(i) | 356 .Times(i) |
342 .WillRepeatedly(Invoke( | 357 .WillRepeatedly(Invoke( |
343 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 358 [task_runner](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
344 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); | 359 EXPECT_TRUE(task_runner->RunsTasksOnCurrentThread()); |
345 return true; | 360 return true; |
346 })); | 361 })); |
347 } | 362 } |
348 | 363 |
349 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 364 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 DisableTracing(); | 399 DisableTracing(); |
385 } | 400 } |
386 | 401 |
387 // Checks that providers get disabled after 3 consecutive failures, but not | 402 // Checks that providers get disabled after 3 consecutive failures, but not |
388 // otherwise (e.g., if interleaved). | 403 // otherwise (e.g., if interleaved). |
389 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { | 404 TEST_F(MemoryDumpManagerTest, DisableFailingDumpers) { |
390 InitializeMemoryDumpManager(false /* is_coordinator */); | 405 InitializeMemoryDumpManager(false /* is_coordinator */); |
391 MockMemoryDumpProvider mdp1; | 406 MockMemoryDumpProvider mdp1; |
392 MockMemoryDumpProvider mdp2; | 407 MockMemoryDumpProvider mdp2; |
393 | 408 |
394 mdm_->RegisterDumpProvider(&mdp1); | 409 RegisterDumpProvider(&mdp1); |
395 mdm_->RegisterDumpProvider(&mdp2); | 410 RegisterDumpProvider(&mdp2); |
396 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 411 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
397 | 412 |
398 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); | 413 const int kNumDumps = 2 * GetMaxConsecutiveFailuresCount(); |
399 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); | 414 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(kNumDumps); |
400 | 415 |
401 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 416 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
402 .Times(GetMaxConsecutiveFailuresCount()) | 417 .Times(GetMaxConsecutiveFailuresCount()) |
403 .WillRepeatedly(Return(false)); | 418 .WillRepeatedly(Return(false)); |
404 | 419 |
405 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 420 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
(...skipping 12 matching lines...) Expand all Loading... | |
418 DisableTracing(); | 433 DisableTracing(); |
419 } | 434 } |
420 | 435 |
421 // Sneakily registers an extra memory dump provider while an existing one is | 436 // Sneakily registers an extra memory dump provider while an existing one is |
422 // dumping and expect it to take part in the already active tracing session. | 437 // dumping and expect it to take part in the already active tracing session. |
423 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { | 438 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
424 InitializeMemoryDumpManager(false /* is_coordinator */); | 439 InitializeMemoryDumpManager(false /* is_coordinator */); |
425 MockMemoryDumpProvider mdp1; | 440 MockMemoryDumpProvider mdp1; |
426 MockMemoryDumpProvider mdp2; | 441 MockMemoryDumpProvider mdp2; |
427 | 442 |
428 mdm_->RegisterDumpProvider(&mdp1); | 443 RegisterDumpProvider(&mdp1); |
429 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 444 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
430 | 445 |
431 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 446 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); |
432 | 447 |
433 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 448 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
434 .Times(4) | 449 .Times(4) |
435 .WillOnce(Return(true)) | 450 .WillOnce(Return(true)) |
436 .WillOnce( | 451 .WillOnce(Invoke( |
437 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 452 [this, &mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
Primiano Tucci (use gerrit)
2015/10/13 13:35:50
if you move RegisterDumpProvider to the anonymous
Ruud van Asseldonk
2015/10/13 13:55:41
Done.
| |
438 MemoryDumpManager::GetInstance()->RegisterDumpProvider(&mdp2); | 453 RegisterDumpProvider(&mdp2); |
439 return true; | 454 return true; |
440 })) | 455 })) |
441 .WillRepeatedly(Return(true)); | 456 .WillRepeatedly(Return(true)); |
442 | 457 |
443 // Depending on the insertion order (before or after mdp1), mdp2 might be | 458 // Depending on the insertion order (before or after mdp1), mdp2 might be |
444 // called also immediately after it gets registered. | 459 // called also immediately after it gets registered. |
445 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 460 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
446 .Times(Between(2, 3)) | 461 .Times(Between(2, 3)) |
447 .WillRepeatedly(Return(true)); | 462 .WillRepeatedly(Return(true)); |
448 | 463 |
449 for (int i = 0; i < 4; i++) { | 464 for (int i = 0; i < 4; i++) { |
450 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 465 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
451 MemoryDumpLevelOfDetail::DETAILED); | 466 MemoryDumpLevelOfDetail::DETAILED); |
452 } | 467 } |
453 | 468 |
454 DisableTracing(); | 469 DisableTracing(); |
455 } | 470 } |
456 | 471 |
457 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. | 472 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. |
458 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { | 473 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
459 InitializeMemoryDumpManager(false /* is_coordinator */); | 474 InitializeMemoryDumpManager(false /* is_coordinator */); |
460 MockMemoryDumpProvider mdp1; | 475 MockMemoryDumpProvider mdp1; |
461 MockMemoryDumpProvider mdp2; | 476 MockMemoryDumpProvider mdp2; |
462 | 477 |
463 mdm_->RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); | 478 RegisterDumpProvider(&mdp1, ThreadTaskRunnerHandle::Get()); |
464 mdm_->RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); | 479 RegisterDumpProvider(&mdp2, ThreadTaskRunnerHandle::Get()); |
465 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 480 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
466 | 481 |
467 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); | 482 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(4); |
468 | 483 |
469 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 484 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
470 .Times(4) | 485 .Times(4) |
471 .WillOnce(Return(true)) | 486 .WillOnce(Return(true)) |
472 .WillOnce( | 487 .WillOnce( |
473 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { | 488 Invoke([&mdp2](const MemoryDumpArgs&, ProcessMemoryDump*) -> bool { |
474 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); | 489 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(&mdp2); |
(...skipping 18 matching lines...) Expand all Loading... | |
493 // Checks that the dump does not abort when unregistering a provider while | 508 // Checks that the dump does not abort when unregistering a provider while |
494 // dumping from a different thread than the dumping thread. | 509 // dumping from a different thread than the dumping thread. |
495 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { | 510 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { |
496 InitializeMemoryDumpManager(false /* is_coordinator */); | 511 InitializeMemoryDumpManager(false /* is_coordinator */); |
497 ScopedVector<TestIOThread> threads; | 512 ScopedVector<TestIOThread> threads; |
498 ScopedVector<MockMemoryDumpProvider> mdps; | 513 ScopedVector<MockMemoryDumpProvider> mdps; |
499 | 514 |
500 for (int i = 0; i < 2; i++) { | 515 for (int i = 0; i < 2; i++) { |
501 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); | 516 threads.push_back(new TestIOThread(TestIOThread::kAutoStart)); |
502 mdps.push_back(new MockMemoryDumpProvider()); | 517 mdps.push_back(new MockMemoryDumpProvider()); |
503 mdm_->RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); | 518 RegisterDumpProvider(mdps.back(), threads.back()->task_runner()); |
504 } | 519 } |
505 | 520 |
506 int on_memory_dump_call_count = 0; | 521 int on_memory_dump_call_count = 0; |
507 RunLoop run_loop; | 522 RunLoop run_loop; |
508 | 523 |
509 // When OnMemoryDump is called on either of the dump providers, it will | 524 // When OnMemoryDump is called on either of the dump providers, it will |
510 // unregister the other one. | 525 // unregister the other one. |
511 for (MockMemoryDumpProvider* mdp : mdps) { | 526 for (MockMemoryDumpProvider* mdp : mdps) { |
512 int other_idx = (mdps.front() == mdp); | 527 int other_idx = (mdps.front() == mdp); |
513 TestIOThread* other_thread = threads[other_idx]; | 528 TestIOThread* other_thread = threads[other_idx]; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 ASSERT_EQ(true, last_callback_success_); | 560 ASSERT_EQ(true, last_callback_success_); |
546 | 561 |
547 DisableTracing(); | 562 DisableTracing(); |
548 } | 563 } |
549 | 564 |
550 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when | 565 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when |
551 // tracing is not enabled. | 566 // tracing is not enabled. |
552 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { | 567 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
553 InitializeMemoryDumpManager(false /* is_coordinator */); | 568 InitializeMemoryDumpManager(false /* is_coordinator */); |
554 MockMemoryDumpProvider mdp1; | 569 MockMemoryDumpProvider mdp1; |
555 mdm_->RegisterDumpProvider(&mdp1); | 570 RegisterDumpProvider(&mdp1); |
556 | 571 |
557 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 572 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
558 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 573 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
559 | 574 |
560 last_callback_success_ = true; | 575 last_callback_success_ = true; |
561 { | 576 { |
562 RunLoop run_loop; | 577 RunLoop run_loop; |
563 MemoryDumpCallback callback = | 578 MemoryDumpCallback callback = |
564 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 579 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
565 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 580 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
566 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 581 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
567 MemoryDumpLevelOfDetail::DETAILED, callback); | 582 MemoryDumpLevelOfDetail::DETAILED, callback); |
568 run_loop.Run(); | 583 run_loop.Run(); |
569 } | 584 } |
570 EXPECT_FALSE(last_callback_success_); | 585 EXPECT_FALSE(last_callback_success_); |
571 } | 586 } |
572 | 587 |
573 // Checks that is the MemoryDumpManager is initialized after tracing already | 588 // Checks that is the MemoryDumpManager is initialized after tracing already |
574 // began, it will still late-join the party (real use case: startup tracing). | 589 // began, it will still late-join the party (real use case: startup tracing). |
575 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { | 590 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { |
576 MockMemoryDumpProvider mdp; | 591 MockMemoryDumpProvider mdp; |
577 mdm_->RegisterDumpProvider(&mdp); | 592 RegisterDumpProvider(&mdp); |
578 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 593 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
579 | 594 |
580 // First check that a RequestGlobalDump() issued before the MemoryDumpManager | 595 // First check that a RequestGlobalDump() issued before the MemoryDumpManager |
581 // initialization gets NACK-ed cleanly. | 596 // initialization gets NACK-ed cleanly. |
582 { | 597 { |
583 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 598 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
584 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); | 599 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); |
585 RunLoop run_loop; | 600 RunLoop run_loop; |
586 MemoryDumpCallback callback = | 601 MemoryDumpCallback callback = |
587 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 602 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 | 712 |
698 EnableTracingWithTraceConfig( | 713 EnableTracingWithTraceConfig( |
699 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( | 714 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( |
700 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); | 715 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); |
701 run_loop.Run(); | 716 run_loop.Run(); |
702 DisableTracing(); | 717 DisableTracing(); |
703 } | 718 } |
704 | 719 |
705 } // namespace trace_event | 720 } // namespace trace_event |
706 } // namespace base | 721 } // namespace base |
OLD | NEW |