| Index: chrome/browser/metrics/perf/perf_provider_chromeos_unittest.cc
|
| diff --git a/chrome/browser/metrics/perf/perf_provider_chromeos_unittest.cc b/chrome/browser/metrics/perf/perf_provider_chromeos_unittest.cc
|
| index 7bf1be53007c1e6760479a793cca410a275f6eee..73df6494d280623ca9cd1aeaffc8dd4b3746a3a4 100644
|
| --- a/chrome/browser/metrics/perf/perf_provider_chromeos_unittest.cc
|
| +++ b/chrome/browser/metrics/perf/perf_provider_chromeos_unittest.cc
|
| @@ -9,12 +9,14 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/metrics/field_trial.h"
|
| #include "base/test/test_simple_task_runner.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "chrome/browser/metrics/perf/windowed_incognito_observer.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| #include "chromeos/login/login_state.h"
|
| #include "components/metrics/proto/sampled_profile.pb.h"
|
| +#include "components/variations/variations_associated_data.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace metrics {
|
| @@ -120,12 +122,14 @@ class TestIncognitoObserver : public WindowedIncognitoObserver {
|
| DISALLOW_COPY_AND_ASSIGN(TestIncognitoObserver);
|
| };
|
|
|
| -// Allows access to PerfProvider::ParseOutputProtoIfValid() for testing.
|
| +// Allows access to some private methods for testing.
|
| class TestPerfProvider : public PerfProvider {
|
| public:
|
| TestPerfProvider() {}
|
|
|
| using PerfProvider::ParseOutputProtoIfValid;
|
| + using PerfProvider::collection_params;
|
| + using PerfProvider::command_selector;
|
|
|
| private:
|
| std::vector<SampledProfile> stored_profiles_;
|
| @@ -582,4 +586,251 @@ TEST_F(PerfProviderTest, DefaultCommandsBasedOnArch_Unknown) {
|
| EXPECT_EQ(cmds[0].value, kPerfRecordCyclesCmd);
|
| }
|
|
|
| +TEST_F(PerfProviderTest, CommandMatching_Empty) {
|
| + CPUIdentity cpuid = {};
|
| + std::map<std::string, std::string> params;
|
| + EXPECT_EQ("", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +TEST_F(PerfProviderTest, CommandMatching_NoPerfCommands) {
|
| + CPUIdentity cpuid = {};
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("NotEvenClose", ""));
|
| + params.insert(param_t("NotAPerfCommand", ""));
|
| + params.insert(param_t("NotAPerfCommand::Really", ""));
|
| + params.insert(param_t("NotAPerfCommand::Nope::0", ""));
|
| + params.insert(param_t("PerfCommands::SoClose::0", ""));
|
| + EXPECT_EQ("", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +TEST_F(PerfProviderTest, CommandMatching_NoMatch) {
|
| + CPUIdentity cpuid;
|
| + cpuid.arch = "x86_64";
|
| + cpuid.vendor = "GenuineIntel";
|
| + cpuid.family = 6;
|
| + cpuid.model = 0x3a; // IvyBridge
|
| + cpuid.model_name = "Xeon or somesuch";
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("PerfCommand::armv7l::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86::1", "perf command"));
|
| + params.insert(param_t("PerfCommand::Broadwell::0", "perf command"));
|
| +
|
| + EXPECT_EQ("", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +TEST_F(PerfProviderTest, CommandMatching_default) {
|
| + CPUIdentity cpuid;
|
| + cpuid.arch = "x86_64";
|
| + cpuid.vendor = "GenuineIntel";
|
| + cpuid.family = 6;
|
| + cpuid.model = 0x3a; // IvyBridge
|
| + cpuid.model_name = "Xeon or somesuch";
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("PerfCommand::default::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::armv7l::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86::1", "perf command"));
|
| + params.insert(param_t("PerfCommand::Broadwell::0", "perf command"));
|
| +
|
| + EXPECT_EQ("default", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +TEST_F(PerfProviderTest, CommandMatching_SystemArch) {
|
| + CPUIdentity cpuid;
|
| + cpuid.arch = "nothing_in_particular";
|
| + cpuid.vendor = "";
|
| + cpuid.family = 0;
|
| + cpuid.model = 0;
|
| + cpuid.model_name = "";
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("PerfCommand::default::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::armv7l::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86::1", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86_64::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86_64::xyz#$%", "perf command"));
|
| + params.insert(param_t("PerfCommand::Broadwell::0", "perf command"));
|
| +
|
| + EXPECT_EQ("default", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +
|
| + cpuid.arch = "armv7l";
|
| + EXPECT_EQ("armv7l", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +
|
| + cpuid.arch = "x86";
|
| + EXPECT_EQ("x86", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +
|
| + cpuid.arch = "x86_64";
|
| + EXPECT_EQ("x86_64", internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +TEST_F(PerfProviderTest, CommandMatching_Microarchitecture) {
|
| + CPUIdentity cpuid;
|
| + cpuid.arch = "x86_64";
|
| + cpuid.vendor = "GenuineIntel";
|
| + cpuid.family = 6;
|
| + cpuid.model = 0x3D; // Broadwell
|
| + cpuid.model_name = "Wrong Model CPU @ 0 Hz";
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("PerfCommand::default::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86_64::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::Broadwell::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::interesting-model-500x::0",
|
| + "perf command"));
|
| +
|
| + EXPECT_EQ("Broadwell",
|
| + internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +TEST_F(PerfProviderTest, CommandMatching_SpecificModel) {
|
| + CPUIdentity cpuid;
|
| + cpuid.arch = "x86_64";
|
| + cpuid.vendor = "GenuineIntel";
|
| + cpuid.family = 6;
|
| + cpuid.model = 0x3D; // Broadwell
|
| + cpuid.model_name = "An Interesting(R) Model(R) 500x CPU @ 1.2GHz";
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("PerfCommand::default::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::x86_64::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::Broadwell::0", "perf command"));
|
| + params.insert(param_t("PerfCommand::interesting-model-500x::0",
|
| + "perf command"));
|
| +
|
| + EXPECT_EQ("interesting-model-500x",
|
| + internal::FindBestCpuSpecifierFromParams(params, cpuid));
|
| +}
|
| +
|
| +
|
| +class PerfProviderCollectionParamsTest : public testing::Test {
|
| + public:
|
| + PerfProviderCollectionParamsTest()
|
| + : task_runner_(new base::TestSimpleTaskRunner),
|
| + task_runner_handle_(task_runner_),
|
| + field_trial_list_(nullptr) {}
|
| +
|
| + void SetUp() override {
|
| + // PerfProvider requires chromeos::LoginState and
|
| + // chromeos::DBusThreadManagerto be initialized.
|
| + chromeos::LoginState::Initialize();
|
| + chromeos::DBusThreadManager::Initialize();
|
| +
|
| + // PerfProvider requires the user to be logged in.
|
| + chromeos::LoginState::Get()->SetLoggedInState(
|
| + chromeos::LoginState::LOGGED_IN_ACTIVE,
|
| + chromeos::LoginState::LOGGED_IN_USER_REGULAR);
|
| + }
|
| +
|
| + void TearDown() override {
|
| + perf_provider_.reset();
|
| + chromeos::DBusThreadManager::Shutdown();
|
| + chromeos::LoginState::Shutdown();
|
| + variations::testing::ClearAllVariationParams();
|
| + }
|
| +
|
| + protected:
|
| + scoped_ptr<TestPerfProvider> perf_provider_;
|
| +
|
| + scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
|
| + base::ThreadTaskRunnerHandle task_runner_handle_;
|
| + base::FieldTrialList field_trial_list_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PerfProviderCollectionParamsTest);
|
| +};
|
| +
|
| +TEST_F(PerfProviderCollectionParamsTest, Commands_EmptyExperiment) {
|
| + std::vector<RandomSelector::WeightAndValue> default_cmds =
|
| + internal::GetDefaultCommandsForCpu(GetCPUIdentity());
|
| + std::map<std::string, std::string> params;
|
| + ASSERT_TRUE(variations::AssociateVariationParams(
|
| + "ChromeOSWideProfilingCollection", "group_name", params));
|
| + ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
|
| + "ChromeOSWideProfilingCollection", "group_name"));
|
| + perf_provider_.reset(new TestPerfProvider);
|
| +
|
| + EXPECT_EQ(default_cmds, perf_provider_->command_selector().odds());
|
| +}
|
| +
|
| +TEST_F(PerfProviderCollectionParamsTest, Commands_InvalidValues) {
|
| + std::vector<RandomSelector::WeightAndValue> default_cmds =
|
| + internal::GetDefaultCommandsForCpu(GetCPUIdentity());
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + // Use the "default" cpu specifier since we don't want to predict what CPU
|
| + // this test is running on. (CPU detection is tested above.)
|
| + params.insert(param_t("PerfCommand::default::0", ""));
|
| + params.insert(param_t("PerfCommand::default::1", " "));
|
| + params.insert(param_t("PerfCommand::default::2", " leading space"));
|
| + params.insert(param_t("PerfCommand::default::3", "no-spaces-or-numbers"));
|
| + params.insert(param_t("PerfCommand::default::4", "NaN-trailing-space "));
|
| + params.insert(param_t("PerfCommand::default::5", "NaN x"));
|
| + params.insert(param_t("PerfCommand::default::6", "perf command"));
|
| + ASSERT_TRUE(variations::AssociateVariationParams(
|
| + "ChromeOSWideProfilingCollection", "group_name", params));
|
| + ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
|
| + "ChromeOSWideProfilingCollection", "group_name"));
|
| + perf_provider_.reset(new TestPerfProvider);
|
| +
|
| + EXPECT_EQ(default_cmds, perf_provider_->command_selector().odds());
|
| +}
|
| +
|
| +TEST_F(PerfProviderCollectionParamsTest, Commands_Override) {
|
| + using WeightAndValue = RandomSelector::WeightAndValue;
|
| + std::vector<RandomSelector::WeightAndValue> default_cmds =
|
| + internal::GetDefaultCommandsForCpu(GetCPUIdentity());
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + // Use the "default" cpu specifier since we don't want to predict what CPU
|
| + // this test is running on. (CPU detection is tested above.)
|
| + params.insert(param_t("PerfCommand::default::0", "50 perf record foo"));
|
| + params.insert(param_t("PerfCommand::default::1", "25 perf record bar"));
|
| + params.insert(param_t("PerfCommand::default::2", "25 perf record baz"));
|
| + params.insert(param_t("PerfCommand::another-cpu::0", "7 perf record bar"));
|
| + ASSERT_TRUE(variations::AssociateVariationParams(
|
| + "ChromeOSWideProfilingCollection", "group_name", params));
|
| + ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
|
| + "ChromeOSWideProfilingCollection", "group_name"));
|
| + perf_provider_.reset(new TestPerfProvider);
|
| +
|
| + std::vector<WeightAndValue> expected_cmds;
|
| + expected_cmds.push_back(WeightAndValue(50.0, "perf record foo"));
|
| + expected_cmds.push_back(WeightAndValue(25.0, "perf record bar"));
|
| + expected_cmds.push_back(WeightAndValue(25.0, "perf record baz"));
|
| +
|
| + EXPECT_EQ(expected_cmds, perf_provider_->command_selector().odds());
|
| +}
|
| +
|
| +TEST_F(PerfProviderCollectionParamsTest, Parameters_Override) {
|
| + std::map<std::string, std::string> params;
|
| + using param_t = decltype(params)::value_type;
|
| + params.insert(param_t("ProfileCollectionDurationSec", "15"));
|
| + params.insert(param_t("PeriodicProfilingIntervalMs","3600000"));
|
| + params.insert(param_t("ResumeFromSuspend::SamplingFactor","1"));
|
| + params.insert(param_t("ResumeFromSuspend::MaxCollectionDelaySec","10"));
|
| + params.insert(param_t("RestoreSession::SamplingFactor","2"));
|
| + params.insert(param_t("RestoreSession::MaxCollectionDelaySec","20"));
|
| + ASSERT_TRUE(variations::AssociateVariationParams(
|
| + "ChromeOSWideProfilingCollection", "group_name", params));
|
| + ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
|
| + "ChromeOSWideProfilingCollection", "group_name"));
|
| + perf_provider_.reset(new TestPerfProvider);
|
| +
|
| + const auto& parsed_params = perf_provider_->collection_params();
|
| + EXPECT_EQ(base::TimeDelta::FromSeconds(15),
|
| + parsed_params.collection_duration());
|
| + EXPECT_EQ(base::TimeDelta::FromHours(1),
|
| + parsed_params.periodic_interval());
|
| + EXPECT_EQ(1, parsed_params.resume_from_suspend().sampling_factor());
|
| + EXPECT_EQ(base::TimeDelta::FromSeconds(10),
|
| + parsed_params.resume_from_suspend().max_collection_delay());
|
| + EXPECT_EQ(2, parsed_params.restore_session().sampling_factor());
|
| + EXPECT_EQ(base::TimeDelta::FromSeconds(20),
|
| + parsed_params.restore_session().max_collection_delay());
|
| +}
|
| +
|
| } // namespace metrics
|
|
|