0

Remove HistogramBase::Count type.

Rename HistogramBase::Count type to Count32. Add size to type name so the size is known without needing to lookup
the typedef.

Changed occurrences under chrome/browser

Bug: 40899968
Change-Id: I6adbf538517263bf65ba6d945aacb3e0e7035ffb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6190699
Commit-Queue: Ramon Cano Aparicio <rcanoaparicio@google.com>
Reviewed-by: David Roger <droger@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Owners-Override: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1410869}
This commit is contained in:
Ramon Cano Aparicio
2025-01-24 05:45:06 -08:00
committed by Chromium LUCI CQ
parent a86ea58512
commit 1a549ea7c9
19 changed files with 60 additions and 63 deletions

@ -907,12 +907,12 @@ TEST_F(AcceleratorControllerTestWithClamshellSplitView, WindowSnapUma) {
// so overview will be nonempty. Otherwise split view will end when it starts.
std::unique_ptr<aura::Window> window2(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
base::HistogramBase::Count left_clamshell_no_overview = 0;
base::HistogramBase::Count left_clamshell_overview = 0;
base::HistogramBase::Count left_tablet = 0;
base::HistogramBase::Count right_clamshell_no_overview = 0;
base::HistogramBase::Count right_clamshell_overview = 0;
base::HistogramBase::Count right_tablet = 0;
base::HistogramBase::Count32 left_clamshell_no_overview = 0;
base::HistogramBase::Count32 left_clamshell_overview = 0;
base::HistogramBase::Count32 left_tablet = 0;
base::HistogramBase::Count32 right_clamshell_no_overview = 0;
base::HistogramBase::Count32 right_clamshell_overview = 0;
base::HistogramBase::Count32 right_tablet = 0;
// Performs |action|, checks that |window1| is in |target_window1_state_type|,
// and verifies metrics. Output of failed expectations includes |description|.
const auto test = [&](const char* description, AcceleratorAction action,

@ -244,7 +244,7 @@ TEST_F(BatterySaverControllerTest, USBCharging) {
// Metrics always logged on enable.
void ExpectEnabledMetrics(base::HistogramTester& histogram_tester,
base::HistogramBase::Count enabled_count) {
base::HistogramBase::Count32 enabled_count) {
histogram_tester.ExpectTotalCount("Ash.BatterySaver.BatteryPercent.Enabled",
enabled_count);
histogram_tester.ExpectTotalCount("Ash.BatterySaver.TimeToEmpty.Enabled",
@ -254,7 +254,7 @@ void ExpectEnabledMetrics(base::HistogramTester& histogram_tester,
// Metrics logged on enable when enabled via settings.
void ExpectSettingsEnabledMetrics(
base::HistogramTester& histogram_tester,
base::HistogramBase::Count settings_enabled_count) {
base::HistogramBase::Count32 settings_enabled_count) {
histogram_tester.ExpectTotalCount(
"Ash.BatterySaver.BatteryPercent.EnabledSettings",
settings_enabled_count);
@ -264,7 +264,7 @@ void ExpectSettingsEnabledMetrics(
// Metrics always logged on disable.
void ExpectDisabledMetrics(base::HistogramTester& histogram_tester,
base::HistogramBase::Count disabled_count) {
base::HistogramBase::Count32 disabled_count) {
histogram_tester.ExpectTotalCount("Ash.BatterySaver.BatteryPercent.Disabled",
disabled_count);
histogram_tester.ExpectTotalCount("Ash.BatterySaver.TimeToEmpty.Disabled",
@ -276,7 +276,7 @@ void ExpectDisabledMetrics(base::HistogramTester& histogram_tester,
// Metrics logged on disable when enabled via notification.
void ExpectNotificationEnabledMetricsOnDisable(
base::HistogramTester& histogram_tester,
base::HistogramBase::Count notification_enabled_count) {
base::HistogramBase::Count32 notification_enabled_count) {
histogram_tester.ExpectTotalCount(
"Ash.BatterySaver.Duration.EnabledNotification",
notification_enabled_count);
@ -285,7 +285,7 @@ void ExpectNotificationEnabledMetricsOnDisable(
// Metrics logged on disable when enabled via settings.
void ExpectSettingsEnabledMetricsOnDisable(
base::HistogramTester& histogram_tester,
base::HistogramBase::Count settings_enabled_count) {
base::HistogramBase::Count32 settings_enabled_count) {
histogram_tester.ExpectTotalCount("Ash.BatterySaver.Duration.EnabledSettings",
settings_enabled_count);
}
@ -293,7 +293,7 @@ void ExpectSettingsEnabledMetricsOnDisable(
// Metrics logged on disable when disabled via charging.
void ExpectChargingDisabledMetrics(
base::HistogramTester& histogram_tester,
base::HistogramBase::Count charging_disabled_count) {
base::HistogramBase::Count32 charging_disabled_count) {
histogram_tester.ExpectTotalCount(
"Ash.BatterySaver.Duration.DisabledCharging", charging_disabled_count);
}
@ -301,7 +301,7 @@ void ExpectChargingDisabledMetrics(
// Metrics logged on disable when disabled via notification.
void ExpectNotificationDisabledMetrics(
base::HistogramTester& histogram_tester,
base::HistogramBase::Count notification_disabled_count) {
base::HistogramBase::Count32 notification_disabled_count) {
histogram_tester.ExpectTotalCount(
"Ash.BatterySaver.Duration.DisabledNotification",
notification_disabled_count);
@ -310,7 +310,7 @@ void ExpectNotificationDisabledMetrics(
// Metrics logged on disable when disabled via settings.
void ExpectSettingsDisabledMetrics(
base::HistogramTester& histogram_tester,
base::HistogramBase::Count settings_disabled_count) {
base::HistogramBase::Count32 settings_disabled_count) {
histogram_tester.ExpectTotalCount(
"Ash.BatterySaver.BatteryPercent.DisabledSettings",
settings_disabled_count);

@ -281,7 +281,7 @@ JNI_NativeUmaRecorder_GetHistogramSamplesForTesting(JNIEnv* env,
!sampleCountIterator->Done(); sampleCountIterator->Next()) {
HistogramBase::Sample32 min;
int64_t max;
HistogramBase::Count count;
HistogramBase::Count32 count;
sampleCountIterator->Get(&min, &max, &count);
buckets.push_back(min);
buckets.push_back(max);

@ -97,9 +97,6 @@ class BASE_EXPORT HistogramBase {
using Sample32 = int32_t; // Used for samples.
using AtomicCount = subtle::Atomic32; // Used to count samples.
using Count32 = int32_t; // Used to manipulate counts in temporaries.
// Temporary alias for backward compatibility.
// TODO(crbug.com/40899968): Remove this alias.
using Count = Count32;
static const Sample32 kSampleType_MAX; // INT_MAX

@ -26,7 +26,7 @@
namespace base {
using Count = HistogramBase::Count;
using Count32 = HistogramBase::Count32;
using Sample32 = HistogramBase::Sample32;
namespace {
@ -43,17 +43,17 @@ struct SampleRecord {
uint64_t id; // Unique identifier of owner.
Sample32 value; // The value for which this record holds a count.
std::atomic<Count> count; // The count associated with the above value.
std::atomic<Count32> count; // The count associated with the above value.
// `count` may operate inter-process and so must be lock-free.
static_assert(std::atomic<Count>::is_always_lock_free);
static_assert(std::atomic<Count32>::is_always_lock_free);
// For backwards compatibility, `std::atomic<Count>` and `Count` must have
// the same memory layouts. If this ever changes, make sure to increment
// `kPersistentTypeId` above.
static_assert(std::is_standard_layout_v<std::atomic<Count>>);
static_assert(sizeof(std::atomic<Count>) == sizeof(Count));
static_assert(alignof(std::atomic<Count>) == alignof(Count));
static_assert(std::is_standard_layout_v<std::atomic<Count32>>);
static_assert(sizeof(std::atomic<Count32>) == sizeof(Count32));
static_assert(alignof(std::atomic<Count32>) == alignof(Count32));
};
} // namespace
@ -66,7 +66,7 @@ PersistentSampleMap::PersistentSampleMap(
PersistentSampleMap::~PersistentSampleMap() = default;
void PersistentSampleMap::Accumulate(Sample32 value, Count count) {
void PersistentSampleMap::Accumulate(Sample32 value, Count32 count) {
// We have to do the following atomically, because even if the caller is using
// a lock, a separate process (that is not aware of this lock) may
// concurrently modify the value.
@ -75,16 +75,16 @@ void PersistentSampleMap::Accumulate(Sample32 value, Count count) {
IncreaseSumAndCount(int64_t{count} * value, count);
}
Count PersistentSampleMap::GetCount(Sample32 value) const {
const std::atomic<Count>* const count_pointer = GetSampleCountStorage(value);
Count32 PersistentSampleMap::GetCount(Sample32 value) const {
const std::atomic<Count32>* const count_pointer = GetSampleCountStorage(value);
return count_pointer ? count_pointer->load(std::memory_order_relaxed) : 0;
}
Count PersistentSampleMap::TotalCount() const {
Count32 PersistentSampleMap::TotalCount() const {
// Make sure all samples have been loaded before trying to iterate over the
// map.
ImportSamples();
Count count = 0;
Count32 count = 0;
for (const auto& entry : sample_counts_) {
count += entry.second->load(std::memory_order_relaxed);
}
@ -160,7 +160,7 @@ bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
Operator op) {
Sample32 min;
int64_t max;
Count count;
Count32 count;
for (; !iter->Done(); iter->Next()) {
iter->Get(&min, &max, &count);
if (count == 0) {
@ -180,17 +180,17 @@ bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
return true;
}
std::atomic<Count>* PersistentSampleMap::GetSampleCountStorage(
std::atomic<Count32>* PersistentSampleMap::GetSampleCountStorage(
Sample32 value) const {
// If |value| is already in the map, just return that.
const auto it = sample_counts_.find(value);
return (it == sample_counts_.end()) ? ImportSamples(value) : it->second.get();
}
std::atomic<Count>* PersistentSampleMap::GetOrCreateSampleCountStorage(
std::atomic<Count32>* PersistentSampleMap::GetOrCreateSampleCountStorage(
Sample32 value) {
// Get any existing count storage.
std::atomic<Count>* count_pointer = GetSampleCountStorage(value);
std::atomic<Count32>* count_pointer = GetSampleCountStorage(value);
if (count_pointer) {
return count_pointer;
}
@ -204,7 +204,7 @@ std::atomic<Count>* PersistentSampleMap::GetOrCreateSampleCountStorage(
// full or corrupt. Instead, allocate the counter from the heap. This
// sample will not be persistent, will not be shared, and will leak...
// but it's better than crashing.
count_pointer = new std::atomic<Count>(0);
count_pointer = new std::atomic<Count32>(0);
sample_counts_[value] = count_pointer;
return count_pointer;
}
@ -235,7 +235,7 @@ PersistentSampleMapRecords* PersistentSampleMap::GetRecords() const {
return records_.get();
}
std::atomic<Count>* PersistentSampleMap::ImportSamples(
std::atomic<Count32>* PersistentSampleMap::ImportSamples(
std::optional<Sample32> until_value) const {
std::vector<PersistentMemoryAllocator::Reference> refs;
PersistentSampleMapRecords* records = GetRecords();

@ -166,7 +166,7 @@ TEST(PersistentSampleMapIteratorTest, IterateTest) {
HistogramBase::Sample32 min;
int64_t max;
HistogramBase::Count count;
HistogramBase::Count32 count;
it->Get(&min, &max, &count);
EXPECT_EQ(1, min);
@ -216,7 +216,7 @@ TEST(PersistentSampleMapIteratorTest, SkipEmptyRanges) {
HistogramBase::Sample32 min;
int64_t max;
HistogramBase::Count count;
HistogramBase::Count32 count;
it->Get(&min, &max, &count);
EXPECT_EQ(10, min);
@ -247,7 +247,7 @@ TEST(PersistentSampleMapIteratorDeathTest, IterateDoneTest) {
HistogramBase::Sample32 min;
int64_t max;
HistogramBase::Count count;
HistogramBase::Count32 count;
EXPECT_DCHECK_DEATH(it->Get(&min, &max, &count));
EXPECT_DCHECK_DEATH(it->Next());

@ -15,7 +15,7 @@
namespace base {
using Count = HistogramBase::Count;
using Count32 = HistogramBase::Count32;
using Sample32 = HistogramBase::Sample32;
SampleMap::SampleMap(uint64_t id)
@ -23,7 +23,7 @@ SampleMap::SampleMap(uint64_t id)
SampleMap::~SampleMap() = default;
void SampleMap::Accumulate(Sample32 value, Count count) {
void SampleMap::Accumulate(Sample32 value, Count32 count) {
// We do not have to do the following atomically -- if the caller needs
// thread safety, they should use a lock. And since this is in local memory,
// if a lock is used, we know the value would not be concurrently modified
@ -33,13 +33,13 @@ void SampleMap::Accumulate(Sample32 value, Count count) {
IncreaseSumAndCount(strict_cast<int64_t>(count) * value, count);
}
Count SampleMap::GetCount(Sample32 value) const {
Count32 SampleMap::GetCount(Sample32 value) const {
const auto it = sample_counts_.find(value);
return (it == sample_counts_.end()) ? 0 : it->second;
}
Count SampleMap::TotalCount() const {
Count count = 0;
Count32 SampleMap::TotalCount() const {
Count32 count = 0;
for (const auto& entry : sample_counts_) {
count += entry.second;
}
@ -68,7 +68,7 @@ bool SampleMap::IsDefinitelyEmpty() const {
bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) {
Sample32 min;
int64_t max;
Count count;
Count32 count;
for (; !iter->Done(); iter->Next()) {
iter->Get(&min, &max, &count);
if (int64_t{min} + 1 != max) {
@ -83,7 +83,7 @@ bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) {
// if a lock is used, we know the value would not be concurrently modified
// by a different process (in contrast to PersistentSampleMap, where the
// value in shared memory may be modified concurrently by a subprocess).
Count& sample_ref = sample_counts_[min];
Count32& sample_ref = sample_counts_[min];
if (op == HistogramSamples::ADD) {
sample_ref = base::WrappingAdd(sample_ref, count);
} else {

@ -590,9 +590,9 @@ TEST_P(RasterBufferProviderTest, MeasureGpuRasterDuration) {
// Only in Chrome OS, we should be measuring raster scheduling delay (and only
// for tasks that don't depend on at-raster image decodes).
base::HistogramBase::Count expected_delay_histogram_all_tiles_count = 0;
base::HistogramBase::Count expected_delay_histogram_jpeg_tiles_count = 0;
base::HistogramBase::Count expected_delay_histogram_webp_tiles_count = 0;
base::HistogramBase::Count32 expected_delay_histogram_all_tiles_count = 0;
base::HistogramBase::Count32 expected_delay_histogram_jpeg_tiles_count = 0;
base::HistogramBase::Count32 expected_delay_histogram_webp_tiles_count = 0;
#if BUILDFLAG(IS_CHROMEOS_ASH)
if (GetParam() == RASTER_BUFFER_PROVIDER_TYPE_GPU) {
expected_delay_histogram_all_tiles_count = 5;

@ -833,7 +833,7 @@ class CloudPolicyInvalidatorWithListenerUserTypedTest
base::HistogramTester histogram_tester_;
};
base::HistogramBase::Count
base::HistogramBase::Count32
CloudPolicyInvalidatorWithListenerUserTypedTest::GetCount(
MetricPolicyRefresh metric) {
const char* metric_name = CloudPolicyInvalidator::GetPolicyRefreshMetricName(
@ -842,7 +842,7 @@ CloudPolicyInvalidatorWithListenerUserTypedTest::GetCount(
->GetCount(metric);
}
base::HistogramBase::Count
base::HistogramBase::Count32
CloudPolicyInvalidatorWithListenerUserTypedTest::GetInvalidationCount(
PolicyInvalidationType type) {
const char* metric_name =

@ -260,7 +260,7 @@ IN_PROC_BROWSER_TEST_F(NaClBrowserTestGLibcVcacheExtension,
// This includes pnacl-llc.nexe, pnacl-ld.nexe, and possibly pnacl-sz.nexe.
IN_PROC_BROWSER_TEST_F(NaClBrowserTestPnacl, ValidationCacheOfTranslatorNexes) {
const bool uses_subzero_with_o0 = IsSubzeroSupportedForArch();
base::HistogramBase::Count subzero_o0_count = (uses_subzero_with_o0 ? 1 : 0);
base::HistogramBase::Count32 subzero_o0_count = (uses_subzero_with_o0 ? 1 : 0);
base::HistogramTester histograms;
// Run a load test w/ one pexe cache identity.
RunLoadTest(FILE_PATH_LITERAL("pnacl_options.html?use_nmf=o_0"));

@ -52,7 +52,7 @@ class CastRuntimeHistogramFlattener final : public base::HistogramFlattener {
!it->Done(); it->Next()) {
base::Histogram::Sample32 min;
int64_t max = 0;
base::Histogram::Count count;
base::Histogram::Count32 count;
it->Get(&min, &max, &count);
cast::metrics::HistogramBucket* bucket = converted.add_bucket();

@ -164,14 +164,14 @@ class ConnectionManagerImplTest : public testing::Test {
void VerifyConnectionResultHistogram(
base::HistogramBase::Sample32 sample,
base::HistogramBase::Count expected_count) {
base::HistogramBase::Count32 expected_count) {
histogram_tester_.ExpectBucketCount(kConnectionResultMetricName, sample,
expected_count);
}
void VerifyConnectionFailureReasonHistogram(
secure_channel::mojom::ConnectionAttemptFailureReason sample,
base::HistogramBase::Count expected_count) {
base::HistogramBase::Count32 expected_count) {
histogram_tester_.ExpectBucketCount(kConnectionResultMetricName, sample,
expected_count);
}

@ -32,7 +32,7 @@ void EncodeHistogramDelta(const std::string& histogram_name,
!it->Done(); it->Next()) {
base::Histogram::Sample32 min;
int64_t max;
base::Histogram::Count count;
base::Histogram::Count32 count;
it->Get(&min, &max, &count);
HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
bucket->set_min(min);

@ -264,7 +264,7 @@ class UnsentLogStore : public LogStore {
int staged_log_index_;
// The total number of samples that have been sent from this LogStore.
base::HistogramBase::Count total_samples_sent_ = 0;
base::HistogramBase::Count32 total_samples_sent_ = 0;
};
} // namespace metrics

@ -1547,7 +1547,7 @@ TEST_F(MutableProfileOAuth2TokenServiceDelegateTest, TokenReencryption) {
auto SetUpTestAndReturnScopedCleanup =
[this](bool new_encryption_enabled, bool expect_reencrypt,
std::string_view key_prefix,
base::HistogramBase::Count expected_writes)
base::HistogramBase::Count32 expected_writes)
-> base::ScopedClosureRunner {
auto histograms = std::make_unique<base::HistogramTester>();
auto features = std::make_unique<base::test::ScopedFeatureList>();

@ -89,7 +89,7 @@ class HistogramTester {
// and is modified based on the snapshot stored for histogram `name`.
BOOL CheckBucketCount(const std::string& name,
base::HistogramBase::Sample32 sample,
base::Histogram::Count expected_count,
base::Histogram::Count32 expected_count,
const base::HistogramSamples& samples,
FailureBlock failure_block) const;
@ -97,7 +97,7 @@ class HistogramTester {
// is `expected_count`. This is checked against `samples` minus the snapshot
// that was taken for `name`.
BOOL CheckTotalCount(const std::string& name,
base::Histogram::Count expected_count,
base::Histogram::Count32 expected_count,
const base::HistogramSamples& samples,
FailureBlock failure_block) const;

@ -36,7 +36,7 @@ constexpr char kPreflightWarningHistogramName[] =
"Net.Cors.PreflightCheckWarning";
base::Bucket MakeBucket(mojom::CorsError error,
base::HistogramBase::Count count) {
base::HistogramBase::Count32 count) {
return base::Bucket(static_cast<base::HistogramBase::Sample32>(error), count);
}

@ -558,7 +558,7 @@ MATCHER_P(OverdrawOpAreMatcher, expected_overdraw_ops, "") {
SCOPED_TRACE(Message() << "Checking overdraw bucket: " << bucket);
arg.ExpectBucketCount(
"Blink.Canvas.OverdrawOp", bucket,
static_cast<base::HistogramBase::Count>(expected_overdraw_ops.count(
static_cast<base::HistogramBase::Count32>(expected_overdraw_ops.count(
static_cast<BaseRenderingContext2D::OverdrawOp>(bucket))));
}
return true;

@ -156,7 +156,7 @@ class ParkableImageBaseTest : public ::testing::Test {
// Checks the counts for all 3 metrics, but only checks the value for
// "Memory.ParkableImage.Write.Size", since the others can't be easily tested.
void ExpectWriteStatistics(base::HistogramBase::Sample32 sample,
base::HistogramBase::Count expected_count) {
base::HistogramBase::Count32 expected_count) {
histogram_tester_.ExpectTotalCount("Memory.ParkableImage.Write.Latency",
expected_count);
histogram_tester_.ExpectBucketCount("Memory.ParkableImage.Write.Size",
@ -171,7 +171,7 @@ class ParkableImageBaseTest : public ::testing::Test {
// Checks the counts for both metrics, but not their values, since they can't
// be easily tested.
void ExpectReadStatistics(base::HistogramBase::Sample32 sample,
base::HistogramBase::Count expected_count) {
base::HistogramBase::Count32 expected_count) {
histogram_tester_.ExpectTotalCount("Memory.ParkableImage.Read.Latency",
expected_count);
histogram_tester_.ExpectTotalCount("Memory.ParkableImage.Read.Throughput",