summaryrefslogtreecommitdiff
path: root/base/metrics
diff options
context:
space:
mode:
Diffstat (limited to 'base/metrics')
-rw-r--r--base/metrics/histogram.cc2
-rw-r--r--base/metrics/histogram_base.cc2
-rw-r--r--base/metrics/histogram_macros.h14
-rw-r--r--base/metrics/histogram_macros_internal.h61
-rw-r--r--base/metrics/histogram_macros_unittest.cc31
-rw-r--r--base/metrics/histogram_samples.cc2
-rw-r--r--base/metrics/persistent_memory_allocator.cc2
-rw-r--r--base/metrics/sample_vector.cc2
-rw-r--r--base/metrics/sparse_histogram.cc14
-rw-r--r--base/metrics/statistics_recorder.cc2
10 files changed, 99 insertions, 33 deletions
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index d455c87b0f..16e36ae4b0 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -130,7 +130,7 @@ class Histogram::Factory {
// Perform any required datafill on the just-created histogram. If
// overridden, be sure to call the "super" version -- this method may not
// always remain empty.
- virtual void FillHistogram(HistogramBase* /*histogram*/) {}
+ virtual void FillHistogram(HistogramBase* histogram) {}
// These values are protected (instead of private) because they need to
// be accessible to methods of sub-classes in order to avoid passing
diff --git a/base/metrics/histogram_base.cc b/base/metrics/histogram_base.cc
index 396f29739a..671cad2429 100644
--- a/base/metrics/histogram_base.cc
+++ b/base/metrics/histogram_base.cc
@@ -97,7 +97,7 @@ bool HistogramBase::SerializeInfo(Pickle* pickle) const {
return SerializeInfoImpl(pickle);
}
-uint32_t HistogramBase::FindCorruption(const HistogramSamples& /* samples */) const {
+uint32_t HistogramBase::FindCorruption(const HistogramSamples& samples) const {
// Not supported by default.
return NO_INCONSISTENCIES;
}
diff --git a/base/metrics/histogram_macros.h b/base/metrics/histogram_macros.h
index 78473761dd..d39972a8a1 100644
--- a/base/metrics/histogram_macros.h
+++ b/base/metrics/histogram_macros.h
@@ -41,10 +41,9 @@
// delete and reused. The value in |sample| must be strictly less than
// |enum_max|.
-#define UMA_HISTOGRAM_ENUMERATION(name, sample, enum_max) \
- INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG( \
- name, sample, enum_max, \
- base::HistogramBase::kUmaTargetedHistogramFlag)
+#define UMA_HISTOGRAM_ENUMERATION(name, sample, enum_max) \
+ INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG( \
+ name, sample, enum_max, base::HistogramBase::kUmaTargetedHistogramFlag)
// Histogram for boolean values.
@@ -68,14 +67,15 @@
// Sample usage:
// UMA_HISTOGRAM_EXACT_LINEAR("Histogram.Linear", count, 10);
#define UMA_HISTOGRAM_EXACT_LINEAR(name, sample, value_max) \
- UMA_HISTOGRAM_ENUMERATION(name, sample, value_max)
+ INTERNAL_HISTOGRAM_EXACT_LINEAR_WITH_FLAG( \
+ name, sample, value_max, base::HistogramBase::kUmaTargetedHistogramFlag)
// Used for capturing basic percentages. This will be 100 buckets of size 1.
// Sample usage:
// UMA_HISTOGRAM_PERCENTAGE("Histogram.Percent", percent_as_int);
-#define UMA_HISTOGRAM_PERCENTAGE(name, percent_as_int) \
- UMA_HISTOGRAM_ENUMERATION(name, percent_as_int, 101)
+#define UMA_HISTOGRAM_PERCENTAGE(name, percent_as_int) \
+ UMA_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101)
//------------------------------------------------------------------------------
// Count histograms. These are used for collecting numeric data. Note that we
diff --git a/base/metrics/histogram_macros_internal.h b/base/metrics/histogram_macros_internal.h
index 53e4f11b75..c107a4729d 100644
--- a/base/metrics/histogram_macros_internal.h
+++ b/base/metrics/histogram_macros_internal.h
@@ -5,6 +5,11 @@
#ifndef BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_
#define BASE_METRICS_HISTOGRAM_MACROS_INTERNAL_H_
+#include <stdint.h>
+
+#include <limits>
+#include <type_traits>
+
#include "base/atomicops.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
@@ -96,17 +101,42 @@
base::Histogram::FactoryGet(name, min, max, bucket_count, flag))
// This is a helper macro used by other macros and shouldn't be used directly.
-// For an enumeration with N items, recording values in the range [0, N - 1],
-// this macro creates a linear histogram with N + 1 buckets:
-// [0, 1), [1, 2), ..., [N - 1, N), and an overflow bucket [N, infinity).
+// The bucketing scheme is linear with a bucket size of 1. For N items,
+// recording values in the range [0, N - 1] creates a linear histogram with N +
+// 1 buckets:
+// [0, 1), [1, 2), ..., [N - 1, N)
+// and an overflow bucket [N, infinity).
+//
// Code should never emit to the overflow bucket; only to the other N buckets.
-// This allows future versions of Chrome to safely append new entries to the
-// enumeration. Otherwise, the histogram would have [N - 1, infinity) as its
-// overflow bucket, and so the maximal value (N - 1) would be emitted to this
-// overflow bucket. But, if an additional enumerated value were later added, the
-// bucket label for the value (N - 1) would change to [N - 1, N), which would
-// result in different versions of Chrome using different bucket labels for
-// identical data.
+// This allows future versions of Chrome to safely increase the boundary size.
+// Otherwise, the histogram would have [N - 1, infinity) as its overflow bucket,
+// and so the maximal value (N - 1) would be emitted to this overflow bucket.
+// But, if an additional value were later added, the bucket label for
+// the value (N - 1) would change to [N - 1, N), which would result in different
+// versions of Chrome using different bucket labels for identical data.
+#define INTERNAL_HISTOGRAM_EXACT_LINEAR_WITH_FLAG(name, sample, boundary, \
+ flag) \
+ do { \
+ static_assert(!std::is_enum<decltype(sample)>::value, \
+ "|sample| should not be an enum type!"); \
+ static_assert(!std::is_enum<decltype(boundary)>::value, \
+ "|boundary| should not be an enum type!"); \
+ STATIC_HISTOGRAM_POINTER_BLOCK( \
+ name, Add(sample), \
+ base::LinearHistogram::FactoryGet(name, 1, boundary, boundary + 1, \
+ flag)); \
+ } while (0)
+
+// Similar to the previous macro but intended for enumerations. This delegates
+// the work to the previous macro, but supports scoped enumerations as well by
+// forcing an explicit cast to the HistogramBase::Sample integral type.
+//
+// Note the range checks verify two separate issues:
+// - that the declared enum max isn't out of range of HistogramBase::Sample
+// - that the declared enum max is > 0
+//
+// TODO(dcheng): This should assert that the passed in types are actually enum
+// types.
#define INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary, flag) \
do { \
static_assert( \
@@ -115,9 +145,14 @@
std::is_same<std::remove_const<decltype(sample)>::type, \
std::remove_const<decltype(boundary)>::type>::value, \
"|sample| and |boundary| shouldn't be of different enums"); \
- STATIC_HISTOGRAM_POINTER_BLOCK( \
- name, Add(sample), base::LinearHistogram::FactoryGet( \
- name, 1, boundary, boundary + 1, flag)); \
+ static_assert( \
+ static_cast<uintmax_t>(boundary) < \
+ static_cast<uintmax_t>( \
+ std::numeric_limits<base::HistogramBase::Sample>::max()), \
+ "|boundary| is out of range of HistogramBase::Sample"); \
+ INTERNAL_HISTOGRAM_EXACT_LINEAR_WITH_FLAG( \
+ name, static_cast<base::HistogramBase::Sample>(sample), \
+ static_cast<base::HistogramBase::Sample>(boundary), flag); \
} while (0)
// This is a helper macro used by other macros and shouldn't be used directly.
diff --git a/base/metrics/histogram_macros_unittest.cc b/base/metrics/histogram_macros_unittest.cc
index c5991619a0..33a9c6e5b2 100644
--- a/base/metrics/histogram_macros_unittest.cc
+++ b/base/metrics/histogram_macros_unittest.cc
@@ -15,4 +15,35 @@ TEST(ScopedHistogramTimer, TwoTimersOneScope) {
SCOPED_UMA_HISTOGRAM_LONG_TIMER("TestLongTimer1");
}
+// Compile tests for UMA_HISTOGRAM_ENUMERATION with the three different types it
+// accepts:
+// - integral types
+// - unscoped enums
+// - scoped enums
+TEST(HistogramMacro, IntegralPsuedoEnumeration) {
+ UMA_HISTOGRAM_ENUMERATION("Test.FauxEnumeration", 1, 10000);
+}
+
+TEST(HistogramMacro, UnscopedEnumeration) {
+ enum TestEnum : char {
+ FIRST_VALUE,
+ SECOND_VALUE,
+ THIRD_VALUE,
+ MAX_ENTRIES,
+ };
+ UMA_HISTOGRAM_ENUMERATION("Test.UnscopedEnumeration", SECOND_VALUE,
+ MAX_ENTRIES);
+}
+
+TEST(HistogramMacro, ScopedEnumeration) {
+ enum class TestEnum {
+ FIRST_VALUE,
+ SECOND_VALUE,
+ THIRD_VALUE,
+ MAX_ENTRIES,
+ };
+ UMA_HISTOGRAM_ENUMERATION("Test.ScopedEnumeration", TestEnum::SECOND_VALUE,
+ TestEnum::MAX_ENTRIES);
+}
+
} // namespace base
diff --git a/base/metrics/histogram_samples.cc b/base/metrics/histogram_samples.cc
index ea3b9874b3..3475cd59f7 100644
--- a/base/metrics/histogram_samples.cc
+++ b/base/metrics/histogram_samples.cc
@@ -147,7 +147,7 @@ void HistogramSamples::IncreaseRedundantCount(HistogramBase::Count diff) {
SampleCountIterator::~SampleCountIterator() {}
-bool SampleCountIterator::GetBucketIndex(size_t* /*index*/) const {
+bool SampleCountIterator::GetBucketIndex(size_t* index) const {
DCHECK(!Done());
return false;
}
diff --git a/base/metrics/persistent_memory_allocator.cc b/base/metrics/persistent_memory_allocator.cc
index abcc532242..d381d8784d 100644
--- a/base/metrics/persistent_memory_allocator.cc
+++ b/base/metrics/persistent_memory_allocator.cc
@@ -872,7 +872,7 @@ PersistentMemoryAllocator::GetBlock(Reference ref, uint32_t type_id,
return reinterpret_cast<const volatile BlockHeader*>(mem_base_ + ref);
}
-void PersistentMemoryAllocator::FlushPartial(size_t /*length*/, bool /*sync*/) {
+void PersistentMemoryAllocator::FlushPartial(size_t length, bool sync) {
// Generally there is nothing to do as every write is done through volatile
// memory with atomic instructions to guarantee consistency. This (virtual)
// method exists so that derivced classes can do special things, such as
diff --git a/base/metrics/sample_vector.cc b/base/metrics/sample_vector.cc
index 7b056cb3fd..477b8aff8c 100644
--- a/base/metrics/sample_vector.cc
+++ b/base/metrics/sample_vector.cc
@@ -26,7 +26,7 @@ SampleVector::SampleVector(uint64_t id, const BucketRanges* bucket_ranges)
SampleVector::SampleVector(uint64_t id,
HistogramBase::AtomicCount* counts,
- size_t /*counts_size*/,
+ size_t counts_size,
Metadata* meta,
const BucketRanges* bucket_ranges)
: HistogramSamples(id, meta),
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc
index bee48d4c17..415d7f9430 100644
--- a/base/metrics/sparse_histogram.cc
+++ b/base/metrics/sparse_histogram.cc
@@ -93,9 +93,9 @@ HistogramType SparseHistogram::GetHistogramType() const {
}
bool SparseHistogram::HasConstructionArguments(
- Sample /*expected_minimum*/,
- Sample /*expected_maximum*/,
- uint32_t /*expected_bucket_count*/) const {
+ Sample expected_minimum,
+ Sample expected_maximum,
+ uint32_t expected_bucket_count) const {
// SparseHistogram never has min/max/bucket_count limit.
return false;
}
@@ -213,13 +213,13 @@ HistogramBase* SparseHistogram::DeserializeInfoImpl(PickleIterator* iter) {
return SparseHistogram::FactoryGet(histogram_name, flags);
}
-void SparseHistogram::GetParameters(DictionaryValue* /*params*/) const {
+void SparseHistogram::GetParameters(DictionaryValue* params) const {
// TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)
}
-void SparseHistogram::GetCountAndBucketData(Count* /*count*/,
- int64_t* /*sum*/,
- ListValue* /*buckets*/) const {
+void SparseHistogram::GetCountAndBucketData(Count* count,
+ int64_t* sum,
+ ListValue* buckets) const {
// TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)
}
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index 74c964a3fb..ba2101bccf 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -520,7 +520,7 @@ void StatisticsRecorder::Reset() {
}
// static
-void StatisticsRecorder::DumpHistogramsToVlog(void* /*instance*/) {
+void StatisticsRecorder::DumpHistogramsToVlog(void* instance) {
std::string output;
StatisticsRecorder::WriteGraph(std::string(), &output);
VLOG(1) << output;