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

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: Review fixes 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/pattern.h" 8 #include "base/strings/pattern.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "content/browser/tracing/background_tracing_manager_impl.h" 10 #include "content/browser/tracing/background_tracing_manager_impl.h"
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 661 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
662 handle, 662 handle,
663 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false)); 663 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
664 664
665 run_loop.Run(); 665 run_loop.Run();
666 666
667 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0); 667 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
668 } 668 }
669 } 669 }
670 670
671 // This tests that no preemptive trace is triggered with 0 chance set.
672 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
673 PreemptiveNotTriggerWithZeroChance) {
674 {
675 SetupBackgroundTracingManager();
676
677 base::RunLoop run_loop;
678 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
679 (base::Closure()));
680
681 base::DictionaryValue dict;
682
683 dict.SetString("mode", "PREEMPTIVE_TRACING_MODE");
684 dict.SetString("category", "BENCHMARK");
685
686 scoped_ptr<base::ListValue> rules_list(new base::ListValue());
687 {
688 scoped_ptr<base::DictionaryValue> rules_dict(new base::DictionaryValue());
689 rules_dict->SetString("rule", "MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED");
690 rules_dict->SetString("trigger_name", "preemptive_test");
691 rules_dict->SetDouble("trigger_chance", 0.0);
692 rules_list->Append(rules_dict.Pass());
693 }
694 dict.Set("configs", rules_list.Pass());
695
696 scoped_ptr<BackgroundTracingConfig> config(
697 BackgroundTracingConfigImpl::FromDict(&dict));
698
699 EXPECT_TRUE(config);
700
701 content::BackgroundTracingManager::TriggerHandle handle =
702 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
703 "preemptive_test");
704
705 BackgroundTracingManager::GetInstance()->SetActiveScenario(
706 config.Pass(), upload_config_wrapper.get_receive_callback(),
707 BackgroundTracingManager::NO_DATA_FILTERING);
708
709 BackgroundTracingManager::GetInstance()->WhenIdle(
710 base::Bind(&DisableScenarioWhenIdle));
711
712 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
713 handle,
714 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
715
716 run_loop.Run();
717
718 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
719 }
720 }
721
722 // This tests that no reactive trace is triggered with 0 chance set.
723 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
724 ReactiveNotTriggerWithZeroChance) {
725 {
726 SetupBackgroundTracingManager();
727
728 base::RunLoop run_loop;
729 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
730 (base::Closure()));
731
732 base::DictionaryValue dict;
733
734 dict.SetString("mode", "REACTIVE_TRACING_MODE");
735
736 scoped_ptr<base::ListValue> rules_list(new base::ListValue());
737 {
738 scoped_ptr<base::DictionaryValue> rules_dict(new base::DictionaryValue());
739 rules_dict->SetString("rule",
740 "TRACE_ON_NAVIGATION_UNTIL_TRIGGER_OR_FULL");
741 rules_dict->SetString("trigger_name", "reactive_test1");
742 rules_dict->SetString("category", "BENCHMARK");
743 rules_dict->SetDouble("trigger_chance", 0.0);
744
745 rules_list->Append(rules_dict.Pass());
746 }
747 dict.Set("configs", rules_list.Pass());
748
749 scoped_ptr<BackgroundTracingConfig> config(
750 BackgroundTracingConfigImpl::FromDict(&dict));
751
752 EXPECT_TRUE(config);
753
754 content::BackgroundTracingManager::TriggerHandle handle =
755 content::BackgroundTracingManager::GetInstance()->RegisterTriggerType(
756 "preemptive_test");
757
758 BackgroundTracingManager::GetInstance()->SetActiveScenario(
759 config.Pass(), upload_config_wrapper.get_receive_callback(),
760 BackgroundTracingManager::NO_DATA_FILTERING);
761
762 BackgroundTracingManager::GetInstance()->WhenIdle(
763 base::Bind(&DisableScenarioWhenIdle));
764
765 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
766 handle,
767 base::Bind(&StartedFinalizingCallback, run_loop.QuitClosure(), false));
768
769 run_loop.Run();
770
771 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 0);
772 }
773 }
774
671 // This tests that histogram triggers for preemptive mode configs. 775 // This tests that histogram triggers for preemptive mode configs.
672 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest, 776 IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
673 ReceiveTraceSucceedsOnHigherHistogramSample) { 777 ReceiveTraceSucceedsOnHigherHistogramSample) {
674 { 778 {
675 SetupBackgroundTracingManager(); 779 SetupBackgroundTracingManager();
676 780
677 base::RunLoop run_loop; 781 base::RunLoop run_loop;
678 782
679 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper( 783 BackgroundTracingManagerUploadConfigWrapper upload_config_wrapper(
680 run_loop.QuitClosure()); 784 run_loop.QuitClosure());
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 BackgroundTracingManager::GetInstance()->TriggerNamedEvent( 1104 BackgroundTracingManager::GetInstance()->TriggerNamedEvent(
1001 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false)); 1105 handle, base::Bind(&StartedFinalizingCallback, base::Closure(), false));
1002 1106
1003 run_loop.Run(); 1107 run_loop.Run();
1004 1108
1005 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1); 1109 EXPECT_TRUE(upload_config_wrapper.get_receive_count() == 1);
1006 } 1110 }
1007 } 1111 }
1008 1112
1009 } // namespace content 1113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698