Commit 9c79c354 authored by Ryan Sleevi's avatar Ryan Sleevi Committed by Commit Bot

Switch CustomHistogram::ArrayToCustomRanges to base::span<>

While at it, also rename the method to ArrayToCustomEnumRanges and
close out an old TODO.

TBR=hubbe@chromium.org, kbr@chromium.org
BUG=837308

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I56464a852707550dd625a1da30186aaaa9fdef38
Reviewed-on: https://chromium-review.googlesource.com/1055947
Commit-Queue: Ryan Sleevi <rsleevi@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558089}
parent 7931cf4b
...@@ -1193,11 +1193,10 @@ HistogramType CustomHistogram::GetHistogramType() const { ...@@ -1193,11 +1193,10 @@ HistogramType CustomHistogram::GetHistogramType() const {
} }
// static // static
std::vector<Sample> CustomHistogram::ArrayToCustomRanges( std::vector<Sample> CustomHistogram::ArrayToCustomEnumRanges(
const Sample* values, uint32_t num_values) { base::span<const Sample> values) {
std::vector<Sample> all_values; std::vector<Sample> all_values;
for (uint32_t i = 0; i < num_values; ++i) { for (Sample value : values) {
Sample value = values[i];
all_values.push_back(value); all_values.push_back(value);
// Ensure that a guard bucket is added. If we end up with duplicate // Ensure that a guard bucket is added. If we end up with duplicate
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -513,9 +514,9 @@ class BASE_EXPORT CustomHistogram : public Histogram { ...@@ -513,9 +514,9 @@ class BASE_EXPORT CustomHistogram : public Histogram {
// This function ensures that a guard bucket exists right after any // This function ensures that a guard bucket exists right after any
// valid sample value (unless the next higher sample is also a valid value), // valid sample value (unless the next higher sample is also a valid value),
// so that invalid samples never fall into the same bucket as valid samples. // so that invalid samples never fall into the same bucket as valid samples.
// TODO(kaiwang): Change name to ArrayToCustomEnumRanges. static std::vector<Sample> ArrayToCustomEnumRanges(
static std::vector<Sample> ArrayToCustomRanges(const Sample* values, base::span<const Sample> values);
uint32_t num_values);
protected: protected:
class Factory; class Factory;
......
...@@ -326,8 +326,8 @@ ...@@ -326,8 +326,8 @@
// Samples should be one of the std::vector<int> list provided via // Samples should be one of the std::vector<int> list provided via
// |custom_ranges|. See comments above CustomRanges::FactoryGet about the // |custom_ranges|. See comments above CustomRanges::FactoryGet about the
// requirement of |custom_ranges|. You can use the helper function // requirement of |custom_ranges|. You can use the helper function
// CustomHistogram::ArrayToCustomRanges to transform a C-style array of valid // CustomHistogram::ArrayToCustomEnumRanges to transform a C-style array of
// sample values to a std::vector<int>. // valid sample values to a std::vector<int>.
#define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \ #define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \ STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
base::CustomHistogram::FactoryGet(name, custom_ranges, \ base::CustomHistogram::FactoryGet(name, custom_ranges, \
......
...@@ -292,10 +292,10 @@ TEST_P(HistogramTest, LinearRangesTest) { ...@@ -292,10 +292,10 @@ TEST_P(HistogramTest, LinearRangesTest) {
EXPECT_TRUE(ranges2.Equals(histogram2->bucket_ranges())); EXPECT_TRUE(ranges2.Equals(histogram2->bucket_ranges()));
} }
TEST_P(HistogramTest, ArrayToCustomRangesTest) { TEST_P(HistogramTest, ArrayToCustomEnumRangesTest) {
const HistogramBase::Sample ranges[3] = {5, 10, 20}; const HistogramBase::Sample ranges[3] = {5, 10, 20};
std::vector<HistogramBase::Sample> ranges_vec = std::vector<HistogramBase::Sample> ranges_vec =
CustomHistogram::ArrayToCustomRanges(ranges, 3); CustomHistogram::ArrayToCustomEnumRanges(ranges);
ASSERT_EQ(6u, ranges_vec.size()); ASSERT_EQ(6u, ranges_vec.size());
EXPECT_EQ(5, ranges_vec[0]); EXPECT_EQ(5, ranges_vec[0]);
EXPECT_EQ(6, ranges_vec[1]); EXPECT_EQ(6, ranges_vec[1]);
......
...@@ -257,25 +257,22 @@ DownloadInterruptReason MapShFileOperationCodes(int code) { ...@@ -257,25 +257,22 @@ DownloadInterruptReason MapShFileOperationCodes(int code) {
if (result == DOWNLOAD_INTERRUPT_REASON_FILE_FAILED) { if (result == DOWNLOAD_INTERRUPT_REASON_FILE_FAILED) {
UMA_HISTOGRAM_CUSTOM_ENUMERATION( UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Download.MapWinShErrorFileFailed", code, "Download.MapWinShErrorFileFailed", code,
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(
kAllSpecialShFileOperationCodes, kAllSpecialShFileOperationCodes));
arraysize(kAllSpecialShFileOperationCodes)));
} }
if (result == DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED) { if (result == DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED) {
UMA_HISTOGRAM_CUSTOM_ENUMERATION( UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Download.MapWinShErrorAccessDenied", code, "Download.MapWinShErrorAccessDenied", code,
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(
kAllSpecialShFileOperationCodes, kAllSpecialShFileOperationCodes));
arraysize(kAllSpecialShFileOperationCodes)));
} }
if (result == DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR) { if (result == DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR) {
UMA_HISTOGRAM_CUSTOM_ENUMERATION( UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Download.MapWinShErrorTransientError", code, "Download.MapWinShErrorTransientError", code,
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(
kAllSpecialShFileOperationCodes, kAllSpecialShFileOperationCodes));
arraysize(kAllSpecialShFileOperationCodes)));
} }
if (result != DOWNLOAD_INTERRUPT_REASON_NONE) if (result != DOWNLOAD_INTERRUPT_REASON_NONE)
......
...@@ -377,8 +377,7 @@ void RecordDownloadInterrupted(DownloadInterruptReason reason, ...@@ -377,8 +377,7 @@ void RecordDownloadInterrupted(DownloadInterruptReason reason,
} }
std::vector<base::HistogramBase::Sample> samples = std::vector<base::HistogramBase::Sample> samples =
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(kAllInterruptReasonCodes);
kAllInterruptReasonCodes, arraysize(kAllInterruptReasonCodes));
UMA_HISTOGRAM_CUSTOM_ENUMERATION("Download.InterruptedReason", reason, UMA_HISTOGRAM_CUSTOM_ENUMERATION("Download.InterruptedReason", reason,
samples); samples);
......
...@@ -103,8 +103,7 @@ std::vector<int> GetAllGLErrors() { ...@@ -103,8 +103,7 @@ std::vector<int> GetAllGLErrors() {
GL_INVALID_FRAMEBUFFER_OPERATION, GL_INVALID_FRAMEBUFFER_OPERATION,
GL_OUT_OF_MEMORY, GL_OUT_OF_MEMORY,
}; };
return base::CustomHistogram::ArrayToCustomRanges(gl_errors, return base::CustomHistogram::ArrayToCustomEnumRanges(gl_errors);
arraysize(gl_errors));
} }
bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin,
......
...@@ -130,8 +130,7 @@ static void UmaHistogramAspectRatio(const char* name, const T& size) { ...@@ -130,8 +130,7 @@ static void UmaHistogramAspectRatio(const char* name, const T& size) {
name, name,
// Intentionally use integer division to truncate the result. // Intentionally use integer division to truncate the result.
size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio, size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio,
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(kCommonAspectRatios100));
kCommonAspectRatios100, arraysize(kCommonAspectRatios100)));
} }
// Record detected track counts by type corresponding to a src= playback. // Record detected track counts by type corresponding to a src= playback.
......
...@@ -193,8 +193,7 @@ void SessionMetricsRecorder::RecordVideoConfiguration() { ...@@ -193,8 +193,7 @@ void SessionMetricsRecorder::RecordVideoConfiguration() {
last_video_profile_, VIDEO_CODEC_PROFILE_MAX + 1); last_video_profile_, VIDEO_CODEC_PROFILE_MAX + 1);
UMA_HISTOGRAM_CUSTOM_ENUMERATION( UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Media.Remoting.VideoNaturalWidth", last_natural_size_.width(), "Media.Remoting.VideoNaturalWidth", last_natural_size_.width(),
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(kVideoWidthBuckets));
kVideoWidthBuckets, arraysize(kVideoWidthBuckets)));
// Intentionally use integer division to truncate the result. // Intentionally use integer division to truncate the result.
const int aspect_ratio_100 = const int aspect_ratio_100 =
last_natural_size_.height() last_natural_size_.height()
...@@ -202,8 +201,7 @@ void SessionMetricsRecorder::RecordVideoConfiguration() { ...@@ -202,8 +201,7 @@ void SessionMetricsRecorder::RecordVideoConfiguration() {
: kInfiniteRatio; : kInfiniteRatio;
UMA_HISTOGRAM_CUSTOM_ENUMERATION( UMA_HISTOGRAM_CUSTOM_ENUMERATION(
"Media.Remoting.VideoAspectRatio", aspect_ratio_100, "Media.Remoting.VideoAspectRatio", aspect_ratio_100,
base::CustomHistogram::ArrayToCustomRanges( base::CustomHistogram::ArrayToCustomEnumRanges(kCommonAspectRatios100));
kCommonAspectRatios100, arraysize(kCommonAspectRatios100)));
} }
void SessionMetricsRecorder::RecordTrackConfiguration() { void SessionMetricsRecorder::RecordTrackConfiguration() {
......
...@@ -105,16 +105,14 @@ void RecordPublicKeyHistogram(const char* chain_position, ...@@ -105,16 +105,14 @@ void RecordPublicKeyHistogram(const char* chain_position,
// binary curves - which range from 163 bits to 571 bits. // binary curves - which range from 163 bits to 571 bits.
counter = base::CustomHistogram::FactoryGet( counter = base::CustomHistogram::FactoryGet(
histogram_name, histogram_name,
base::CustomHistogram::ArrayToCustomRanges(kEccKeySizes, base::CustomHistogram::ArrayToCustomEnumRanges(kEccKeySizes),
arraysize(kEccKeySizes)),
base::HistogramBase::kUmaTargetedHistogramFlag); base::HistogramBase::kUmaTargetedHistogramFlag);
} else { } else {
// Key sizes < 1024 bits should cause errors, while key sizes > 16K are not // Key sizes < 1024 bits should cause errors, while key sizes > 16K are not
// uniformly supported by the underlying cryptographic libraries. // uniformly supported by the underlying cryptographic libraries.
counter = base::CustomHistogram::FactoryGet( counter = base::CustomHistogram::FactoryGet(
histogram_name, histogram_name,
base::CustomHistogram::ArrayToCustomRanges(kRsaDsaKeySizes, base::CustomHistogram::ArrayToCustomEnumRanges(kRsaDsaKeySizes),
arraysize(kRsaDsaKeySizes)),
base::HistogramBase::kUmaTargetedHistogramFlag); base::HistogramBase::kUmaTargetedHistogramFlag);
} }
counter->Add(size_bits); counter->Add(size_bits);
......
...@@ -172,8 +172,7 @@ std::vector<int> GetAllGetAddrinfoOSErrors() { ...@@ -172,8 +172,7 @@ std::vector<int> GetAllGetAddrinfoOSErrors() {
os_errors[i] = std::abs(os_errors[i]); os_errors[i] = std::abs(os_errors[i]);
} }
return base::CustomHistogram::ArrayToCustomRanges(os_errors, return base::CustomHistogram::ArrayToCustomEnumRanges(os_errors);
arraysize(os_errors));
} }
enum DnsResolveStatus { enum DnsResolveStatus {
......
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