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" |
11 #include "base/test/test_io_thread.h" | 11 #include "base/test/test_io_thread.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/trace_event/memory_dump_provider.h" | 14 #include "base/trace_event/memory_dump_provider.h" |
15 #include "base/trace_event/process_memory_dump.h" | 15 #include "base/trace_event/process_memory_dump.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 using testing::_; | 19 using testing::_; |
20 using testing::AtMost; | 20 using testing::AtMost; |
21 using testing::Between; | 21 using testing::Between; |
22 using testing::Invoke; | 22 using testing::Invoke; |
23 using testing::Return; | 23 using testing::Return; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 namespace trace_event { | 26 namespace trace_event { |
27 namespace { | 27 namespace { |
28 MemoryDumpArgs high_detail_args = {MemoryDumpArgs::LevelOfDetail::HIGH}; | 28 MemoryDumpArgs g_high_detail_args = {MemoryDumpArgs::LevelOfDetail::HIGH}; |
29 MemoryDumpArgs low_detail_args = {MemoryDumpArgs::LevelOfDetail::LOW}; | 29 MemoryDumpArgs g_low_detail_args = {MemoryDumpArgs::LevelOfDetail::LOW}; |
30 } | 30 |
31 const char kMemoryDumpTraceConfigString[] = | |
32 "{" | |
33 "\"included_categories\":[" | |
34 "\"disabled-by-default-memory-infra\"" | |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
I'd probably move this as an inline string in the
ssid
2015/09/03 16:30:18
Done.
| |
35 "]," | |
36 "\"memory_dump_config\":{" | |
37 "\"triggers\":[" | |
38 "{" | |
39 "\"mode\":\"light\"," | |
40 "\"periodic_interval_ms\":1" | |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
Hmm I'm scared that this is too fast. There is the
ssid
2015/09/03 16:30:18
I asked sami about this and he suggested this is t
Sami
2015/09/03 16:41:52
Right, the idea was that we should try to keep uni
| |
41 "}," | |
42 "{" | |
43 "\"mode\":\"detailed\"," | |
44 "\"periodic_interval_ms\":3" | |
45 "}" | |
46 "]" | |
47 "}" | |
48 "}"; | |
49 | |
50 } // namespace | |
31 | 51 |
32 // Testing MemoryDumpManagerDelegate which short-circuits dump requests locally | 52 // Testing MemoryDumpManagerDelegate which short-circuits dump requests locally |
33 // instead of performing IPC dances. | 53 // instead of performing IPC dances. |
34 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { | 54 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { |
35 public: | 55 public: |
56 static bool is_coordinator_process; | |
36 void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, | 57 void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, |
37 const MemoryDumpCallback& callback) override { | 58 const MemoryDumpCallback& callback) override { |
38 CreateProcessDump(args, callback); | 59 CreateProcessDump(args, callback); |
39 } | 60 } |
40 | 61 |
41 bool IsCoordinatorProcess() const override { return false; } | 62 bool IsCoordinatorProcess() const override { return is_coordinator_process; } |
42 uint64 GetTracingProcessId() const override { | 63 uint64 GetTracingProcessId() const override { |
43 return MemoryDumpManager::kInvalidTracingProcessId; | 64 return MemoryDumpManager::kInvalidTracingProcessId; |
44 } | 65 } |
45 }; | 66 }; |
46 | 67 |
68 bool MemoryDumpManagerDelegateForTesting::is_coordinator_process = false; | |
69 | |
47 class MemoryDumpManagerTest : public testing::Test { | 70 class MemoryDumpManagerTest : public testing::Test { |
48 public: | 71 public: |
49 void SetUp() override { | 72 void SetUp() override { |
50 last_callback_success_ = false; | 73 last_callback_success_ = false; |
51 message_loop_.reset(new MessageLoop()); | 74 message_loop_.reset(new MessageLoop()); |
52 mdm_.reset(new MemoryDumpManager()); | 75 mdm_.reset(new MemoryDumpManager()); |
53 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); | 76 MemoryDumpManager::SetInstanceForTesting(mdm_.get()); |
54 ASSERT_EQ(mdm_, MemoryDumpManager::GetInstance()); | 77 ASSERT_EQ(mdm_, MemoryDumpManager::GetInstance()); |
55 MemoryDumpManager::GetInstance()->Initialize(); | 78 MemoryDumpManager::GetInstance()->Initialize(); |
56 MemoryDumpManager::GetInstance()->SetDelegate(&delegate_); | 79 MemoryDumpManager::GetInstance()->SetDelegate(&delegate_); |
57 } | 80 } |
58 | 81 |
59 void TearDown() override { | 82 void TearDown() override { |
60 MemoryDumpManager::SetInstanceForTesting(nullptr); | 83 MemoryDumpManager::SetInstanceForTesting(nullptr); |
61 mdm_.reset(); | 84 mdm_.reset(); |
62 message_loop_.reset(); | 85 message_loop_.reset(); |
63 TraceLog::DeleteForTesting(); | 86 TraceLog::DeleteForTesting(); |
64 } | 87 } |
65 | 88 |
66 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, | 89 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, |
67 Closure closure, | 90 Closure closure, |
68 uint64 dump_guid, | 91 uint64 dump_guid, |
69 bool success) { | 92 bool success) { |
70 last_callback_success_ = success; | 93 last_callback_success_ = success; |
71 task_runner->PostTask(FROM_HERE, closure); | 94 task_runner->PostTask(FROM_HERE, closure); |
72 } | 95 } |
73 | 96 |
74 protected: | 97 protected: |
75 void EnableTracing(const char* category) { | 98 void EnableTracing(const char* category) { |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
Please add a comment here saying that this enalbes
ssid
2015/09/03 16:30:18
Done.
| |
99 delegate_.is_coordinator_process = false; | |
76 TraceLog::GetInstance()->SetEnabled( | 100 TraceLog::GetInstance()->SetEnabled( |
77 TraceConfig(category, ""), TraceLog::RECORDING_MODE); | 101 TraceConfig(category, ""), TraceLog::RECORDING_MODE); |
78 } | 102 } |
79 | 103 |
104 void EnableTracingWithTraceConfig() { | |
105 delegate_.is_coordinator_process = true; | |
106 TraceConfig tc(kMemoryDumpTraceConfigString); | |
107 TraceLog::GetInstance()->SetEnabled(tc, TraceLog::RECORDING_MODE); | |
108 } | |
109 | |
80 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } | 110 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } |
81 | 111 |
82 scoped_ptr<MemoryDumpManager> mdm_; | 112 scoped_ptr<MemoryDumpManager> mdm_; |
83 bool last_callback_success_; | 113 bool last_callback_success_; |
84 | 114 |
85 private: | 115 private: |
86 scoped_ptr<MessageLoop> message_loop_; | 116 scoped_ptr<MessageLoop> message_loop_; |
87 MemoryDumpManagerDelegateForTesting delegate_; | 117 MemoryDumpManagerDelegateForTesting delegate_; |
88 | 118 |
89 // We want our singleton torn down after each test. | 119 // We want our singleton torn down after each test. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 | 185 |
156 // Used by OnMemoryDump_(Un)RegisterExtraDumpProvider. | 186 // Used by OnMemoryDump_(Un)RegisterExtraDumpProvider. |
157 MemoryDumpProvider* dump_provider_to_register_or_unregister; | 187 MemoryDumpProvider* dump_provider_to_register_or_unregister; |
158 | 188 |
159 private: | 189 private: |
160 MemoryDumpSessionState* last_session_state_; | 190 MemoryDumpSessionState* last_session_state_; |
161 scoped_refptr<SingleThreadTaskRunner> task_runner_; | 191 scoped_refptr<SingleThreadTaskRunner> task_runner_; |
162 const MemoryDumpArgs::LevelOfDetail level_of_detail_; | 192 const MemoryDumpArgs::LevelOfDetail level_of_detail_; |
163 }; | 193 }; |
164 | 194 |
195 // Provider used by SchedulePeriodicDumpsFromTraceConfig. | |
196 class MockDumpProviderForPeriodicDump : public MockDumpProvider { | |
197 public: | |
198 MockDumpProviderForPeriodicDump(int dump_calls_to_quit, | |
199 base::Closure quit_closure) | |
200 : dump_call_count_(0), | |
201 dump_calls_to_quit_(dump_calls_to_quit), | |
202 quit_closure_(quit_closure) {} | |
203 ~MockDumpProviderForPeriodicDump() override {} | |
204 | |
205 // OnMemoryDump() override for the SchedulePeriodicDumpsFromTraceConfig test. | |
206 // Quits the loop after specified OnMemoryDump calls. | |
207 bool OnMemoryDump_SchedulePeriodicDumpsFromTraceConfig( | |
208 const MemoryDumpArgs& args, | |
209 ProcessMemoryDump* pmd) { | |
210 if (++dump_call_count_ == dump_calls_to_quit_) { | |
211 TraceLog::GetInstance()->SetDisabled(); | |
212 MemoryDumpManager::GetInstance()->UnregisterDumpProvider(this); | |
213 MessageLoop::current()->task_runner()->PostTask(FROM_HERE, quit_closure_); | |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
s/MessageLoop::current()->task_runner()/TaskRunner
ssid
2015/09/03 16:30:18
Done.
| |
214 } | |
215 return true; | |
216 } | |
217 | |
218 private: | |
219 int dump_call_count_; | |
220 int dump_calls_to_quit_; | |
221 base::Closure quit_closure_; | |
222 }; | |
223 | |
165 TEST_F(MemoryDumpManagerTest, SingleDumper) { | 224 TEST_F(MemoryDumpManagerTest, SingleDumper) { |
166 MockDumpProvider mdp; | 225 MockDumpProvider mdp; |
167 mdm_->RegisterDumpProvider(&mdp); | 226 mdm_->RegisterDumpProvider(&mdp); |
168 | 227 |
169 // Check that the dumper is not called if the memory category is not enabled. | 228 // Check that the dumper is not called if the memory category is not enabled. |
170 EnableTracing("foo-and-bar-but-not-memory"); | 229 EnableTracing("foo-and-bar-but-not-memory"); |
171 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 230 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
172 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 231 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
173 high_detail_args); | 232 g_high_detail_args); |
174 DisableTracing(); | 233 DisableTracing(); |
175 | 234 |
176 // Now repeat enabling the memory category and check that the dumper is | 235 // Now repeat enabling the memory category and check that the dumper is |
177 // invoked this time. | 236 // invoked this time. |
178 EnableTracing(MemoryDumpManager::kTraceCategory); | 237 EnableTracing(MemoryDumpManager::kTraceCategory); |
179 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); | 238 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); |
180 for (int i = 0; i < 3; ++i) | 239 for (int i = 0; i < 3; ++i) |
181 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 240 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
182 high_detail_args); | 241 g_high_detail_args); |
183 DisableTracing(); | 242 DisableTracing(); |
184 | 243 |
185 mdm_->UnregisterDumpProvider(&mdp); | 244 mdm_->UnregisterDumpProvider(&mdp); |
186 | 245 |
187 // Finally check the unregister logic (no calls to the mdp after unregister). | 246 // Finally check the unregister logic (no calls to the mdp after unregister). |
188 EnableTracing(MemoryDumpManager::kTraceCategory); | 247 EnableTracing(MemoryDumpManager::kTraceCategory); |
189 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 248 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
190 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 249 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
191 high_detail_args); | 250 g_high_detail_args); |
192 TraceLog::GetInstance()->SetDisabled(); | 251 TraceLog::GetInstance()->SetDisabled(); |
193 } | 252 } |
194 | 253 |
195 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { | 254 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { |
196 // Check that requesting dumps with high level of detail actually propagates | 255 // Check that requesting dumps with high level of detail actually propagates |
197 // to OnMemoryDump() call on dump providers. | 256 // to OnMemoryDump() call on dump providers. |
198 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH); | 257 MockDumpProvider mdp_high_detail(MemoryDumpArgs::LevelOfDetail::HIGH); |
199 mdm_->RegisterDumpProvider(&mdp_high_detail); | 258 mdm_->RegisterDumpProvider(&mdp_high_detail); |
200 | 259 |
201 EnableTracing(MemoryDumpManager::kTraceCategory); | 260 EnableTracing(MemoryDumpManager::kTraceCategory); |
202 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _)) | 261 EXPECT_CALL(mdp_high_detail, OnMemoryDump(_, _)) |
203 .Times(1) | 262 .Times(1) |
204 .WillRepeatedly( | 263 .WillRepeatedly( |
205 Invoke(&mdp_high_detail, | 264 Invoke(&mdp_high_detail, |
206 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); | 265 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); |
207 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 266 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
208 high_detail_args); | 267 g_high_detail_args); |
209 DisableTracing(); | 268 DisableTracing(); |
210 mdm_->UnregisterDumpProvider(&mdp_high_detail); | 269 mdm_->UnregisterDumpProvider(&mdp_high_detail); |
211 | 270 |
212 // Check that requesting dumps with low level of detail actually propagates to | 271 // Check that requesting dumps with low level of detail actually propagates to |
213 // OnMemoryDump() call on dump providers. | 272 // OnMemoryDump() call on dump providers. |
214 MockDumpProvider mdp_low_detail(MemoryDumpArgs::LevelOfDetail::LOW); | 273 MockDumpProvider mdp_low_detail(MemoryDumpArgs::LevelOfDetail::LOW); |
215 mdm_->RegisterDumpProvider(&mdp_low_detail); | 274 mdm_->RegisterDumpProvider(&mdp_low_detail); |
216 | 275 |
217 EnableTracing(MemoryDumpManager::kTraceCategory); | 276 EnableTracing(MemoryDumpManager::kTraceCategory); |
218 EXPECT_CALL(mdp_low_detail, OnMemoryDump(_, _)) | 277 EXPECT_CALL(mdp_low_detail, OnMemoryDump(_, _)) |
219 .Times(1) | 278 .Times(1) |
220 .WillRepeatedly( | 279 .WillRepeatedly( |
221 Invoke(&mdp_low_detail, | 280 Invoke(&mdp_low_detail, |
222 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); | 281 &MockDumpProvider::OnMemoryDump_CheckMemoryDumpArgs)); |
223 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 282 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
224 low_detail_args); | 283 g_low_detail_args); |
225 DisableTracing(); | 284 DisableTracing(); |
226 mdm_->UnregisterDumpProvider(&mdp_low_detail); | 285 mdm_->UnregisterDumpProvider(&mdp_low_detail); |
227 } | 286 } |
228 | 287 |
229 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 288 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
230 MockDumpProvider mdp1; | 289 MockDumpProvider mdp1; |
231 MockDumpProvider mdp2; | 290 MockDumpProvider mdp2; |
232 mdm_->RegisterDumpProvider(&mdp1); | 291 mdm_->RegisterDumpProvider(&mdp1); |
233 mdm_->RegisterDumpProvider(&mdp2); | 292 mdm_->RegisterDumpProvider(&mdp2); |
234 | 293 |
235 EnableTracing(MemoryDumpManager::kTraceCategory); | 294 EnableTracing(MemoryDumpManager::kTraceCategory); |
236 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 295 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
237 .Times(2) | 296 .Times(2) |
238 .WillRepeatedly( | 297 .WillRepeatedly( |
239 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState)); | 298 Invoke(&mdp1, &MockDumpProvider::OnMemoryDump_CheckSessionState)); |
240 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 299 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
241 .Times(2) | 300 .Times(2) |
242 .WillRepeatedly( | 301 .WillRepeatedly( |
243 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState)); | 302 Invoke(&mdp2, &MockDumpProvider::OnMemoryDump_CheckSessionState)); |
244 | 303 |
245 for (int i = 0; i < 2; ++i) | 304 for (int i = 0; i < 2; ++i) |
246 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 305 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
247 high_detail_args); | 306 g_high_detail_args); |
248 | 307 |
249 DisableTracing(); | 308 DisableTracing(); |
250 } | 309 } |
251 | 310 |
252 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { | 311 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { |
253 MockDumpProvider mdp1; | 312 MockDumpProvider mdp1; |
254 MockDumpProvider mdp2; | 313 MockDumpProvider mdp2; |
255 | 314 |
256 // Enable only mdp1. | 315 // Enable only mdp1. |
257 mdm_->RegisterDumpProvider(&mdp1); | 316 mdm_->RegisterDumpProvider(&mdp1); |
258 EnableTracing(MemoryDumpManager::kTraceCategory); | 317 EnableTracing(MemoryDumpManager::kTraceCategory); |
259 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 318 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
260 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); | 319 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); |
261 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 320 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
262 high_detail_args); | 321 g_high_detail_args); |
263 DisableTracing(); | 322 DisableTracing(); |
264 | 323 |
265 // Invert: enable mdp1 and disable mdp2. | 324 // Invert: enable mdp1 and disable mdp2. |
266 mdm_->UnregisterDumpProvider(&mdp1); | 325 mdm_->UnregisterDumpProvider(&mdp1); |
267 mdm_->RegisterDumpProvider(&mdp2); | 326 mdm_->RegisterDumpProvider(&mdp2); |
268 EnableTracing(MemoryDumpManager::kTraceCategory); | 327 EnableTracing(MemoryDumpManager::kTraceCategory); |
269 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 328 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
270 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 329 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
271 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 330 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
272 high_detail_args); | 331 g_high_detail_args); |
273 DisableTracing(); | 332 DisableTracing(); |
274 | 333 |
275 // Enable both mdp1 and mdp2. | 334 // Enable both mdp1 and mdp2. |
276 mdm_->RegisterDumpProvider(&mdp1); | 335 mdm_->RegisterDumpProvider(&mdp1); |
277 EnableTracing(MemoryDumpManager::kTraceCategory); | 336 EnableTracing(MemoryDumpManager::kTraceCategory); |
278 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 337 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
279 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); | 338 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(1).WillRepeatedly(Return(true)); |
280 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 339 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
281 high_detail_args); | 340 g_high_detail_args); |
282 DisableTracing(); | 341 DisableTracing(); |
283 } | 342 } |
284 | 343 |
285 // Verify that whether OnMemoryDump is called depends only on the current | 344 // Verify that whether OnMemoryDump is called depends only on the current |
286 // registration state and not on previous registrations and dumps. | 345 // registration state and not on previous registrations and dumps. |
287 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { | 346 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { |
288 MockDumpProvider mdp; | 347 MockDumpProvider mdp; |
289 | 348 |
290 mdm_->RegisterDumpProvider(&mdp); | 349 mdm_->RegisterDumpProvider(&mdp); |
291 | 350 |
292 { | 351 { |
293 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); | 352 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); |
294 EnableTracing(MemoryDumpManager::kTraceCategory); | 353 EnableTracing(MemoryDumpManager::kTraceCategory); |
295 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 354 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
296 high_detail_args); | 355 g_high_detail_args); |
297 DisableTracing(); | 356 DisableTracing(); |
298 } | 357 } |
299 | 358 |
300 mdm_->UnregisterDumpProvider(&mdp); | 359 mdm_->UnregisterDumpProvider(&mdp); |
301 | 360 |
302 { | 361 { |
303 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 362 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
304 EnableTracing(MemoryDumpManager::kTraceCategory); | 363 EnableTracing(MemoryDumpManager::kTraceCategory); |
305 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 364 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
306 high_detail_args); | 365 g_high_detail_args); |
307 DisableTracing(); | 366 DisableTracing(); |
308 } | 367 } |
309 | 368 |
310 mdm_->RegisterDumpProvider(&mdp); | 369 mdm_->RegisterDumpProvider(&mdp); |
311 mdm_->UnregisterDumpProvider(&mdp); | 370 mdm_->UnregisterDumpProvider(&mdp); |
312 | 371 |
313 { | 372 { |
314 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); | 373 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); |
315 EnableTracing(MemoryDumpManager::kTraceCategory); | 374 EnableTracing(MemoryDumpManager::kTraceCategory); |
316 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 375 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
317 high_detail_args); | 376 g_high_detail_args); |
318 DisableTracing(); | 377 DisableTracing(); |
319 } | 378 } |
320 | 379 |
321 mdm_->RegisterDumpProvider(&mdp); | 380 mdm_->RegisterDumpProvider(&mdp); |
322 mdm_->UnregisterDumpProvider(&mdp); | 381 mdm_->UnregisterDumpProvider(&mdp); |
323 mdm_->RegisterDumpProvider(&mdp); | 382 mdm_->RegisterDumpProvider(&mdp); |
324 | 383 |
325 { | 384 { |
326 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); | 385 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); |
327 EnableTracing(MemoryDumpManager::kTraceCategory); | 386 EnableTracing(MemoryDumpManager::kTraceCategory); |
328 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 387 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
329 high_detail_args); | 388 g_high_detail_args); |
330 DisableTracing(); | 389 DisableTracing(); |
331 } | 390 } |
332 } | 391 } |
333 | 392 |
334 // Checks that the MemoryDumpManager respects the thread affinity when a | 393 // Checks that the MemoryDumpManager respects the thread affinity when a |
335 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 | 394 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 |
336 // threads and registering a MemoryDumpProvider on each of them. At each | 395 // threads and registering a MemoryDumpProvider on each of them. At each |
337 // iteration, one thread is removed, to check the live unregistration logic. | 396 // iteration, one thread is removed, to check the live unregistration logic. |
338 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { | 397 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { |
339 const uint32 kNumInitialThreads = 8; | 398 const uint32 kNumInitialThreads = 8; |
(...skipping 19 matching lines...) Expand all Loading... | |
359 EnableTracing(MemoryDumpManager::kTraceCategory); | 418 EnableTracing(MemoryDumpManager::kTraceCategory); |
360 | 419 |
361 while (!threads.empty()) { | 420 while (!threads.empty()) { |
362 last_callback_success_ = false; | 421 last_callback_success_ = false; |
363 { | 422 { |
364 RunLoop run_loop; | 423 RunLoop run_loop; |
365 MemoryDumpCallback callback = | 424 MemoryDumpCallback callback = |
366 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 425 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
367 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 426 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
368 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 427 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
369 high_detail_args, callback); | 428 g_high_detail_args, callback); |
370 // This nested message loop (|run_loop|) will be quit if and only if | 429 // This nested message loop (|run_loop|) will be quit if and only if |
371 // the RequestGlobalDump callback is invoked. | 430 // the RequestGlobalDump callback is invoked. |
372 run_loop.Run(); | 431 run_loop.Run(); |
373 } | 432 } |
374 EXPECT_TRUE(last_callback_success_); | 433 EXPECT_TRUE(last_callback_success_); |
375 | 434 |
376 // Unregister a MDP and destroy one thread at each iteration to check the | 435 // Unregister a MDP and destroy one thread at each iteration to check the |
377 // live unregistration logic. The unregistration needs to happen on the same | 436 // live unregistration logic. The unregistration needs to happen on the same |
378 // thread the MDP belongs to. | 437 // thread the MDP belongs to. |
379 { | 438 { |
(...skipping 27 matching lines...) Expand all Loading... | |
407 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) | 466 .Times(MemoryDumpManager::kMaxConsecutiveFailuresCount) |
408 .WillRepeatedly(Return(false)); | 467 .WillRepeatedly(Return(false)); |
409 | 468 |
410 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 469 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
411 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) | 470 .Times(1 + MemoryDumpManager::kMaxConsecutiveFailuresCount) |
412 .WillOnce(Return(false)) | 471 .WillOnce(Return(false)) |
413 .WillRepeatedly(Return(true)); | 472 .WillRepeatedly(Return(true)); |
414 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount; | 473 for (int i = 0; i < 1 + MemoryDumpManager::kMaxConsecutiveFailuresCount; |
415 i++) { | 474 i++) { |
416 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 475 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
417 high_detail_args); | 476 g_high_detail_args); |
418 } | 477 } |
419 | 478 |
420 DisableTracing(); | 479 DisableTracing(); |
421 } | 480 } |
422 | 481 |
423 // Sneakily register an extra memory dump provider while an existing one is | 482 // Sneakily register an extra memory dump provider while an existing one is |
424 // dumping and expect it to take part in the already active tracing session. | 483 // dumping and expect it to take part in the already active tracing session. |
425 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { | 484 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { |
426 MockDumpProvider mdp1; | 485 MockDumpProvider mdp1; |
427 MockDumpProvider mdp2; | 486 MockDumpProvider mdp2; |
(...skipping 10 matching lines...) Expand all Loading... | |
438 .WillRepeatedly(Return(true)); | 497 .WillRepeatedly(Return(true)); |
439 | 498 |
440 // Depending on the insertion order (before or after mdp1), mdp2 might be | 499 // Depending on the insertion order (before or after mdp1), mdp2 might be |
441 // called also immediately after it gets registered. | 500 // called also immediately after it gets registered. |
442 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 501 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
443 .Times(Between(2, 3)) | 502 .Times(Between(2, 3)) |
444 .WillRepeatedly(Return(true)); | 503 .WillRepeatedly(Return(true)); |
445 | 504 |
446 for (int i = 0; i < 4; i++) { | 505 for (int i = 0; i < 4; i++) { |
447 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 506 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
448 high_detail_args); | 507 g_high_detail_args); |
449 } | 508 } |
450 | 509 |
451 DisableTracing(); | 510 DisableTracing(); |
452 } | 511 } |
453 | 512 |
454 // Like the above, but suddenly unregister the dump provider. | 513 // Like the above, but suddenly unregister the dump provider. |
455 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { | 514 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { |
456 MockDumpProvider mdp1; | 515 MockDumpProvider mdp1; |
457 MockDumpProvider mdp2; | 516 MockDumpProvider mdp2; |
458 | 517 |
(...skipping 10 matching lines...) Expand all Loading... | |
469 .WillRepeatedly(Return(true)); | 528 .WillRepeatedly(Return(true)); |
470 | 529 |
471 // Depending on the insertion order (before or after mdp1), mdp2 might have | 530 // Depending on the insertion order (before or after mdp1), mdp2 might have |
472 // been already called when OnMemoryDump_UnregisterDumpProvider happens. | 531 // been already called when OnMemoryDump_UnregisterDumpProvider happens. |
473 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 532 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
474 .Times(Between(1, 2)) | 533 .Times(Between(1, 2)) |
475 .WillRepeatedly(Return(true)); | 534 .WillRepeatedly(Return(true)); |
476 | 535 |
477 for (int i = 0; i < 4; i++) { | 536 for (int i = 0; i < 4; i++) { |
478 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 537 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
479 high_detail_args); | 538 g_high_detail_args); |
480 } | 539 } |
481 | 540 |
482 DisableTracing(); | 541 DisableTracing(); |
483 } | 542 } |
484 | 543 |
485 // Verify that the dump does not abort when unregistering a provider while | 544 // Verify that the dump does not abort when unregistering a provider while |
486 // dumping from a different thread than the dumping thread. | 545 // dumping from a different thread than the dumping thread. |
487 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { | 546 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { |
488 ScopedVector<TestIOThread> threads; | 547 ScopedVector<TestIOThread> threads; |
489 ScopedVector<MockDumpProvider> mdps; | 548 ScopedVector<MockDumpProvider> mdps; |
(...skipping 29 matching lines...) Expand all Loading... | |
519 .WillOnce(Invoke(on_dump)); | 578 .WillOnce(Invoke(on_dump)); |
520 } | 579 } |
521 | 580 |
522 last_callback_success_ = false; | 581 last_callback_success_ = false; |
523 MemoryDumpCallback callback = | 582 MemoryDumpCallback callback = |
524 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 583 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
525 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 584 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
526 | 585 |
527 EnableTracing(MemoryDumpManager::kTraceCategory); | 586 EnableTracing(MemoryDumpManager::kTraceCategory); |
528 MemoryDumpRequestArgs request_args = {0, MemoryDumpType::EXPLICITLY_TRIGGERED, | 587 MemoryDumpRequestArgs request_args = {0, MemoryDumpType::EXPLICITLY_TRIGGERED, |
529 high_detail_args}; | 588 g_high_detail_args}; |
530 mdm_->CreateProcessDump(request_args, callback); | 589 mdm_->CreateProcessDump(request_args, callback); |
531 | 590 |
532 run_loop.Run(); | 591 run_loop.Run(); |
533 | 592 |
534 ASSERT_EQ(1, on_memory_dump_call_count); | 593 ASSERT_EQ(1, on_memory_dump_call_count); |
535 ASSERT_EQ(true, last_callback_success_); | 594 ASSERT_EQ(true, last_callback_success_); |
536 | 595 |
537 DisableTracing(); | 596 DisableTracing(); |
538 } | 597 } |
539 | 598 |
540 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when | 599 // Ensures that a NACK callback is invoked if RequestGlobalDump is called when |
541 // tracing is not enabled. | 600 // tracing is not enabled. |
542 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { | 601 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { |
543 MockDumpProvider mdp1; | 602 MockDumpProvider mdp1; |
544 | 603 |
545 mdm_->RegisterDumpProvider(&mdp1); | 604 mdm_->RegisterDumpProvider(&mdp1); |
546 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); | 605 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); |
547 | 606 |
548 last_callback_success_ = true; | 607 last_callback_success_ = true; |
549 { | 608 { |
550 RunLoop run_loop; | 609 RunLoop run_loop; |
551 MemoryDumpCallback callback = | 610 MemoryDumpCallback callback = |
552 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), | 611 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), |
553 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); | 612 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); |
554 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, | 613 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, |
555 high_detail_args, callback); | 614 g_high_detail_args, callback); |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
Thanks for fixing these :)
| |
556 run_loop.Run(); | 615 run_loop.Run(); |
557 } | 616 } |
558 EXPECT_FALSE(last_callback_success_); | 617 EXPECT_FALSE(last_callback_success_); |
559 } | 618 } |
560 | 619 |
620 TEST_F(MemoryDumpManagerTest, SchedulePeriodicDumpsFromTraceConfig) { | |
621 RunLoop run_loop; | |
622 MockDumpProviderForPeriodicDump mdp(10, run_loop.QuitClosure()); | |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
either make this 10 a constant (i.e. const int kDu
ssid
2015/09/03 16:30:18
Done.
| |
623 mdm_->RegisterDumpProvider(&mdp); | |
624 EnableTracingWithTraceConfig(); | |
625 | |
626 DCHECK(g_high_detail_args == g_high_detail_args); | |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
uh?
ssid
2015/09/03 16:30:18
sorry, removed!
| |
627 EXPECT_CALL(mdp, OnMemoryDump(g_high_detail_args, _)) | |
628 .Times(4) | |
Primiano Tucci (use gerrit)
2015/09/03 08:39:51
just make these 2+3 = 5 (instead of 6+4 = 10) so t
ssid
2015/09/03 16:30:18
Done.
| |
629 .WillRepeatedly( | |
630 Invoke(&mdp, &MockDumpProviderForPeriodicDump:: | |
631 OnMemoryDump_SchedulePeriodicDumpsFromTraceConfig)); | |
632 | |
633 EXPECT_CALL(mdp, OnMemoryDump(g_low_detail_args, _)) | |
634 .Times(6) | |
635 .WillRepeatedly( | |
636 Invoke(&mdp, &MockDumpProviderForPeriodicDump:: | |
637 OnMemoryDump_SchedulePeriodicDumpsFromTraceConfig)); | |
638 | |
639 run_loop.Run(); | |
640 } | |
641 | |
561 } // namespace trace_event | 642 } // namespace trace_event |
562 } // namespace base | 643 } // namespace base |
OLD | NEW |