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

Side by Side Diff: base/trace_event/memory_dump_manager_unittest.cc

Issue 1337943003: [tracing] Non-functional refactor of memory dump arg names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows test Created 5 years, 3 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/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider.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 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/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/test/test_io_thread.h" 12 #include "base/test/test_io_thread.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "base/trace_event/memory_dump_provider.h" 15 #include "base/trace_event/memory_dump_provider.h"
16 #include "base/trace_event/process_memory_dump.h" 16 #include "base/trace_event/process_memory_dump.h"
17 #include "base/trace_event/trace_config_memory_test_util.h" 17 #include "base/trace_event/trace_config_memory_test_util.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using testing::_; 21 using testing::_;
22 using testing::AnyNumber; 22 using testing::AnyNumber;
23 using testing::AtMost; 23 using testing::AtMost;
24 using testing::Between; 24 using testing::Between;
25 using testing::Invoke; 25 using testing::Invoke;
26 using testing::Return; 26 using testing::Return;
27 27
28 namespace base { 28 namespace base {
29 namespace trace_event { 29 namespace trace_event {
30 namespace {
31 MemoryDumpArgs g_high_detail_args = {MemoryDumpArgs::LevelOfDetail::HIGH};
32 MemoryDumpArgs g_low_detail_args = {MemoryDumpArgs::LevelOfDetail::LOW};
33 } // namespace
34 30
35 // GTest matchers for MemoryDumpRequestArgs arguments. 31 // GTest matchers for MemoryDumpRequestArgs arguments.
36 MATCHER(IsHighDetail, "") { 32 MATCHER(IsDetailedDump, "") {
37 return arg.level_of_detail == MemoryDumpArgs::LevelOfDetail::HIGH; 33 return arg.level_of_detail == MemoryDumpLevelOfDetail::DETAILED;
38 } 34 }
39 35
40 MATCHER(IsLowDetail, "") { 36 MATCHER(IsLightDump, "") {
41 return arg.level_of_detail == MemoryDumpArgs::LevelOfDetail::LOW; 37 return arg.level_of_detail == MemoryDumpLevelOfDetail::LIGHT;
42 }
43
44 // GTest matchers for MemoryDumpArgs arguments.
45 MATCHER(IsHighDetailArgs, "") {
46 return arg.dump_args.level_of_detail == MemoryDumpArgs::LevelOfDetail::HIGH;
47 }
48
49 MATCHER(IsLowDetailArgs, "") {
50 return arg.dump_args.level_of_detail == MemoryDumpArgs::LevelOfDetail::LOW;
51 } 38 }
52 39
53 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump 40 // Testing MemoryDumpManagerDelegate which, by default, short-circuits dump
54 // requests locally to the MemoryDumpManager instead of performing IPC dances. 41 // requests locally to the MemoryDumpManager instead of performing IPC dances.
55 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate { 42 class MemoryDumpManagerDelegateForTesting : public MemoryDumpManagerDelegate {
56 public: 43 public:
57 MemoryDumpManagerDelegateForTesting() { 44 MemoryDumpManagerDelegateForTesting() {
58 ON_CALL(*this, RequestGlobalMemoryDump(_, _)) 45 ON_CALL(*this, RequestGlobalMemoryDump(_, _))
59 .WillByDefault(Invoke( 46 .WillByDefault(Invoke(
60 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump)); 47 this, &MemoryDumpManagerDelegateForTesting::CreateProcessDump));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 TEST_F(MemoryDumpManagerTest, SingleDumper) { 131 TEST_F(MemoryDumpManagerTest, SingleDumper) {
145 InitializeMemoryDumpManager(false /* is_coordinator */); 132 InitializeMemoryDumpManager(false /* is_coordinator */);
146 MockMemoryDumpProvider mdp; 133 MockMemoryDumpProvider mdp;
147 mdm_->RegisterDumpProvider(&mdp); 134 mdm_->RegisterDumpProvider(&mdp);
148 135
149 // Check that the dumper is not called if the memory category is not enabled. 136 // Check that the dumper is not called if the memory category is not enabled.
150 EnableTracingWithLegacyCategories("foobar-but-not-memory"); 137 EnableTracingWithLegacyCategories("foobar-but-not-memory");
151 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); 138 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
152 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 139 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
153 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 140 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
154 g_high_detail_args); 141 MemoryDumpLevelOfDetail::DETAILED);
155 DisableTracing(); 142 DisableTracing();
156 143
157 // Now repeat enabling the memory category and check that the dumper is 144 // Now repeat enabling the memory category and check that the dumper is
158 // invoked this time. 145 // invoked this time.
159 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 146 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
160 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3); 147 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(3);
161 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true)); 148 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(3).WillRepeatedly(Return(true));
162 for (int i = 0; i < 3; ++i) 149 for (int i = 0; i < 3; ++i)
163 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 150 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
164 g_high_detail_args); 151 MemoryDumpLevelOfDetail::DETAILED);
165 DisableTracing(); 152 DisableTracing();
166 153
167 mdm_->UnregisterDumpProvider(&mdp); 154 mdm_->UnregisterDumpProvider(&mdp);
168 155
169 // Finally check the unregister logic: the delegate will be invoked but not 156 // Finally check the unregister logic: the delegate will be invoked but not
170 // the dump provider, as it has been unregistered. 157 // the dump provider, as it has been unregistered.
171 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 158 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
172 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 159 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
173 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 160 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
174 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 161 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
175 g_high_detail_args); 162 MemoryDumpLevelOfDetail::DETAILED);
176 TraceLog::GetInstance()->SetDisabled(); 163 TraceLog::GetInstance()->SetDisabled();
177 } 164 }
178 165
179 // Checks that requesting dumps with high level of detail actually propagates 166 // Checks that requesting dumps with high level of detail actually propagates
180 // the level of the detail properly to OnMemoryDump() call on dump providers. 167 // the level of the detail properly to OnMemoryDump() call on dump providers.
181 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) { 168 TEST_F(MemoryDumpManagerTest, CheckMemoryDumpArgs) {
182 InitializeMemoryDumpManager(false /* is_coordinator */); 169 InitializeMemoryDumpManager(false /* is_coordinator */);
183 MockMemoryDumpProvider mdp; 170 MockMemoryDumpProvider mdp;
184 171
185 mdm_->RegisterDumpProvider(&mdp); 172 mdm_->RegisterDumpProvider(&mdp);
186 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 173 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
187 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 174 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
188 EXPECT_CALL(mdp, OnMemoryDump(IsHighDetail(), _)).WillOnce(Return(true)); 175 EXPECT_CALL(mdp, OnMemoryDump(IsDetailedDump(), _)).WillOnce(Return(true));
189 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 176 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
190 g_high_detail_args); 177 MemoryDumpLevelOfDetail::DETAILED);
191 DisableTracing(); 178 DisableTracing();
192 mdm_->UnregisterDumpProvider(&mdp); 179 mdm_->UnregisterDumpProvider(&mdp);
193 180
194 // Check that requesting dumps with low level of detail actually propagates to 181 // Check that requesting dumps with low level of detail actually propagates to
195 // OnMemoryDump() call on dump providers. 182 // OnMemoryDump() call on dump providers.
196 mdm_->RegisterDumpProvider(&mdp); 183 mdm_->RegisterDumpProvider(&mdp);
197 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 184 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
198 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 185 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
199 EXPECT_CALL(mdp, OnMemoryDump(IsLowDetail(), _)).WillOnce(Return(true)); 186 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true));
200 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 187 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
201 g_low_detail_args); 188 MemoryDumpLevelOfDetail::LIGHT);
202 DisableTracing(); 189 DisableTracing();
203 mdm_->UnregisterDumpProvider(&mdp); 190 mdm_->UnregisterDumpProvider(&mdp);
204 } 191 }
205 192
206 // Checks that the SharedSessionState object is acqually shared over time. 193 // Checks that the SharedSessionState object is acqually shared over time.
207 TEST_F(MemoryDumpManagerTest, SharedSessionState) { 194 TEST_F(MemoryDumpManagerTest, SharedSessionState) {
208 InitializeMemoryDumpManager(false /* is_coordinator */); 195 InitializeMemoryDumpManager(false /* is_coordinator */);
209 MockMemoryDumpProvider mdp1; 196 MockMemoryDumpProvider mdp1;
210 MockMemoryDumpProvider mdp2; 197 MockMemoryDumpProvider mdp2;
211 mdm_->RegisterDumpProvider(&mdp1); 198 mdm_->RegisterDumpProvider(&mdp1);
(...skipping 12 matching lines...) Expand all
224 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 211 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
225 .Times(2) 212 .Times(2)
226 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, 213 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&,
227 ProcessMemoryDump* pmd) -> bool { 214 ProcessMemoryDump* pmd) -> bool {
228 EXPECT_EQ(session_state, pmd->session_state().get()); 215 EXPECT_EQ(session_state, pmd->session_state().get());
229 return true; 216 return true;
230 })); 217 }));
231 218
232 for (int i = 0; i < 2; ++i) 219 for (int i = 0; i < 2; ++i)
233 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 220 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
234 g_high_detail_args); 221 MemoryDumpLevelOfDetail::DETAILED);
235 222
236 DisableTracing(); 223 DisableTracing();
237 } 224 }
238 225
239 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. 226 // Checks that the (Un)RegisterDumpProvider logic behaves sanely.
240 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { 227 TEST_F(MemoryDumpManagerTest, MultipleDumpers) {
241 InitializeMemoryDumpManager(false /* is_coordinator */); 228 InitializeMemoryDumpManager(false /* is_coordinator */);
242 MockMemoryDumpProvider mdp1; 229 MockMemoryDumpProvider mdp1;
243 MockMemoryDumpProvider mdp2; 230 MockMemoryDumpProvider mdp2;
244 231
245 // Enable only mdp1. 232 // Enable only mdp1.
246 mdm_->RegisterDumpProvider(&mdp1); 233 mdm_->RegisterDumpProvider(&mdp1);
247 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 234 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
248 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 235 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
249 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); 236 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true));
250 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0); 237 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).Times(0);
251 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 238 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
252 g_high_detail_args); 239 MemoryDumpLevelOfDetail::DETAILED);
253 DisableTracing(); 240 DisableTracing();
254 241
255 // Invert: enable mdp1 and disable mdp2. 242 // Invert: enable mdp1 and disable mdp2.
256 mdm_->UnregisterDumpProvider(&mdp1); 243 mdm_->UnregisterDumpProvider(&mdp1);
257 mdm_->RegisterDumpProvider(&mdp2); 244 mdm_->RegisterDumpProvider(&mdp2);
258 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 245 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
259 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 246 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
260 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); 247 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
261 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); 248 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true));
262 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 249 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
263 g_high_detail_args); 250 MemoryDumpLevelOfDetail::DETAILED);
264 DisableTracing(); 251 DisableTracing();
265 252
266 // Enable both mdp1 and mdp2. 253 // Enable both mdp1 and mdp2.
267 mdm_->RegisterDumpProvider(&mdp1); 254 mdm_->RegisterDumpProvider(&mdp1);
268 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 255 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
269 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 256 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
270 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true)); 257 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).WillOnce(Return(true));
271 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true)); 258 EXPECT_CALL(mdp2, OnMemoryDump(_, _)).WillOnce(Return(true));
272 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 259 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
273 g_high_detail_args); 260 MemoryDumpLevelOfDetail::DETAILED);
274 DisableTracing(); 261 DisableTracing();
275 } 262 }
276 263
277 // Checks that the dump provider invocations depend only on the current 264 // Checks that the dump provider invocations depend only on the current
278 // registration state and not on previous registrations and dumps. 265 // registration state and not on previous registrations and dumps.
279 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) { 266 TEST_F(MemoryDumpManagerTest, RegistrationConsistency) {
280 InitializeMemoryDumpManager(false /* is_coordinator */); 267 InitializeMemoryDumpManager(false /* is_coordinator */);
281 MockMemoryDumpProvider mdp; 268 MockMemoryDumpProvider mdp;
282 269
283 mdm_->RegisterDumpProvider(&mdp); 270 mdm_->RegisterDumpProvider(&mdp);
284 271
285 { 272 {
286 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 273 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
287 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); 274 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true));
288 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 275 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
289 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 276 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
290 g_high_detail_args); 277 MemoryDumpLevelOfDetail::DETAILED);
291 DisableTracing(); 278 DisableTracing();
292 } 279 }
293 280
294 mdm_->UnregisterDumpProvider(&mdp); 281 mdm_->UnregisterDumpProvider(&mdp);
295 282
296 { 283 {
297 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 284 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
298 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 285 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
299 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 286 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
300 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 287 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
301 g_high_detail_args); 288 MemoryDumpLevelOfDetail::DETAILED);
302 DisableTracing(); 289 DisableTracing();
303 } 290 }
304 291
305 mdm_->RegisterDumpProvider(&mdp); 292 mdm_->RegisterDumpProvider(&mdp);
306 mdm_->UnregisterDumpProvider(&mdp); 293 mdm_->UnregisterDumpProvider(&mdp);
307 294
308 { 295 {
309 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 296 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
310 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 297 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
311 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 298 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
312 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 299 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
313 g_high_detail_args); 300 MemoryDumpLevelOfDetail::DETAILED);
314 DisableTracing(); 301 DisableTracing();
315 } 302 }
316 303
317 mdm_->RegisterDumpProvider(&mdp); 304 mdm_->RegisterDumpProvider(&mdp);
318 mdm_->UnregisterDumpProvider(&mdp); 305 mdm_->UnregisterDumpProvider(&mdp);
319 mdm_->RegisterDumpProvider(&mdp); 306 mdm_->RegisterDumpProvider(&mdp);
320 307
321 { 308 {
322 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 309 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
323 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true)); 310 EXPECT_CALL(mdp, OnMemoryDump(_, _)).WillOnce(Return(true));
324 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 311 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
325 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 312 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
326 g_high_detail_args); 313 MemoryDumpLevelOfDetail::DETAILED);
327 DisableTracing(); 314 DisableTracing();
328 } 315 }
329 } 316 }
330 317
331 // Checks that the MemoryDumpManager respects the thread affinity when a 318 // Checks that the MemoryDumpManager respects the thread affinity when a
332 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8 319 // MemoryDumpProvider specifies a task_runner(). The test starts creating 8
333 // threads and registering a MemoryDumpProvider on each of them. At each 320 // threads and registering a MemoryDumpProvider on each of them. At each
334 // iteration, one thread is removed, to check the live unregistration logic. 321 // iteration, one thread is removed, to check the live unregistration logic.
335 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) { 322 TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) {
336 InitializeMemoryDumpManager(false /* is_coordinator */); 323 InitializeMemoryDumpManager(false /* is_coordinator */);
(...skipping 26 matching lines...) Expand all
363 350
364 while (!threads.empty()) { 351 while (!threads.empty()) {
365 last_callback_success_ = false; 352 last_callback_success_ = false;
366 { 353 {
367 RunLoop run_loop; 354 RunLoop run_loop;
368 MemoryDumpCallback callback = 355 MemoryDumpCallback callback =
369 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 356 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
370 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 357 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
371 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 358 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
372 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 359 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
373 g_high_detail_args, callback); 360 MemoryDumpLevelOfDetail::DETAILED, callback);
374 // This nested message loop (|run_loop|) will quit if and only if the 361 // This nested message loop (|run_loop|) will quit if and only if the
375 // |callback| passed to RequestGlobalDump() is invoked. 362 // |callback| passed to RequestGlobalDump() is invoked.
376 run_loop.Run(); 363 run_loop.Run();
377 } 364 }
378 EXPECT_TRUE(last_callback_success_); 365 EXPECT_TRUE(last_callback_success_);
379 366
380 // Unregister a MDP and destroy one thread at each iteration to check the 367 // Unregister a MDP and destroy one thread at each iteration to check the
381 // live unregistration logic. The unregistration needs to happen on the same 368 // live unregistration logic. The unregistration needs to happen on the same
382 // thread the MDP belongs to. 369 // thread the MDP belongs to.
383 { 370 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 405 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
419 .WillOnce(Return(false)) 406 .WillOnce(Return(false))
420 .WillOnce(Return(true)) 407 .WillOnce(Return(true))
421 .WillOnce(Return(false)) 408 .WillOnce(Return(false))
422 .WillOnce(Return(false)) 409 .WillOnce(Return(false))
423 .WillOnce(Return(true)) 410 .WillOnce(Return(true))
424 .WillOnce(Return(false)); 411 .WillOnce(Return(false));
425 412
426 for (int i = 0; i < kNumDumps; i++) { 413 for (int i = 0; i < kNumDumps; i++) {
427 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 414 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
428 g_high_detail_args); 415 MemoryDumpLevelOfDetail::DETAILED);
429 } 416 }
430 417
431 DisableTracing(); 418 DisableTracing();
432 } 419 }
433 420
434 // Sneakily registers an extra memory dump provider while an existing one is 421 // Sneakily registers an extra memory dump provider while an existing one is
435 // dumping and expect it to take part in the already active tracing session. 422 // dumping and expect it to take part in the already active tracing session.
436 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) { 423 TEST_F(MemoryDumpManagerTest, RegisterDumperWhileDumping) {
437 InitializeMemoryDumpManager(false /* is_coordinator */); 424 InitializeMemoryDumpManager(false /* is_coordinator */);
438 MockMemoryDumpProvider mdp1; 425 MockMemoryDumpProvider mdp1;
(...skipping 15 matching lines...) Expand all
454 .WillRepeatedly(Return(true)); 441 .WillRepeatedly(Return(true));
455 442
456 // Depending on the insertion order (before or after mdp1), mdp2 might be 443 // Depending on the insertion order (before or after mdp1), mdp2 might be
457 // called also immediately after it gets registered. 444 // called also immediately after it gets registered.
458 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 445 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
459 .Times(Between(2, 3)) 446 .Times(Between(2, 3))
460 .WillRepeatedly(Return(true)); 447 .WillRepeatedly(Return(true));
461 448
462 for (int i = 0; i < 4; i++) { 449 for (int i = 0; i < 4; i++) {
463 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 450 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
464 g_high_detail_args); 451 MemoryDumpLevelOfDetail::DETAILED);
465 } 452 }
466 453
467 DisableTracing(); 454 DisableTracing();
468 } 455 }
469 456
470 // Like RegisterDumperWhileDumping, but unregister the dump provider instead. 457 // Like RegisterDumperWhileDumping, but unregister the dump provider instead.
471 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) { 458 TEST_F(MemoryDumpManagerTest, UnregisterDumperWhileDumping) {
472 InitializeMemoryDumpManager(false /* is_coordinator */); 459 InitializeMemoryDumpManager(false /* is_coordinator */);
473 MockMemoryDumpProvider mdp1; 460 MockMemoryDumpProvider mdp1;
474 MockMemoryDumpProvider mdp2; 461 MockMemoryDumpProvider mdp2;
(...skipping 15 matching lines...) Expand all
490 .WillRepeatedly(Return(true)); 477 .WillRepeatedly(Return(true));
491 478
492 // Depending on the insertion order (before or after mdp1), mdp2 might have 479 // Depending on the insertion order (before or after mdp1), mdp2 might have
493 // been already called when UnregisterDumpProvider happens. 480 // been already called when UnregisterDumpProvider happens.
494 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) 481 EXPECT_CALL(mdp2, OnMemoryDump(_, _))
495 .Times(Between(1, 2)) 482 .Times(Between(1, 2))
496 .WillRepeatedly(Return(true)); 483 .WillRepeatedly(Return(true));
497 484
498 for (int i = 0; i < 4; i++) { 485 for (int i = 0; i < 4; i++) {
499 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 486 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
500 g_high_detail_args); 487 MemoryDumpLevelOfDetail::DETAILED);
501 } 488 }
502 489
503 DisableTracing(); 490 DisableTracing();
504 } 491 }
505 492
506 // Checks that the dump does not abort when unregistering a provider while 493 // Checks that the dump does not abort when unregistering a provider while
507 // dumping from a different thread than the dumping thread. 494 // dumping from a different thread than the dumping thread.
508 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) { 495 TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) {
509 InitializeMemoryDumpManager(false /* is_coordinator */); 496 InitializeMemoryDumpManager(false /* is_coordinator */);
510 ScopedVector<TestIOThread> threads; 497 ScopedVector<TestIOThread> threads;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 530
544 last_callback_success_ = false; 531 last_callback_success_ = false;
545 MemoryDumpCallback callback = 532 MemoryDumpCallback callback =
546 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 533 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
547 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 534 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
548 535
549 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 536 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
550 537
551 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 538 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
552 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 539 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
553 g_high_detail_args, callback); 540 MemoryDumpLevelOfDetail::DETAILED, callback);
554 541
555 run_loop.Run(); 542 run_loop.Run();
556 543
557 ASSERT_EQ(1, on_memory_dump_call_count); 544 ASSERT_EQ(1, on_memory_dump_call_count);
558 ASSERT_EQ(true, last_callback_success_); 545 ASSERT_EQ(true, last_callback_success_);
559 546
560 DisableTracing(); 547 DisableTracing();
561 } 548 }
562 549
563 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when 550 // Checks that a NACK callback is invoked if RequestGlobalDump() is called when
564 // tracing is not enabled. 551 // tracing is not enabled.
565 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) { 552 TEST_F(MemoryDumpManagerTest, CallbackCalledOnFailure) {
566 InitializeMemoryDumpManager(false /* is_coordinator */); 553 InitializeMemoryDumpManager(false /* is_coordinator */);
567 MockMemoryDumpProvider mdp1; 554 MockMemoryDumpProvider mdp1;
568 mdm_->RegisterDumpProvider(&mdp1); 555 mdm_->RegisterDumpProvider(&mdp1);
569 556
570 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); 557 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
571 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0); 558 EXPECT_CALL(mdp1, OnMemoryDump(_, _)).Times(0);
572 559
573 last_callback_success_ = true; 560 last_callback_success_ = true;
574 { 561 {
575 RunLoop run_loop; 562 RunLoop run_loop;
576 MemoryDumpCallback callback = 563 MemoryDumpCallback callback =
577 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 564 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
578 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 565 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
579 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 566 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
580 g_high_detail_args, callback); 567 MemoryDumpLevelOfDetail::DETAILED, callback);
581 run_loop.Run(); 568 run_loop.Run();
582 } 569 }
583 EXPECT_FALSE(last_callback_success_); 570 EXPECT_FALSE(last_callback_success_);
584 } 571 }
585 572
586 // Checks that is the MemoryDumpManager is initialized after tracing already 573 // Checks that is the MemoryDumpManager is initialized after tracing already
587 // began, it will still late-join the party (real use case: startup tracing). 574 // began, it will still late-join the party (real use case: startup tracing).
588 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) { 575 TEST_F(MemoryDumpManagerTest, InitializedAfterStartOfTracing) {
589 MockMemoryDumpProvider mdp; 576 MockMemoryDumpProvider mdp;
590 mdm_->RegisterDumpProvider(&mdp); 577 mdm_->RegisterDumpProvider(&mdp);
591 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); 578 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory);
592 579
593 // First check that a RequestGlobalDump() issued before the MemoryDumpManager 580 // First check that a RequestGlobalDump() issued before the MemoryDumpManager
594 // initialization gets NACK-ed cleanly. 581 // initialization gets NACK-ed cleanly.
595 { 582 {
596 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0); 583 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(0);
597 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0); 584 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(0);
598 RunLoop run_loop; 585 RunLoop run_loop;
599 MemoryDumpCallback callback = 586 MemoryDumpCallback callback =
600 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 587 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
601 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 588 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
602 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 589 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
603 g_high_detail_args, callback); 590 MemoryDumpLevelOfDetail::DETAILED, callback);
604 run_loop.Run(); 591 run_loop.Run();
605 EXPECT_FALSE(last_callback_success_); 592 EXPECT_FALSE(last_callback_success_);
606 } 593 }
607 594
608 // Now late-initialize the MemoryDumpManager and check that the 595 // Now late-initialize the MemoryDumpManager and check that the
609 // RequestGlobalDump completes successfully. 596 // RequestGlobalDump completes successfully.
610 { 597 {
611 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1); 598 EXPECT_CALL(mdp, OnMemoryDump(_, _)).Times(1);
612 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); 599 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1);
613 InitializeMemoryDumpManager(false /* is_coordinator */); 600 InitializeMemoryDumpManager(false /* is_coordinator */);
614 RunLoop run_loop; 601 RunLoop run_loop;
615 MemoryDumpCallback callback = 602 MemoryDumpCallback callback =
616 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this), 603 Bind(&MemoryDumpManagerTest::DumpCallbackAdapter, Unretained(this),
617 MessageLoop::current()->task_runner(), run_loop.QuitClosure()); 604 MessageLoop::current()->task_runner(), run_loop.QuitClosure());
618 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED, 605 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED,
619 g_high_detail_args, callback); 606 MemoryDumpLevelOfDetail::DETAILED, callback);
620 run_loop.Run(); 607 run_loop.Run();
621 EXPECT_TRUE(last_callback_success_); 608 EXPECT_TRUE(last_callback_success_);
622 } 609 }
623 DisableTracing(); 610 DisableTracing();
624 } 611 }
625 612
626 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the 613 // This test (and the MemoryDumpManagerTestCoordinator below) crystallizes the
627 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic 614 // expectations of the chrome://tracing UI and chrome telemetry w.r.t. periodic
628 // dumps in memory-infra, handling gracefully the transition between the legacy 615 // dumps in memory-infra, handling gracefully the transition between the legacy
629 // and the new-style (JSON-based) TraceConfig. 616 // and the new-style (JSON-based) TraceConfig.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // process with a fully defined trigger config should cause periodic dumps to 673 // process with a fully defined trigger config should cause periodic dumps to
687 // be performed in the correct order. 674 // be performed in the correct order.
688 RunLoop run_loop; 675 RunLoop run_loop;
689 auto quit_closure = run_loop.QuitClosure(); 676 auto quit_closure = run_loop.QuitClosure();
690 677
691 const int kHeavyDumpRate = 5; 678 const int kHeavyDumpRate = 5;
692 const int kLightDumpPeriodMs = 1; 679 const int kLightDumpPeriodMs = 1;
693 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs; 680 const int kHeavyDumpPeriodMs = kHeavyDumpRate * kLightDumpPeriodMs;
694 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,... 681 // The expected sequence with light=1ms, heavy=5ms is H,L,L,L,L,H,...
695 testing::InSequence sequence; 682 testing::InSequence sequence;
696 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsHighDetailArgs(), _)); 683 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _));
697 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLowDetailArgs(), _)) 684 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
698 .Times(kHeavyDumpRate - 1); 685 .Times(kHeavyDumpRate - 1);
699 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsHighDetailArgs(), _)); 686 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsDetailedDump(), _));
700 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLowDetailArgs(), _)) 687 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
701 .Times(kHeavyDumpRate - 2); 688 .Times(kHeavyDumpRate - 2);
702 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLowDetailArgs(), _)) 689 EXPECT_CALL(delegate, RequestGlobalMemoryDump(IsLightDump(), _))
703 .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args, 690 .WillOnce(Invoke([quit_closure](const MemoryDumpRequestArgs& args,
704 const MemoryDumpCallback& callback) { 691 const MemoryDumpCallback& callback) {
705 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); 692 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure);
706 })); 693 }));
707 694
708 // Swallow all the final spurious calls until tracing gets disabled. 695 // Swallow all the final spurious calls until tracing gets disabled.
709 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber()); 696 EXPECT_CALL(delegate, RequestGlobalMemoryDump(_, _)).Times(AnyNumber());
710 697
711 EnableTracingWithTraceConfig( 698 EnableTracingWithTraceConfig(
712 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers( 699 TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(
713 kLightDumpPeriodMs, kHeavyDumpPeriodMs)); 700 kLightDumpPeriodMs, kHeavyDumpPeriodMs));
714 run_loop.Run(); 701 run_loop.Run();
715 DisableTracing(); 702 DisableTracing();
716 } 703 }
717 704
718 } // namespace trace_event 705 } // namespace trace_event
719 } // namespace base 706 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698