Skip to content

Commit

Permalink
Log histogram for CBX scope level
Browse files Browse the repository at this point in the history
In addition to commit baa865c ("Log histogram for feature level.")
Propagate the scope_level flag to UMA for filtering.
See crrev.com/c/4917184.

--gtest_filter='*/ChromeOSHistogramMetricsProvider.*'

(cherry picked from commit e79a4ee)

Bug: 283127211
Test: out/Default/components_unittests
Change-Id: I7a1925390ff771765074c4a1d4e6354f293080fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4915887
Reviewed-by: Mark Pearson <mpearson@chromium.org>
Auto-Submit: Gwendal Grignou <gwendal@chromium.org>
Commit-Queue: Gwendal Grignou <gwendal@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1208308}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4932462
Reviewed-by: Steven Holte <holte@chromium.org>
Cr-Commit-Position: refs/branch-heads/5993@{#1305}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
gwendalcr authored and Chromium LUCI CQ committed Oct 16, 2023
1 parent e352826 commit 4134b85
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 10 deletions.
44 changes: 38 additions & 6 deletions chrome/browser/metrics/chromeos_metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ inline constexpr char kFeatureManagementLevelFlag[] =
"feature-management-level";
inline constexpr char kFeatureManagementMaxLevelFlag[] =
"feature-management-max-level";
inline constexpr char kFeatureManagementScopeFlag[] =
"feature-management-scope";

void IncrementPrefValue(const char* path, int num_samples) {
PrefService* pref = g_browser_process->local_state();
Expand Down Expand Up @@ -261,34 +263,64 @@ ChromeOSHistogramMetricsProvider::ChromeOSHistogramMetricsProvider() = default;
ChromeOSHistogramMetricsProvider::~ChromeOSHistogramMetricsProvider() = default;

bool ChromeOSHistogramMetricsProvider::ProvideHistograms() {
// The scope type. Used in a histogram; do not modify existing types.
// see histograms/enums.xml.
enum {
FEATURE_MANAGEMENT_REGULAR = 0,
FEATURE_MANAGEMENT_SOFT_BRANDED = 1,
FEATURE_MANAGEMENT_HARD_BRANDED = 2,
kMaxValue = FEATURE_MANAGEMENT_HARD_BRANDED
} scope_level;

if (!base::CommandLine::InitializedForCurrentProcess()) {
return false;
}

base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(kFeatureManagementLevelFlag) ||
!command_line->HasSwitch(kFeatureManagementMaxLevelFlag)) {
!command_line->HasSwitch(kFeatureManagementMaxLevelFlag) ||
!command_line->HasSwitch(kFeatureManagementScopeFlag)) {
return false;
}
int feature_level = -1;
int feature_max_level = -1;
int scope_level_raw = -1;
if (!base::StringToInt(
command_line->GetSwitchValueASCII(kFeatureManagementLevelFlag),
&feature_level) ||
!base::StringToInt(
command_line->GetSwitchValueASCII(kFeatureManagementMaxLevelFlag),
&feature_max_level)) {
&feature_max_level) ||
!base::StringToInt(
command_line->GetSwitchValueASCII(kFeatureManagementScopeFlag),
&scope_level_raw)) {
return false;
}
if (feature_level < 0 || feature_max_level < 0 ||
if (feature_level < 0 || feature_max_level < 0 || scope_level_raw < 0 ||
feature_max_level < feature_level) {
LOG(ERROR) << "Invalid " << kFeatureManagementLevelFlag << " ("
<< feature_level << ") or " << kFeatureManagementMaxLevelFlag
<< " (" << feature_max_level << ")";
LOG(ERROR) << "Invalid FeatureLevel arguments: "
<< kFeatureManagementLevelFlag << " (" << feature_level
<< ") or " << kFeatureManagementMaxLevelFlag << " ("
<< feature_max_level << ") or " << kFeatureManagementScopeFlag
<< " (" << scope_level_raw << ")";
return false;
}
if (feature_level == 0 && scope_level_raw == 0) {
scope_level = FEATURE_MANAGEMENT_REGULAR;
} else if (feature_level > 0 && scope_level_raw == 0) {
scope_level = FEATURE_MANAGEMENT_SOFT_BRANDED;
} else if (feature_level > 0 && scope_level_raw == 1) {
scope_level = FEATURE_MANAGEMENT_HARD_BRANDED;
} else {
LOG(ERROR) << "Invalid ScopeLevel:" << kFeatureManagementLevelFlag << " ("
<< feature_level << ") or " << kFeatureManagementScopeFlag
<< " (" << scope_level_raw << ")";
return false;
}

base::UmaHistogramExactLinear("Platform.Segmentation.FeatureLevel",
feature_level, feature_max_level + 1);
base::UmaHistogramEnumeration("Platform.Segmentation.ScopeLevel",
scope_level);
return true;
}
55 changes: 51 additions & 4 deletions chrome/browser/metrics/chromeos_metrics_provider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TEST(ChromeOSHistogramMetricsProvider, NoCommandLine) {
ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_OnlyOne) {
Expand All @@ -27,6 +28,7 @@ TEST(ChromeOSHistogramMetricsProvider, CommandLine_OnlyOne) {
ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_NotInts) {
Expand All @@ -36,10 +38,12 @@ TEST(ChromeOSHistogramMetricsProvider, CommandLine_NotInts) {
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "s");
command_line->AppendSwitchASCII("feature-management-max-level", "t");
command_line->AppendSwitchASCII("feature-management-scope", "u");

ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_OnlyOneInt) {
Expand All @@ -49,10 +53,12 @@ TEST(ChromeOSHistogramMetricsProvider, CommandLine_OnlyOneInt) {
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "1");
command_line->AppendSwitchASCII("feature-management-max-level", "t");
command_line->AppendSwitchASCII("feature-management-scope", "0");

ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_Invalid_Level) {
Expand All @@ -62,10 +68,12 @@ TEST(ChromeOSHistogramMetricsProvider, CommandLine_Invalid_Level) {
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "-1");
command_line->AppendSwitchASCII("feature-management-max-level", "1");
command_line->AppendSwitchASCII("feature-management-scope", "0");

ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_Negative_MaxLevel) {
Expand All @@ -75,10 +83,12 @@ TEST(ChromeOSHistogramMetricsProvider, CommandLine_Negative_MaxLevel) {
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "1");
command_line->AppendSwitchASCII("feature-management-max-level", "-1");
command_line->AppendSwitchASCII("feature-management-scope", "0");

ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_Small_MaxLevel) {
Expand All @@ -88,37 +98,74 @@ TEST(ChromeOSHistogramMetricsProvider, CommandLine_Small_MaxLevel) {
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "1");
command_line->AppendSwitchASCII("feature-management-max-level", "0");
command_line->AppendSwitchASCII("feature-management-scope", "0");

ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_Success) {
TEST(ChromeOSHistogramMetricsProvider, CommandLine_Success_NonCBX) {
base::HistogramTester histogram_tester;

base::test::ScopedCommandLine scoped_command_line;
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "0");
command_line->AppendSwitchASCII("feature-management-max-level", "1");
command_line->AppendSwitchASCII("feature-management-scope", "0");

ChromeOSHistogramMetricsProvider provider;
EXPECT_TRUE(provider.ProvideHistograms());
histogram_tester.ExpectUniqueSample("Platform.Segmentation.FeatureLevel", 0,
1);
histogram_tester.ExpectUniqueSample("Platform.Segmentation.ScopeLevel", 0, 1);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_Success_HB) {
base::HistogramTester histogram_tester;

base::test::ScopedCommandLine scoped_command_line;
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "1");
command_line->AppendSwitchASCII("feature-management-max-level", "1");
command_line->AppendSwitchASCII("feature-management-scope", "1");

ChromeOSHistogramMetricsProvider provider;
EXPECT_TRUE(provider.ProvideHistograms());
histogram_tester.ExpectUniqueSample("Platform.Segmentation.FeatureLevel", 1,
1);
histogram_tester.ExpectUniqueSample("Platform.Segmentation.ScopeLevel", 2, 1);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_Success_DifferentValues) {
TEST(ChromeOSHistogramMetricsProvider, CommandLine_Success_SB) {
base::HistogramTester histogram_tester;

base::test::ScopedCommandLine scoped_command_line;
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "0");
command_line->AppendSwitchASCII("feature-management-level", "1");
command_line->AppendSwitchASCII("feature-management-max-level", "1");
command_line->AppendSwitchASCII("feature-management-scope", "0");

ChromeOSHistogramMetricsProvider provider;
EXPECT_TRUE(provider.ProvideHistograms());
histogram_tester.ExpectUniqueSample("Platform.Segmentation.FeatureLevel", 0,
histogram_tester.ExpectUniqueSample("Platform.Segmentation.FeatureLevel", 1,
1);
histogram_tester.ExpectUniqueSample("Platform.Segmentation.ScopeLevel", 1, 1);
}

TEST(ChromeOSHistogramMetricsProvider, CommandLine_NonCBX_Hardbranded) {
base::HistogramTester histogram_tester;

base::test::ScopedCommandLine scoped_command_line;
base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine();
command_line->AppendSwitchASCII("feature-management-level", "0");
command_line->AppendSwitchASCII("feature-management-max-level", "1");
command_line->AppendSwitchASCII("feature-management-scope", "1");

ChromeOSHistogramMetricsProvider provider;
EXPECT_FALSE(provider.ProvideHistograms());
histogram_tester.ExpectTotalCount("Platform.Segmentation.FeatureLevel", 0);
histogram_tester.ExpectTotalCount("Platform.Segmentation.ScopeLevel", 0);
}
} // namespace
10 changes: 10 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39065,6 +39065,16 @@ Called by update_extension_permission.py.-->
<int value="2" label="Grace period is not over"/>
</enum>

<enum name="FeatureManagementScopeLevel">
<int value="0" label="Regular">Device is a regular Chromebook.</int>
<int value="1" label="Soft Braned">
Device is a Soft Branded Chromebook Plus.
</int>
<int value="2" label="Hard Braned">
Device is a Hard Branded Chromebook Plus.
</int>
</enum>

<enum name="FeatureModuleAvailabilityStatus">
<int value="0" label="Requested">
Feature module has been requested but is not installed yet.
Expand Down
15 changes: 15 additions & 0 deletions tools/metrics/histograms/metadata/platform/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@ chromium-metrics-reviews@google.com.

<histogram name="Platform.Segmentation.FeatureLevel" units="level number"
expires_after="2024-08-09">
<owner>gwendal@chromium.org</owner>
<owner>mutexlox@chromium.org</owner>
<owner>iby@chromium.org</owner>
<owner>cros-telemetry@google.com</owner>
Expand All @@ -1640,6 +1641,20 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Platform.Segmentation.ScopeLevel"
enum="FeatureManagementScopeLevel" expires_after="2024-08-09">
<owner>gwendal@chromium.org</owner>
<owner>mutexlox@chromium.org</owner>
<owner>iby@chromium.org</owner>
<owner>cros-telemetry@google.com</owner>
<summary>
Records the scope level of the device (Soft vs Hard Branded). Recorded in
every UMA upload.

See libsegmentation in platform2 for context.
</summary>
</histogram>

<histogram name="Platform.SmartTransferErrors" units="units"
expires_after="2024-01-14">
<owner>gwendal@google.com</owner>
Expand Down

0 comments on commit 4134b85

Please sign in to comment.