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

Side by Side Diff: chrome/browser/metrics/perf/perf_provider_chromeos_unittest.cc

Issue 1392153003: PerfProvider: Get collection parameters from Finch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@perf_commands
Patch Set: Address comments on PS3 Created 5 years, 2 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 "chrome/browser/metrics/perf/perf_provider_chromeos.h" 5 #include "chrome/browser/metrics/perf/perf_provider_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/field_trial.h"
12 #include "base/test/test_simple_task_runner.h" 13 #include "base/test/test_simple_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "chrome/browser/metrics/perf/windowed_incognito_observer.h" 15 #include "chrome/browser/metrics/perf/windowed_incognito_observer.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/login/login_state.h" 17 #include "chromeos/login/login_state.h"
17 #include "components/metrics/proto/sampled_profile.pb.h" 18 #include "components/metrics/proto/sampled_profile.pb.h"
19 #include "components/variations/variations_associated_data.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 21
20 namespace metrics { 22 namespace metrics {
21 23
22 namespace { 24 namespace {
23 25
24 // Return values for perf. 26 // Return values for perf.
25 const int kPerfSuccess = 0; 27 const int kPerfSuccess = 0;
26 const int kPerfFailure = 1; 28 const int kPerfFailure = 1;
27 29
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 observer->set_incognito_launched(incognito_launched); 115 observer->set_incognito_launched(incognito_launched);
114 return observer.Pass(); 116 return observer.Pass();
115 } 117 }
116 118
117 private: 119 private:
118 TestIncognitoObserver() {} 120 TestIncognitoObserver() {}
119 121
120 DISALLOW_COPY_AND_ASSIGN(TestIncognitoObserver); 122 DISALLOW_COPY_AND_ASSIGN(TestIncognitoObserver);
121 }; 123 };
122 124
123 // Allows access to PerfProvider::ParseOutputProtoIfValid() for testing. 125 // Allows access to some private methods for testing.
124 class TestPerfProvider : public PerfProvider { 126 class TestPerfProvider : public PerfProvider {
125 public: 127 public:
126 TestPerfProvider() {} 128 TestPerfProvider() {}
127 129
128 using PerfProvider::ParseOutputProtoIfValid; 130 using PerfProvider::ParseOutputProtoIfValid;
131 using PerfProvider::collection_params;
132 using PerfProvider::command_selector;
129 133
130 private: 134 private:
131 std::vector<SampledProfile> stored_profiles_; 135 std::vector<SampledProfile> stored_profiles_;
132 136
133 DISALLOW_COPY_AND_ASSIGN(TestPerfProvider); 137 DISALLOW_COPY_AND_ASSIGN(TestPerfProvider);
134 }; 138 };
135 139
136 } // namespace 140 } // namespace
137 141
138 class PerfProviderTest : public testing::Test { 142 class PerfProviderTest : public testing::Test {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 cpuid.vendor = ""; 579 cpuid.vendor = "";
576 cpuid.family = 0; 580 cpuid.family = 0;
577 cpuid.model = 0; 581 cpuid.model = 0;
578 cpuid.model_name = ""; 582 cpuid.model_name = "";
579 std::vector<RandomSelector::WeightAndValue> cmds = 583 std::vector<RandomSelector::WeightAndValue> cmds =
580 internal::GetDefaultCommandsForCpu(cpuid); 584 internal::GetDefaultCommandsForCpu(cpuid);
581 EXPECT_EQ(1UL, cmds.size()); 585 EXPECT_EQ(1UL, cmds.size());
582 EXPECT_EQ(cmds[0].value, kPerfRecordCyclesCmd); 586 EXPECT_EQ(cmds[0].value, kPerfRecordCyclesCmd);
583 } 587 }
584 588
589 TEST_F(PerfProviderTest, CommandMatching_Empty) {
590 CPUIdentity cpuid = {};
591 std::map<std::string, std::string> params;
592 EXPECT_EQ("", internal::FindBestCpuSpecifierFromParams(params, cpuid));
593 }
594
595 TEST_F(PerfProviderTest, CommandMatching_NoPerfCommands) {
596 CPUIdentity cpuid = {};
597 std::map<std::string, std::string> params;
598 params.insert(std::make_pair("NotEvenClose", ""));
599 params.insert(std::make_pair("NotAPerfCommand", ""));
600 params.insert(std::make_pair("NotAPerfCommand::Really", ""));
601 params.insert(std::make_pair("NotAPerfCommand::Nope::0", ""));
602 params.insert(std::make_pair("PerfCommands::SoClose::0", ""));
603 EXPECT_EQ("", internal::FindBestCpuSpecifierFromParams(params, cpuid));
604 }
605
606 TEST_F(PerfProviderTest, CommandMatching_NoMatch) {
607 CPUIdentity cpuid;
608 cpuid.arch = "x86_64";
609 cpuid.vendor = "GenuineIntel";
610 cpuid.family = 6;
611 cpuid.model = 0x3a; // IvyBridge
612 cpuid.model_name = "Xeon or somesuch";
613 std::map<std::string, std::string> params;
614 params.insert(std::make_pair("PerfCommand::armv7l::0", "perf command"));
615 params.insert(std::make_pair("PerfCommand::x86::0", "perf command"));
616 params.insert(std::make_pair("PerfCommand::x86::1", "perf command"));
617 params.insert(std::make_pair("PerfCommand::Broadwell::0", "perf command"));
618
619 EXPECT_EQ("", internal::FindBestCpuSpecifierFromParams(params, cpuid));
620 }
621
622 TEST_F(PerfProviderTest, CommandMatching_default) {
623 CPUIdentity cpuid;
624 cpuid.arch = "x86_64";
625 cpuid.vendor = "GenuineIntel";
626 cpuid.family = 6;
627 cpuid.model = 0x3a; // IvyBridge
628 cpuid.model_name = "Xeon or somesuch";
629 std::map<std::string, std::string> params;
630 params.insert(std::make_pair("PerfCommand::default::0", "perf command"));
631 params.insert(std::make_pair("PerfCommand::armv7l::0", "perf command"));
632 params.insert(std::make_pair("PerfCommand::x86::0", "perf command"));
633 params.insert(std::make_pair("PerfCommand::x86::1", "perf command"));
634 params.insert(std::make_pair("PerfCommand::Broadwell::0", "perf command"));
635
636 EXPECT_EQ("default", internal::FindBestCpuSpecifierFromParams(params, cpuid));
637 }
638
639 TEST_F(PerfProviderTest, CommandMatching_SystemArch) {
640 CPUIdentity cpuid;
641 cpuid.arch = "nothing_in_particular";
642 cpuid.vendor = "";
643 cpuid.family = 0;
644 cpuid.model = 0;
645 cpuid.model_name = "";
646 std::map<std::string, std::string> params;
647 params.insert(std::make_pair("PerfCommand::default::0", "perf command"));
648 params.insert(std::make_pair("PerfCommand::armv7l::0", "perf command"));
649 params.insert(std::make_pair("PerfCommand::x86::0", "perf command"));
650 params.insert(std::make_pair("PerfCommand::x86::1", "perf command"));
651 params.insert(std::make_pair("PerfCommand::x86_64::0", "perf command"));
652 params.insert(std::make_pair("PerfCommand::x86_64::xyz#$%", "perf command"));
653 params.insert(std::make_pair("PerfCommand::Broadwell::0", "perf command"));
654
655 EXPECT_EQ("default", internal::FindBestCpuSpecifierFromParams(params, cpuid));
656
657 cpuid.arch = "armv7l";
658 EXPECT_EQ("armv7l", internal::FindBestCpuSpecifierFromParams(params, cpuid));
659
660 cpuid.arch = "x86";
661 EXPECT_EQ("x86", internal::FindBestCpuSpecifierFromParams(params, cpuid));
662
663 cpuid.arch = "x86_64";
664 EXPECT_EQ("x86_64", internal::FindBestCpuSpecifierFromParams(params, cpuid));
665 }
666
667 TEST_F(PerfProviderTest, CommandMatching_Microarchitecture) {
668 CPUIdentity cpuid;
669 cpuid.arch = "x86_64";
670 cpuid.vendor = "GenuineIntel";
671 cpuid.family = 6;
672 cpuid.model = 0x3D; // Broadwell
673 cpuid.model_name = "Wrong Model CPU @ 0 Hz";
674 std::map<std::string, std::string> params;
675 params.insert(std::make_pair("PerfCommand::default::0", "perf command"));
676 params.insert(std::make_pair("PerfCommand::x86_64::0", "perf command"));
677 params.insert(std::make_pair("PerfCommand::Broadwell::0", "perf command"));
678 params.insert(std::make_pair("PerfCommand::interesting-model-500x::0",
679 "perf command"));
680
681 EXPECT_EQ("Broadwell",
682 internal::FindBestCpuSpecifierFromParams(params, cpuid));
683 }
684
685 TEST_F(PerfProviderTest, CommandMatching_SpecificModel) {
686 CPUIdentity cpuid;
687 cpuid.arch = "x86_64";
688 cpuid.vendor = "GenuineIntel";
689 cpuid.family = 6;
690 cpuid.model = 0x3D; // Broadwell
691 cpuid.model_name = "An Interesting(R) Model(R) 500x CPU @ 1.2GHz";
692 std::map<std::string, std::string> params;
693 params.insert(std::make_pair("PerfCommand::default::0", "perf command"));
694 params.insert(std::make_pair("PerfCommand::x86_64::0", "perf command"));
695 params.insert(std::make_pair("PerfCommand::Broadwell::0", "perf command"));
696 params.insert(std::make_pair("PerfCommand::interesting-model-500x::0",
697 "perf command"));
698
699 EXPECT_EQ("interesting-model-500x",
700 internal::FindBestCpuSpecifierFromParams(params, cpuid));
701 }
702
703 TEST_F(PerfProviderTest, CommandMatching_SpecificModel_LongestMatch) {
704 CPUIdentity cpuid;
705 cpuid.arch = "x86_64";
706 cpuid.vendor = "GenuineIntel";
707 cpuid.family = 6;
708 cpuid.model = 0x3D; // Broadwell
709 cpuid.model_name = "An Interesting(R) Model(R) 500x CPU @ 1.2GHz";
710 std::map<std::string, std::string> params;
711 params.insert(std::make_pair("PerfCommand::default::0", "perf command"));
712 params.insert(std::make_pair("PerfCommand::x86_64::0", "perf command"));
713 params.insert(std::make_pair("PerfCommand::Broadwell::0", "perf command"));
714 params.insert(std::make_pair("PerfCommand::model-500x::0",
715 "perf command"));
716 params.insert(std::make_pair("PerfCommand::interesting-model-500x::0",
717 "perf command"));
718 params.insert(std::make_pair("PerfCommand::interesting-model::0",
719 "perf command"));
720
721 EXPECT_EQ("interesting-model-500x",
722 internal::FindBestCpuSpecifierFromParams(params, cpuid));
723 }
724
725 class PerfProviderCollectionParamsTest : public testing::Test {
726 public:
727 PerfProviderCollectionParamsTest()
728 : task_runner_(new base::TestSimpleTaskRunner),
729 task_runner_handle_(task_runner_),
730 field_trial_list_(nullptr) {}
731
732 void SetUp() override {
733 // PerfProvider requires chromeos::LoginState and
734 // chromeos::DBusThreadManagerto be initialized.
735 chromeos::LoginState::Initialize();
736 chromeos::DBusThreadManager::Initialize();
737
738 // PerfProvider requires the user to be logged in.
739 chromeos::LoginState::Get()->SetLoggedInState(
740 chromeos::LoginState::LOGGED_IN_ACTIVE,
741 chromeos::LoginState::LOGGED_IN_USER_REGULAR);
742 }
743
744 void TearDown() override {
745 chromeos::DBusThreadManager::Shutdown();
746 chromeos::LoginState::Shutdown();
747 variations::testing::ClearAllVariationParams();
748 }
749
750 private:
751 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
752 base::ThreadTaskRunnerHandle task_runner_handle_;
753 base::FieldTrialList field_trial_list_;
754
755 DISALLOW_COPY_AND_ASSIGN(PerfProviderCollectionParamsTest);
756 };
757
758 TEST_F(PerfProviderCollectionParamsTest, Commands_EmptyExperiment) {
759 std::vector<RandomSelector::WeightAndValue> default_cmds =
760 internal::GetDefaultCommandsForCpu(GetCPUIdentity());
761 std::map<std::string, std::string> params;
762 ASSERT_TRUE(variations::AssociateVariationParams(
763 "ChromeOSWideProfilingCollection", "group_name", params));
764 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
765 "ChromeOSWideProfilingCollection", "group_name"));
766
767 TestPerfProvider perf_provider;
768 EXPECT_EQ(default_cmds, perf_provider.command_selector().odds());
769 }
770
771 TEST_F(PerfProviderCollectionParamsTest, Commands_InvalidValues) {
772 std::vector<RandomSelector::WeightAndValue> default_cmds =
773 internal::GetDefaultCommandsForCpu(GetCPUIdentity());
774 std::map<std::string, std::string> params;
775 // Use the "default" cpu specifier since we don't want to predict what CPU
776 // this test is running on. (CPU detection is tested above.)
777 params.insert(std::make_pair("PerfCommand::default::0", ""));
778 params.insert(std::make_pair("PerfCommand::default::1", " "));
779 params.insert(std::make_pair("PerfCommand::default::2", " leading space"));
780 params.insert(std::make_pair("PerfCommand::default::3",
781 "no-spaces-or-numbers"));
782 params.insert(std::make_pair("PerfCommand::default::4",
783 "NaN-trailing-space "));
784 params.insert(std::make_pair("PerfCommand::default::5", "NaN x"));
785 params.insert(std::make_pair("PerfCommand::default::6", "perf command"));
786 ASSERT_TRUE(variations::AssociateVariationParams(
787 "ChromeOSWideProfilingCollection", "group_name", params));
788 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
789 "ChromeOSWideProfilingCollection", "group_name"));
790
791 TestPerfProvider perf_provider;
792 EXPECT_EQ(default_cmds, perf_provider.command_selector().odds());
793 }
794
795 TEST_F(PerfProviderCollectionParamsTest, Commands_Override) {
796 using WeightAndValue = RandomSelector::WeightAndValue;
797 std::vector<RandomSelector::WeightAndValue> default_cmds =
798 internal::GetDefaultCommandsForCpu(GetCPUIdentity());
799 std::map<std::string, std::string> params;
800 // Use the "default" cpu specifier since we don't want to predict what CPU
801 // this test is running on. (CPU detection is tested above.)
802 params.insert(std::make_pair("PerfCommand::default::0",
803 "50 perf record foo"));
804 params.insert(std::make_pair("PerfCommand::default::1",
805 "25 perf record bar"));
806 params.insert(std::make_pair("PerfCommand::default::2",
807 "25 perf record baz"));
808 params.insert(std::make_pair("PerfCommand::another-cpu::0",
809 "7 perf record bar"));
810 ASSERT_TRUE(variations::AssociateVariationParams(
811 "ChromeOSWideProfilingCollection", "group_name", params));
812 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
813 "ChromeOSWideProfilingCollection", "group_name"));
814
815 TestPerfProvider perf_provider;
816
817 std::vector<WeightAndValue> expected_cmds;
818 expected_cmds.push_back(WeightAndValue(50.0, "perf record foo"));
819 expected_cmds.push_back(WeightAndValue(25.0, "perf record bar"));
820 expected_cmds.push_back(WeightAndValue(25.0, "perf record baz"));
821
822 EXPECT_EQ(expected_cmds, perf_provider.command_selector().odds());
823 }
824
825 TEST_F(PerfProviderCollectionParamsTest, Parameters_Override) {
826 std::map<std::string, std::string> params;
827 params.insert(std::make_pair("ProfileCollectionDurationSec", "15"));
828 params.insert(std::make_pair("PeriodicProfilingIntervalMs", "3600000"));
829 params.insert(std::make_pair("ResumeFromSuspend::SamplingFactor", "1"));
830 params.insert(std::make_pair("ResumeFromSuspend::MaxDelaySec", "10"));
831 params.insert(std::make_pair("RestoreSession::SamplingFactor", "2"));
832 params.insert(std::make_pair("RestoreSession::MaxDelaySec", "20"));
833 ASSERT_TRUE(variations::AssociateVariationParams(
834 "ChromeOSWideProfilingCollection", "group_name", params));
835 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
836 "ChromeOSWideProfilingCollection", "group_name"));
837
838 TestPerfProvider perf_provider;
839
840 const auto& parsed_params = perf_provider.collection_params();
841 EXPECT_EQ(base::TimeDelta::FromSeconds(15),
842 parsed_params.collection_duration());
843 EXPECT_EQ(base::TimeDelta::FromHours(1),
844 parsed_params.periodic_interval());
845 EXPECT_EQ(1, parsed_params.resume_from_suspend().sampling_factor());
846 EXPECT_EQ(base::TimeDelta::FromSeconds(10),
847 parsed_params.resume_from_suspend().max_collection_delay());
848 EXPECT_EQ(2, parsed_params.restore_session().sampling_factor());
849 EXPECT_EQ(base::TimeDelta::FromSeconds(20),
850 parsed_params.restore_session().max_collection_delay());
851 }
852
585 } // namespace metrics 853 } // namespace metrics
OLDNEW
« no previous file with comments | « chrome/browser/metrics/perf/perf_provider_chromeos.cc ('k') | chrome/browser/metrics/perf/random_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698