Commit 4c4b5b1f authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Factor out platform config 3/4

Third in a series factoring the ThreadProfiler platform specific
configuration state from the code that takes action on the state. Defines
a GetEnabledRate function that returns how frequently the profiler should
be enabled overall, in support of a synthetic experiment.

The end goal is to reduce the configuration complexity, to support
enabling per-thread on Android.

Bug: 1129939
Change-Id: Ib0b23e2c56ff45644c521157789bbf1c1dc64261
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424671
Commit-Queue: Mike Wittman <wittman@chromium.org>
Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811741}
parent 9c44604f
......@@ -232,20 +232,18 @@ ThreadProfilerConfiguration::GenerateConfiguration(
break;
}
switch (chrome::GetChannel()) {
// Enable the profiler unconditionally for development/waterfall builds.
case version_info::Channel::UNKNOWN:
return PROFILE_ENABLED;
#if (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) || defined(OS_MAC)
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
return ChooseConfiguration({{PROFILE_ENABLED, 80},
{PROFILE_CONTROL, 10},
{PROFILE_DISABLED, 10}});
#endif
default:
return PROFILE_DISABLED;
ThreadProfilerPlatformConfiguration::RelativePopulations
relative_populations = platform_configuration.GetEnableRates(
BUILDFLAG(GOOGLE_CHROME_BRANDING), channel);
if (relative_populations.enabled == 0 &&
relative_populations.experiment == 0) {
return PROFILE_DISABLED;
}
CHECK_EQ(0, relative_populations.experiment % 2);
return ChooseConfiguration({
{PROFILE_ENABLED, relative_populations.enabled},
{PROFILE_CONTROL, relative_populations.experiment / 2},
{PROFILE_DISABLED, relative_populations.experiment / 2},
});
}
......@@ -27,6 +27,10 @@ class DefaultPlatformConfiguration
bool is_chrome_branded,
version_info::Channel channel) const override;
RelativePopulations GetEnableRates(
bool is_chrome_branded,
version_info::Channel channel) const override;
protected:
bool IsSupportedForChannel(bool is_chrome_branded,
version_info::Channel channel) const override;
......@@ -48,6 +52,26 @@ DefaultPlatformConfiguration::GetRuntimeModuleState(
return RuntimeModuleState::kModuleNotRequired;
}
ThreadProfilerPlatformConfiguration::RelativePopulations
DefaultPlatformConfiguration::GetEnableRates(
bool is_chrome_branded,
version_info::Channel channel) const {
// TODO(https://crbug.com/1129939): Make this logic consistent with
// IsSupportedForChannel() for identifying local/CQ builds.
switch (channel) {
// Enable the profiler unconditionally for development/waterfall builds.
case version_info::Channel::UNKNOWN:
return RelativePopulations{100, 0};
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
return RelativePopulations{80, 20};
default:
return RelativePopulations{0, 0};
}
}
bool DefaultPlatformConfiguration::IsSupportedForChannel(
bool is_chrome_branded,
version_info::Channel channel) const {
......
......@@ -36,6 +36,17 @@ class ThreadProfilerPlatformConfiguration {
kModuleNotAvailable, // A module is necessary but not available.
};
// The relative populations to use for enabling/disabling the profiler.
// |enabled| + |experiment| is expected to equal 100. Profiling is to be
// enabled with probability |enabled|/100. The fraction |experiment|/100 is to
// be split in to two equal-sized experiment groups with probability
// |experiment|/(2 * 100), one of which will be enabled and one disabled. As a
// special case {0, 0} means always disable.
struct RelativePopulations {
int enabled;
int experiment;
};
virtual ~ThreadProfilerPlatformConfiguration() = default;
// Create the platform configuration.
......@@ -57,6 +68,13 @@ class ThreadProfilerPlatformConfiguration {
// GetRuntimeModuleState() returns kModuleAbsentButAvailable.
virtual void RequestRuntimeModuleInstall() const {}
// Returns the relative population disposition for the channel/chrome branding
// on the platform. See the documentation on RelativePopulations. Enable rates
// are valid only if IsSupported().
virtual RelativePopulations GetEnableRates(
bool is_chrome_branded,
version_info::Channel channel) const = 0;
protected:
// True if the profiler is to be run for the channel/chrome branding on the
// platform. Does not need to check whether the StackSamplingProfiler is
......
......@@ -17,6 +17,14 @@
#define THREAD_PROFILER_SUPPORTED_ON_PLATFORM false
#endif
#if THREAD_PROFILER_SUPPORTED_ON_PLATFORM
#define MAYBE_PLATFORM_CONFIG_TEST_F(suite, test) TEST_F(suite, test)
#else
#define MAYBE_PLATFORM_CONFIG_TEST_F(suite, test) TEST_F(suite, DISABLED_##test)
#endif
namespace {
class ThreadProfilerPlatformConfigurationTest : public ::testing::Test {
public:
// The browser_test_mode_enabled=true scenario is already covered by the
......@@ -33,11 +41,22 @@ class ThreadProfilerPlatformConfigurationTest : public ::testing::Test {
const std::unique_ptr<ThreadProfilerPlatformConfiguration> config_;
};
#if THREAD_PROFILER_SUPPORTED_ON_PLATFORM
#define MAYBE_PLATFORM_CONFIG_TEST_F(suite, test) TEST_F(suite, test)
#else
#define MAYBE_PLATFORM_CONFIG_TEST_F(suite, test) TEST_F(suite, DISABLED_##test)
#endif
} // namespace
// Glue functions to make RelativePopulations work with googletest.
std::ostream& operator<<(
std::ostream& strm,
const ThreadProfilerPlatformConfiguration::RelativePopulations&
populations) {
return strm << "{" << populations.enabled << ", " << populations.experiment
<< "}";
}
bool operator==(
const ThreadProfilerPlatformConfiguration::RelativePopulations& a,
const ThreadProfilerPlatformConfiguration::RelativePopulations& b) {
return a.enabled == b.enabled && a.experiment == b.experiment;
}
TEST_F(ThreadProfilerPlatformConfigurationTest, IsSupported) {
#if !THREAD_PROFILER_SUPPORTED_ON_PLATFORM
......@@ -131,3 +150,28 @@ MAYBE_PLATFORM_CONFIG_TEST_F(ThreadProfilerPlatformConfigurationTest,
version_info::Channel::UNKNOWN));
#endif
}
MAYBE_PLATFORM_CONFIG_TEST_F(ThreadProfilerPlatformConfigurationTest,
GetEnableRates) {
using RelativePopulations =
ThreadProfilerPlatformConfiguration::RelativePopulations;
EXPECT_EQ((RelativePopulations{100, 0}),
config()->GetEnableRates(/*is_chrome_branded=*/true,
version_info::Channel::UNKNOWN));
EXPECT_EQ((RelativePopulations{80, 20}),
config()->GetEnableRates(/*is_chrome_branded=*/true,
version_info::Channel::CANARY));
EXPECT_EQ((RelativePopulations{80, 20}),
config()->GetEnableRates(/*is_chrome_branded=*/true,
version_info::Channel::DEV));
EXPECT_EQ((RelativePopulations{0, 0}),
config()->GetEnableRates(/*is_chrome_branded=*/true,
version_info::Channel::BETA));
EXPECT_EQ((RelativePopulations{0, 0}),
config()->GetEnableRates(/*is_chrome_branded=*/true,
version_info::Channel::STABLE));
EXPECT_EQ((RelativePopulations{100, 0}),
config()->GetEnableRates(/*is_chrome_branded=*/true,
version_info::Channel::UNKNOWN));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment