Commit 1be08774 authored by Brian White's avatar Brian White Committed by Commit Bot

Have histogram-functions take native char* names.

Without this, the compiler emits ctor/dtor code to convert constant
strings to std::string making the call about 100x larger in size and
almost 2x the size of a caching macro instantiation.

According to the Android binary-size try-bot, saves about 4K...

Specifics:
-4,096 bytes main lib size
-4,738 bytes normalized apk size
InstallSize:
-4,122 bytes APK size
-4,122 bytes Estimated installed size (Android Go)
-4,122 bytes Estimated installed size
InstallBreakdown (-4,066 bytes):
+28 bytes unwind_cfi (dev and canary only) size
-4,096 bytes Native code size
+2 bytes Package metadata size


Bug: 944842
Change-Id: I4b9bdff28acfa7b0e5146de74fd922a5c8245b4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1630968Reviewed-by: default avatarNik Bhagat <nikunjb@chromium.org>
Commit-Queue: Brian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663838}
parent 9d665497
......@@ -17,6 +17,12 @@ void UmaHistogramBoolean(const std::string& name, bool sample) {
histogram->Add(sample);
}
void UmaHistogramBoolean(const char* name, bool sample) {
HistogramBase* histogram = BooleanHistogram::FactoryGet(
name, HistogramBase::kUmaTargetedHistogramFlag);
histogram->Add(sample);
}
void UmaHistogramExactLinear(const std::string& name,
int sample,
int value_max) {
......@@ -26,10 +32,21 @@ void UmaHistogramExactLinear(const std::string& name,
histogram->Add(sample);
}
void UmaHistogramExactLinear(const char* name, int sample, int value_max) {
HistogramBase* histogram =
LinearHistogram::FactoryGet(name, 1, value_max, value_max + 1,
HistogramBase::kUmaTargetedHistogramFlag);
histogram->Add(sample);
}
void UmaHistogramPercentage(const std::string& name, int percent) {
UmaHistogramExactLinear(name, percent, 100);
}
void UmaHistogramPercentage(const char* name, int percent) {
UmaHistogramExactLinear(name, percent, 100);
}
void UmaHistogramCustomCounts(const std::string& name,
int sample,
int min,
......@@ -40,30 +57,64 @@ void UmaHistogramCustomCounts(const std::string& name,
histogram->Add(sample);
}
void UmaHistogramCustomCounts(const char* name,
int sample,
int min,
int max,
int buckets) {
HistogramBase* histogram = Histogram::FactoryGet(
name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
histogram->Add(sample);
}
void UmaHistogramCounts100(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 100, 50);
}
void UmaHistogramCounts100(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 100, 50);
}
void UmaHistogramCounts1000(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
}
void UmaHistogramCounts1000(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
}
void UmaHistogramCounts10000(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 10000, 50);
}
void UmaHistogramCounts10000(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 10000, 50);
}
void UmaHistogramCounts100000(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 100000, 50);
}
void UmaHistogramCounts100000(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 100000, 50);
}
void UmaHistogramCounts1M(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 1000000, 50);
}
void UmaHistogramCounts1M(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 1000000, 50);
}
void UmaHistogramCounts10M(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 10000000, 50);
}
void UmaHistogramCounts10M(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 10000000, 50);
}
void UmaHistogramCustomTimes(const std::string& name,
TimeDelta sample,
TimeDelta min,
......@@ -74,21 +125,46 @@ void UmaHistogramCustomTimes(const std::string& name,
histogram->AddTimeMillisecondsGranularity(sample);
}
void UmaHistogramCustomTimes(const char* name,
TimeDelta sample,
TimeDelta min,
TimeDelta max,
int buckets) {
HistogramBase* histogram = Histogram::FactoryTimeGet(
name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
histogram->AddTimeMillisecondsGranularity(sample);
}
void UmaHistogramTimes(const std::string& name, TimeDelta sample) {
UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
TimeDelta::FromSeconds(10), 50);
}
void UmaHistogramTimes(const char* name, TimeDelta sample) {
UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
TimeDelta::FromSeconds(10), 50);
}
void UmaHistogramMediumTimes(const std::string& name, TimeDelta sample) {
UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
TimeDelta::FromMinutes(3), 50);
}
void UmaHistogramMediumTimes(const char* name, TimeDelta sample) {
UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
TimeDelta::FromMinutes(3), 50);
}
void UmaHistogramLongTimes(const std::string& name, TimeDelta sample) {
UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
TimeDelta::FromHours(1), 50);
}
void UmaHistogramLongTimes(const char* name, TimeDelta sample) {
UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
TimeDelta::FromHours(1), 50);
}
void UmaHistogramCustomMicrosecondsTimes(const std::string& name,
TimeDelta sample,
TimeDelta min,
......@@ -99,28 +175,62 @@ void UmaHistogramCustomMicrosecondsTimes(const std::string& name,
histogram->AddTimeMicrosecondsGranularity(sample);
}
void UmaHistogramCustomMicrosecondsTimes(const char* name,
TimeDelta sample,
TimeDelta min,
TimeDelta max,
int buckets) {
HistogramBase* histogram = Histogram::FactoryTimeGet(
name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
histogram->AddTimeMicrosecondsGranularity(sample);
}
void UmaHistogramMicrosecondsTimes(const std::string& name, TimeDelta sample) {
UmaHistogramCustomMicrosecondsTimes(name, sample,
TimeDelta::FromMicroseconds(1),
TimeDelta::FromSeconds(10), 50);
}
void UmaHistogramMicrosecondsTimes(const char* name, TimeDelta sample) {
UmaHistogramCustomMicrosecondsTimes(name, sample,
TimeDelta::FromMicroseconds(1),
TimeDelta::FromSeconds(10), 50);
}
void UmaHistogramMemoryKB(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
}
void UmaHistogramMemoryKB(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
}
void UmaHistogramMemoryMB(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
}
void UmaHistogramMemoryMB(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
}
void UmaHistogramMemoryLargeMB(const std::string& name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
}
void UmaHistogramMemoryLargeMB(const char* name, int sample) {
UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
}
void UmaHistogramSparse(const std::string& name, int sample) {
HistogramBase* histogram = SparseHistogram::FactoryGet(
name, HistogramBase::kUmaTargetedHistogramFlag);
histogram->Add(sample);
}
void UmaHistogramSparse(const char* name, int sample) {
HistogramBase* histogram = SparseHistogram::FactoryGet(
name, HistogramBase::kUmaTargetedHistogramFlag);
histogram->Add(sample);
}
} // namespace base
......@@ -21,6 +21,11 @@
// histogram names. These functions are slower compared to their macro
// equivalent because the histogram objects are not cached between calls.
// So, these shouldn't be used in performance critical code.
//
// Every function is duplicated to take both std::string and char* for the
// name. This avoids ctor/dtor instantiation for constant strigs to std::string
// which makes the call be larger than caching macros (which do accept char*)
// in those cases.
namespace base {
// For histograms with linear buckets.
......@@ -33,6 +38,9 @@ namespace base {
BASE_EXPORT void UmaHistogramExactLinear(const std::string& name,
int sample,
int value_max);
BASE_EXPORT void UmaHistogramExactLinear(const char* name,
int sample,
int value_max);
// For adding a sample to an enumerated histogram.
// Sample usage:
......@@ -58,6 +66,15 @@ void UmaHistogramEnumeration(const std::string& name, T sample, T enum_size) {
return UmaHistogramExactLinear(name, static_cast<int>(sample),
static_cast<int>(enum_size));
}
template <typename T>
void UmaHistogramEnumeration(const char* name, T sample, T enum_size) {
static_assert(std::is_enum<T>::value,
"Non enum passed to UmaHistogramEnumeration");
DCHECK_LE(static_cast<uintmax_t>(enum_size), static_cast<uintmax_t>(INT_MAX));
DCHECK_LT(static_cast<uintmax_t>(sample), static_cast<uintmax_t>(enum_size));
return UmaHistogramExactLinear(name, static_cast<int>(sample),
static_cast<int>(enum_size));
}
// Same as above, but uses T::kMaxValue as the inclusive maximum value of the
// enum.
......@@ -72,17 +89,30 @@ void UmaHistogramEnumeration(const std::string& name, T sample) {
return UmaHistogramExactLinear(name, static_cast<int>(sample),
static_cast<int>(T::kMaxValue) + 1);
}
template <typename T>
void UmaHistogramEnumeration(const char* name, T sample) {
static_assert(std::is_enum<T>::value,
"Non enum passed to UmaHistogramEnumeration");
DCHECK_LE(static_cast<uintmax_t>(T::kMaxValue),
static_cast<uintmax_t>(INT_MAX) - 1);
DCHECK_LE(static_cast<uintmax_t>(sample),
static_cast<uintmax_t>(T::kMaxValue));
return UmaHistogramExactLinear(name, static_cast<int>(sample),
static_cast<int>(T::kMaxValue) + 1);
}
// For adding boolean sample to histogram.
// Sample usage:
// base::UmaHistogramBoolean("My.Boolean", true)
BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
BASE_EXPORT void UmaHistogramBoolean(const char* name, bool sample);
// For adding histogram with percent.
// Percents are integer between 1 and 100.
// Sample usage:
// base::UmaHistogramPercentage("My.Percent", 69)
BASE_EXPORT void UmaHistogramPercentage(const std::string& name, int percent);
BASE_EXPORT void UmaHistogramPercentage(const char* name, int percent);
// For adding counts histogram.
// Sample usage:
......@@ -92,14 +122,25 @@ BASE_EXPORT void UmaHistogramCustomCounts(const std::string& name,
int min,
int max,
int buckets);
BASE_EXPORT void UmaHistogramCustomCounts(const char* name,
int sample,
int min,
int max,
int buckets);
// Counts specialization for maximum counts 100, 1000, 10k, 100k, 1M and 10M.
BASE_EXPORT void UmaHistogramCounts100(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramCounts100(const char* name, int sample);
BASE_EXPORT void UmaHistogramCounts1000(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramCounts1000(const char* name, int sample);
BASE_EXPORT void UmaHistogramCounts10000(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramCounts10000(const char* name, int sample);
BASE_EXPORT void UmaHistogramCounts100000(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramCounts100000(const char* name, int sample);
BASE_EXPORT void UmaHistogramCounts1M(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramCounts1M(const char* name, int sample);
BASE_EXPORT void UmaHistogramCounts10M(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramCounts10M(const char* name, int sample);
// For histograms storing times. It uses milliseconds granularity.
BASE_EXPORT void UmaHistogramCustomTimes(const std::string& name,
......@@ -107,14 +148,22 @@ BASE_EXPORT void UmaHistogramCustomTimes(const std::string& name,
TimeDelta min,
TimeDelta max,
int buckets);
BASE_EXPORT void UmaHistogramCustomTimes(const char* name,
TimeDelta sample,
TimeDelta min,
TimeDelta max,
int buckets);
// For short timings from 1 ms up to 10 seconds (50 buckets).
BASE_EXPORT void UmaHistogramTimes(const std::string& name, TimeDelta sample);
BASE_EXPORT void UmaHistogramTimes(const char* name, TimeDelta sample);
// For medium timings up to 3 minutes (50 buckets).
BASE_EXPORT void UmaHistogramMediumTimes(const std::string& name,
TimeDelta sample);
BASE_EXPORT void UmaHistogramMediumTimes(const char* name, TimeDelta sample);
// For time intervals up to 1 hr (50 buckets).
BASE_EXPORT void UmaHistogramLongTimes(const std::string& name,
TimeDelta sample);
BASE_EXPORT void UmaHistogramLongTimes(const char* name, TimeDelta sample);
// For histograms storing times with microseconds granularity.
BASE_EXPORT void UmaHistogramCustomMicrosecondsTimes(const std::string& name,
......@@ -122,18 +171,28 @@ BASE_EXPORT void UmaHistogramCustomMicrosecondsTimes(const std::string& name,
TimeDelta min,
TimeDelta max,
int buckets);
BASE_EXPORT void UmaHistogramCustomMicrosecondsTimes(const char* name,
TimeDelta sample,
TimeDelta min,
TimeDelta max,
int buckets);
// For microseconds timings from 1 microsecond up to 10 seconds (50 buckets).
BASE_EXPORT void UmaHistogramMicrosecondsTimes(const std::string& name,
TimeDelta sample);
BASE_EXPORT void UmaHistogramMicrosecondsTimes(const char* name,
TimeDelta sample);
// For recording memory related histograms.
// Used to measure common KB-granularity memory stats. Range is up to 500M.
BASE_EXPORT void UmaHistogramMemoryKB(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramMemoryKB(const char* name, int sample);
// Used to measure common MB-granularity memory stats. Range is up to ~1G.
BASE_EXPORT void UmaHistogramMemoryMB(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramMemoryMB(const char* name, int sample);
// Used to measure common MB-granularity memory stats. Range is up to ~64G.
BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramMemoryLargeMB(const char* name, int sample);
// For recording sparse histograms.
// The |sample| can be a negative or non-negative number.
......@@ -163,6 +222,7 @@ BASE_EXPORT void UmaHistogramMemoryLargeMB(const std::string& name, int sample);
// guarantees on the range of your data, use clamping, e.g.:
// UmaHistogramSparse("MyHistogram", ClampToRange(value, 0, 200));
BASE_EXPORT void UmaHistogramSparse(const std::string& name, int sample);
BASE_EXPORT void UmaHistogramSparse(const char* name, int sample);
} // namespace base
......
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