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

Side by Side Diff: content/browser/tracing/background_tracing_manager_browsertest.cc

Issue 1148393003: Implement Reactive Configuration in Background Tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 5 years, 6 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
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/bind.h" 5 #include "base/bind.h"
6 #include "content/public/browser/background_tracing_manager.h" 6 #include "content/public/browser/background_tracing_manager.h"
7 #include "content/public/browser/background_tracing_preemptive_config.h" 7 #include "content/public/browser/background_tracing_preemptive_config.h"
8 #include "content/public/browser/background_tracing_reactive_config.h" 8 #include "content/public/browser/background_tracing_reactive_config.h"
9 #include "content/public/test/content_browser_test.h" 9 #include "content/public/test/content_browser_test.h"
10 #include "content/public/test/content_browser_test_utils.h" 10 #include "content/public/test/content_browser_test_utils.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 callback.Run(); 60 callback.Run();
61 } 61 }
62 62
63 scoped_ptr<BackgroundTracingPreemptiveConfig> CreatePreemptiveConfig() { 63 scoped_ptr<BackgroundTracingPreemptiveConfig> CreatePreemptiveConfig() {
64 scoped_ptr<BackgroundTracingPreemptiveConfig> config( 64 scoped_ptr<BackgroundTracingPreemptiveConfig> config(
65 new BackgroundTracingPreemptiveConfig()); 65 new BackgroundTracingPreemptiveConfig());
66 66
67 BackgroundTracingPreemptiveConfig::MonitoringRule rule; 67 BackgroundTracingPreemptiveConfig::MonitoringRule rule;
68 rule.type = 68 rule.type =
69 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED; 69 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED;
70 rule.named_trigger_info.trigger_name = "test"; 70 rule.named_trigger_info.trigger_name = "preemptive_test";
71 71
72 config->configs.push_back(rule); 72 config->configs.push_back(rule);
73 73
74 return config.Pass();
75 }
76
77 scoped_ptr<BackgroundTracingReactiveConfig> CreateReactiveConfig() {
78 scoped_ptr<BackgroundTracingReactiveConfig> config(
79 new BackgroundTracingReactiveConfig());
80
81 BackgroundTracingReactiveConfig::TracingRule rule;
82 rule.type =
83 BackgroundTracingReactiveConfig::TRACE_UNTIL_10S_OR_TRIGGER_OR_FULL;
84 rule.trigger_name = "reactive_test";
85 rule.category_preset =
86 BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP;
87
88 config->configs.push_back(rule);
89
74 return config.Pass(); 90 return config.Pass();
75 } 91 }
76 92
77 void SetupBackgroundTracingManager() { 93 void SetupBackgroundTracingManager() {
78 content::BackgroundTracingManager::GetInstance() 94 content::BackgroundTracingManager::GetInstance()
79 ->InvalidateTriggerHandlesForTesting(); 95 ->InvalidateTriggerHandlesForTesting();
80 } 96 }
81 97
82 void DisableScenarioWhenIdle() { 98 void DisableScenarioWhenIdle() {
83 BackgroundTracingManager::GetInstance()->SetActiveScenario( 99 BackgroundTracingManager::GetInstance()->SetActiveScenario(
84 NULL, BackgroundTracingManager::ReceiveCallback(), false); 100 NULL, BackgroundTracingManager::ReceiveCallback(), false);
85 } 101 }
86 102
87 // This tests that the endpoint receives the final trace data. 103 // This tests that the endpoint receives the final trace data.
88 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, 104 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
89 ReceiveTraceFinalContentsOnTrigger) { 105 ReceiveTraceFinalContentsOnTrigger) {
90 { 106 {
91 SetupBackgroundTracingManager(); 107 SetupBackgroundTracingManager();
92 108
93 base::RunLoop run_loop; 109 base::RunLoop run_loop;
94 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 110 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
95 run_loop.QuitClosure()); 111 run_loop.QuitClosure());
96 112
97 scoped_ptr<BackgroundTracingPreemptiveConfig> config = 113 scoped_ptr<BackgroundTracingPreemptiveConfig> config =
98 CreatePreemptiveConfig(); 114 CreatePreemptiveConfig();
99 115
100 BackgroundTracingManager::TriggerHandle handle = 116 BackgroundTracingManager::TriggerHandle handle =
101 BackgroundTracingManager::GetInstance()->RegisterTriggerType("test"); 117 BackgroundTracingManager::
118 GetInstance()->RegisterTriggerType("preemptive_test");
102 119
103 BackgroundTracingManager::GetInstance()->SetActiveScenario( 120 BackgroundTracingManager::GetInstance()->SetActiveScenario(
104 config.Pass(), upload_config_wrapper.get_receive_callback(), true); 121 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
105 122
106 BackgroundTracingManager::GetInstance()->WhenIdle( 123 BackgroundTracingManager::GetInstance()->WhenIdle(
107 base::Bind(&DisableScenarioWhenIdle)); 124 base::Bind(&DisableScenarioWhenIdle));
108 125
109 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 126 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
110 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true)); 127 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
111 128
(...skipping 11 matching lines...) Expand all
123 140
124 base::RunLoop run_loop; 141 base::RunLoop run_loop;
125 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 142 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
126 run_loop.QuitClosure()); 143 run_loop.QuitClosure());
127 144
128 scoped_ptr<BackgroundTracingPreemptiveConfig> config = 145 scoped_ptr<BackgroundTracingPreemptiveConfig> config =
129 CreatePreemptiveConfig(); 146 CreatePreemptiveConfig();
130 147
131 content::BackgroundTracingManager::TriggerHandle handle = 148 content::BackgroundTracingManager::TriggerHandle handle =
132 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType( 149 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
133 "test"); 150 "preemptive_test");
134 151
135 BackgroundTracingManager::GetInstance()->SetActiveScenario( 152 BackgroundTracingManager::GetInstance()->SetActiveScenario(
136 config.Pass(), upload_config_wrapper.get_receive_callback(), true); 153 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
137 154
138 BackgroundTracingManager::GetInstance()->WhenIdle( 155 BackgroundTracingManager::GetInstance()->WhenIdle(
139 base::Bind(&DisableScenarioWhenIdle)); 156 base::Bind(&DisableScenarioWhenIdle));
140 157
141 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 158 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
142 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true)); 159 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
143 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 160 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 SetupBackgroundTracingManager(); 218 SetupBackgroundTracingManager();
202 219
203 base::RunLoop run_loop; 220 base::RunLoop run_loop;
204 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 221 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
205 (base::Closure())); 222 (base::Closure()));
206 223
207 scoped_ptr<BackgroundTracingConfig> config = CreatePreemptiveConfig(); 224 scoped_ptr<BackgroundTracingConfig> config = CreatePreemptiveConfig();
208 225
209 content::BackgroundTracingManager::TriggerHandle handle = 226 content::BackgroundTracingManager::TriggerHandle handle =
210 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType( 227 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
211 "test"); 228 "preemptive_test");
212 229
213 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 230 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
214 handle, 231 handle,
215 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false)); 232 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
216 233
217 run_loop.Run(); 234 run_loop.Run();
218 235
219 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0); 236 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
220 } 237 }
221 } 238 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 279
263 base::RunLoop run_loop; 280 base::RunLoop run_loop;
264 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 281 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
265 (base::Closure())); 282 (base::Closure()));
266 283
267 scoped_ptr<BackgroundTracingPreemptiveConfig> config = 284 scoped_ptr<BackgroundTracingPreemptiveConfig> config =
268 CreatePreemptiveConfig(); 285 CreatePreemptiveConfig();
269 286
270 content::BackgroundTracingManager::TriggerHandle handle = 287 content::BackgroundTracingManager::TriggerHandle handle =
271 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType( 288 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
272 "test"); 289 "preemptive_test");
273 290
274 content::BackgroundTracingManager::GetInstance() 291 content::BackgroundTracingManager::GetInstance()
275 ->InvalidateTriggerHandlesForTesting(); 292 ->InvalidateTriggerHandlesForTesting();
276 293
277 BackgroundTracingManager::GetInstance()->SetActiveScenario( 294 BackgroundTracingManager::GetInstance()->SetActiveScenario(
278 config.Pass(), upload_config_wrapper.get_receive_callback(), true); 295 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
279 296
280 BackgroundTracingManager::GetInstance()->WhenIdle( 297 BackgroundTracingManager::GetInstance()->WhenIdle(
281 base::Bind(&DisableScenarioWhenIdle)); 298 base::Bind(&DisableScenarioWhenIdle));
282 299
283 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 300 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
284 handle, 301 handle,
285 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false)); 302 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
286 303
287 run_loop.Run(); 304 run_loop.Run();
288 305
289 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0); 306 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
290 } 307 }
291 } 308 }
292 309
293 // This tests that reactive mode configs will fail. 310 // This tests that preemptive mode configs will fail.
294 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, 311 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
295 DoesNotAllowPreemptiveConfigThatsNotManual) { 312 DoesNotAllowPreemptiveConfigThatsNotManual) {
296 { 313 {
297 SetupBackgroundTracingManager(); 314 SetupBackgroundTracingManager();
298 315
299 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 316 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
300 (base::Closure())); 317 (base::Closure()));
301 318
302 scoped_ptr<BackgroundTracingPreemptiveConfig> config( 319 scoped_ptr<BackgroundTracingPreemptiveConfig> config(
303 new content::BackgroundTracingPreemptiveConfig()); 320 new content::BackgroundTracingPreemptiveConfig());
304 321
305 BackgroundTracingPreemptiveConfig::MonitoringRule rule; 322 BackgroundTracingPreemptiveConfig::MonitoringRule rule;
306 rule.type = BackgroundTracingPreemptiveConfig:: 323 rule.type = BackgroundTracingPreemptiveConfig::
307 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE; 324 MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE;
308 rule.histogram_trigger_info.histogram_name_to_trigger_on = "fake"; 325 rule.histogram_trigger_info.histogram_name_to_trigger_on = "fake";
309 rule.histogram_trigger_info.histogram_bin_to_trigger_on = 0; 326 rule.histogram_trigger_info.histogram_bin_to_trigger_on = 0;
310 config->configs.push_back(rule); 327 config->configs.push_back(rule);
311 328
312 bool result = BackgroundTracingManager::GetInstance()->SetActiveScenario( 329 bool result = BackgroundTracingManager::GetInstance()->SetActiveScenario(
313 config.Pass(), upload_config_wrapper.get_receive_callback(), true); 330 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
314 331
315 EXPECT_FALSE(result); 332 EXPECT_FALSE(result);
316 } 333 }
317 } 334 }
318 335
319 // This tests that reactive mode configs will fail. 336 // This tests that reactive mode records and terminates with timeout.
320 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, 337 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
321 DoesNotAllowReactiveConfig) { 338 ReactiveTimeoutTermination) {
322 { 339 {
323 SetupBackgroundTracingManager(); 340 SetupBackgroundTracingManager();
324 341
342
343 base::RunLoop run_loop;
325 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 344 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
326 (base::Closure())); 345 run_loop.QuitClosure());
327 346
328 scoped_ptr<BackgroundTracingConfig> config( 347 scoped_ptr<BackgroundTracingReactiveConfig> config =
329 new BackgroundTracingReactiveConfig()); 348 CreateReactiveConfig();
330 349
331 bool result = BackgroundTracingManager::GetInstance()->SetActiveScenario( 350 BackgroundTracingManager::TriggerHandle handle =
351 BackgroundTracingManager::
352 GetInstance()->RegisterTriggerType("reactive_test");
353
354 BackgroundTracingManager::GetInstance()->SetActiveScenario(
332 config.Pass(), upload_config_wrapper.get_receive_callback(), true); 355 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
333 356
334 EXPECT_FALSE(result); 357 BackgroundTracingManager::GetInstance()->WhenIdle(
358 base::Bind(&DisableScenarioWhenIdle));
359
360 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
dsinclair 2015/06/01 19:14:52 What is the timeout this is using? How long will t
fmeawad 2015/06/02 21:15:27 I added a Test fire to make it instant, it used to
361 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
362
363 run_loop.Run();
364
365 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
335 } 366 }
336 } 367 }
337 368
369 // This tests that reactive mode records and terminates with a second trigger.
370 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
371 ReactiveSecondTriggerTermination) {
372 {
373 SetupBackgroundTracingManager();
374
375
dsinclair 2015/06/01 19:14:52 nit: extra blank line.
fmeawad 2015/06/02 21:15:28 Done.
376 base::RunLoop run_loop;
377 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
378 run_loop.QuitClosure());
379
380 scoped_ptr<BackgroundTracingReactiveConfig> config =
381 CreateReactiveConfig();
382
383 BackgroundTracingManager::TriggerHandle handle =
384 BackgroundTracingManager::
385 GetInstance()->RegisterTriggerType("reactive_test");
386
387 BackgroundTracingManager::GetInstance()->SetActiveScenario(
388 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
389
390 BackgroundTracingManager::GetInstance()->WhenIdle(
391 base::Bind(&DisableScenarioWhenIdle));
392
393 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
394 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
395 // second trigger to terminate.
396 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
dsinclair 2015/06/01 19:14:52 How do we know this terminated because of the seco
fmeawad 2015/06/02 21:15:28 The timeout is 10 seconds. It is not guaranteed, b
397 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
398
399 run_loop.Run();
400
401 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
402 }
403 }
404
405 // This tests that reactive mode multiple still triggers gathers once.
dsinclair 2015/06/01 19:14:52 I'm not sure what this is trying to say? triggers
fmeawad 2015/06/02 21:15:28 Fixed.
406 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
407 ReactiveThirdTriggerTimeout) {
408 {
409 SetupBackgroundTracingManager();
410
411
dsinclair 2015/06/01 19:14:52 nit: remove blank link.
fmeawad 2015/06/02 21:15:28 Done.
412 base::RunLoop run_loop;
413 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
414 run_loop.QuitClosure());
415
416 scoped_ptr<BackgroundTracingReactiveConfig> config =
417 CreateReactiveConfig();
418
419 BackgroundTracingManager::TriggerHandle handle =
420 BackgroundTracingManager::
421 GetInstance()->RegisterTriggerType("reactive_test");
422
423 BackgroundTracingManager::GetInstance()->SetActiveScenario(
424 config.Pass(), upload_config_wrapper.get_receive_callback(), true);
425
426 BackgroundTracingManager::GetInstance()->WhenIdle(
427 base::Bind(&DisableScenarioWhenIdle));
428
429 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
430 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
431 // second trigger to terminate.
432 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
433 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), true));
434 // third trigger to trigger again, fails as it is still gathering.
435 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
436 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false));
dsinclair 2015/06/01 19:14:52 How do we know this failed?
fmeawad 2015/06/02 21:15:28 The callback (StartedFinalizingCallback) is bound
437
438 run_loop.Run();
439
440 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
441 }
442 }
443
338 } // namespace content 444 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698