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

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

Issue 1427873003: Background tracing: Added trace_chance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 "base/metrics/histogram_macros.h" 6 #include "base/metrics/histogram_macros.h"
7 #include "base/strings/pattern.h" 7 #include "base/strings/pattern.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "content/browser/tracing/background_tracing_manager_impl.h" 9 #include "content/browser/tracing/background_tracing_manager_impl.h"
10 #include "content/browser/tracing/background_tracing_rule.h" 10 #include "content/browser/tracing/background_tracing_rule.h"
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 569 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
570 handle, 570 handle,
571 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false)); 571 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
572 572
573 run_loop.Run(); 573 run_loop.Run();
574 574
575 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0); 575 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
576 } 576 }
577 } 577 }
578 578
579 // This tests that no preemptive trace is triggered with 0 chance set.
580 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
581 PreemptiveNotTriggerWithZeroChance) {
582 {
583 SetupBackgroundTracingManager();
584
585 base::RunLoop run_loop;
586 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
587 (base::Closure()));
588
589 base::DictionaryValue dict;
590
591 dict.SetString("mode", "PREEMPTIVE_TRACING_MODE");
592 dict.SetString("category", "BENCHMARK");
593
594 scoped_ptr<base::ListValue> rules_list(new base::ListValue());
595 {
596 scoped_ptr<base::DictionaryValue> rules_dict(new base::DictionaryValue());
597 rules_dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED");
598 rules_dict->SetString("trigger_name", "preemptive_test");
599 rules_dict->SetDouble("trigger_chance", 0.0);
600 rules_list->Append(rules_dict.Pass());
601 }
602 dict.Set("configs", rules_list.Pass());
603
604 scoped_ptr<BackgroundTracingConfig> config(
605 BackgroundTracingConfigImpl::FromDict(&dict));
606
607 EXPECT_TRUE(config);
608
609 content::BackgroundTracingManager::TriggerHandle handle =
610 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
611 "preemptive_test");
612
613 BackgroundTracingManager::GetInstance()->SetActiveScenario(
614 config.Pass(), upload_config_wrapper.get_receive_callback(),
615 BackgroundTracingManager::NO_DATA_FILTERING);
616
617 BackgroundTracingManager::GetInstance()->WhenIdle(
618 base::Bind(&DisableScenarioWhenIdle));
619
620 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
621 handle,
622 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
623
624 run_loop.Run();
625
626 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
627 }
628 }
629
630 // This tests that no preemptive trace is triggered with 0 chance set.
shatch 2015/10/30 15:50:28 nit: reactive
oystein (OOO til 10th of July) 2015/10/30 19:11:43 Done.
631 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
632 ReactiveNotTriggerWithZeroChance) {
633 {
634 SetupBackgroundTracingManager();
635
636 base::RunLoop run_loop;
637 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
638 (base::Closure()));
639
640 base::DictionaryValue dict;
641
642 dict.SetString("mode", "REACTIVE_TRACING_MODE");
643
644 scoped_ptr<base::ListValue> rules_list(new base::ListValue());
645 {
646 scoped_ptr<base::DictionaryValue> rules_dict(new base::DictionaryValue());
647 rules_dict->SetString("rule",
648 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
649 rules_dict->SetString("trigger_name", "reactive_test1");
650 rules_dict->SetString("category", "BENCHMARK");
651 rules_dict->SetDouble("trigger_chance", 0.0);
652
653 rules_list->Append(rules_dict.Pass());
654 }
655 dict.Set("configs", rules_list.Pass());
656
657 scoped_ptr<BackgroundTracingConfig> config(
658 BackgroundTracingConfigImpl::FromDict(&dict));
659
660 EXPECT_TRUE(config);
661
662 content::BackgroundTracingManager::TriggerHandle handle =
663 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
664 "preemptive_test");
665
666 BackgroundTracingManager::GetInstance()->SetActiveScenario(
667 config.Pass(), upload_config_wrapper.get_receive_callback(),
668 BackgroundTracingManager::NO_DATA_FILTERING);
669
670 BackgroundTracingManager::GetInstance()->WhenIdle(
671 base::Bind(&DisableScenarioWhenIdle));
672
673 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
674 handle,
675 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
676
677 run_loop.Run();
678
679 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
680 }
681 }
682
579 // This tests that histogram triggers for preemptive mode configs. 683 // This tests that histogram triggers for preemptive mode configs.
580 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, 684 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
581 ReceiveTraceSucceedsOnHigherHistogramSample) { 685 ReceiveTraceSucceedsOnHigherHistogramSample) {
582 { 686 {
583 SetupBackgroundTracingManager(); 687 SetupBackgroundTracingManager();
584 688
585 base::RunLoop run_loop; 689 base::RunLoop run_loop;
586 690
587 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 691 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
588 run_loop.QuitClosure()); 692 run_loop.QuitClosure());
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 1012 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
909 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); 1013 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false));
910 1014
911 run_loop.Run(); 1015 run_loop.Run();
912 1016
913 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); 1017 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
914 } 1018 }
915 } 1019 }
916 1020
917 } // namespace content 1021 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698