summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/histogram.cc152
-rw-r--r--base/histogram.h292
-rw-r--r--base/histogram_unittest.cc186
-rw-r--r--base/message_loop.cc13
-rw-r--r--chrome/browser/chrome_browser_application_mac.mm7
-rw-r--r--chrome/browser/chrome_browser_application_mac_unittest.mm2
-rw-r--r--chrome/browser/diagnostics/sqlite_diagnostics.cc6
-rw-r--r--chrome/browser/jankometer.cc14
-rw-r--r--chrome/browser/metrics/metrics_service.cc2
-rw-r--r--chrome/browser/net/dns_host_info.cc7
-rw-r--r--chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc61
-rw-r--r--chrome/browser/renderer_host/buffered_resource_handler.cc15
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_blocking_page.cc7
-rw-r--r--chrome/browser/ssl/ssl_blocking_page.cc7
-rw-r--r--chrome/browser/sync/profile_sync_service.cc7
-rw-r--r--chrome/renderer/render_thread.cc8
-rw-r--r--net/base/connection_type_histograms.cc26
-rw-r--r--net/base/mime_sniffer.cc5
-rw-r--r--net/base/sdch_manager.cc6
-rw-r--r--net/disk_cache/histogram_macros.h9
-rw-r--r--net/ftp/ftp_network_transaction.cc34
-rw-r--r--net/ftp/ftp_server_type_histograms.cc36
-rw-r--r--net/http/http_network_transaction.cc39
-rw-r--r--net/socket_stream/socket_stream_metrics.cc16
-rw-r--r--net/socket_stream/socket_stream_metrics_unittest.cc18
25 files changed, 304 insertions, 671 deletions
diff --git a/base/histogram.cc b/base/histogram.cc
index d55c84f..b7f6cb2 100644
--- a/base/histogram.cc
+++ b/base/histogram.cc
@@ -20,12 +20,8 @@ using base::TimeDelta;
typedef Histogram::Count Count;
-// static
-const int Histogram::kHexRangePrintingFlag = 0x8000;
-
-scoped_refptr<Histogram> Histogram::HistogramFactoryGet(
- const std::string& name, Sample minimum, Sample maximum,
- size_t bucket_count) {
+scoped_refptr<Histogram> Histogram::FactoryGet(const std::string& name,
+ Sample minimum, Sample maximum, size_t bucket_count, Flags flags) {
scoped_refptr<Histogram> histogram(NULL);
// Defensive code.
@@ -48,14 +44,15 @@ scoped_refptr<Histogram> Histogram::HistogramFactoryGet(
DCHECK(HISTOGRAM == histogram->histogram_type());
DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
+ histogram->SetFlags(flags);
return histogram;
}
-scoped_refptr<Histogram> Histogram::HistogramFactoryGet(
- const std::string& name, base::TimeDelta minimum, base::TimeDelta maximum,
- size_t bucket_count) {
- return HistogramFactoryGet(name,
- minimum.InMilliseconds(), maximum.InMilliseconds(), bucket_count);
+scoped_refptr<Histogram> Histogram::FactoryGet(const std::string& name,
+ base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count,
+ Flags flags) {
+ return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
+ bucket_count, flags);
}
Histogram::Histogram(const std::string& name, Sample minimum,
@@ -64,7 +61,7 @@ Histogram::Histogram(const std::string& name, Sample minimum,
declared_min_(minimum),
declared_max_(maximum),
bucket_count_(bucket_count),
- flags_(0),
+ flags_(kNoFlags),
ranges_(bucket_count + 1, 0),
sample_() {
Initialize();
@@ -76,14 +73,13 @@ Histogram::Histogram(const std::string& name, TimeDelta minimum,
declared_min_(static_cast<int> (minimum.InMilliseconds())),
declared_max_(static_cast<int> (maximum.InMilliseconds())),
bucket_count_(bucket_count),
- flags_(0),
+ flags_(kNoFlags),
ranges_(bucket_count + 1, 0),
sample_() {
Initialize();
}
Histogram::~Histogram() {
- DCHECK(!(kPlannedLeakFlag & flags_));
if (StatisticsRecorder::dump_on_exit()) {
std::string output;
WriteAscii(true, "\n", &output);
@@ -184,7 +180,7 @@ void Histogram::WriteAscii(bool graph_it, const std::string& newline,
bool Histogram::ValidateBucketRanges() const {
// Standard assertions that all bucket ranges should satisfy.
DCHECK(ranges_.size() == bucket_count_ + 1);
- DCHECK(0 == ranges_[0]);
+ DCHECK_EQ(0, ranges_[0]);
DCHECK(declared_min() == ranges_[1]);
DCHECK(declared_max() == ranges_[bucket_count_ - 1]);
DCHECK(kSampleType_MAX == ranges_[bucket_count_]);
@@ -197,12 +193,12 @@ void Histogram::Initialize() {
declared_min_ = 1;
if (declared_max_ >= kSampleType_MAX)
declared_max_ = kSampleType_MAX - 1;
- DCHECK(declared_min_ > 0); // We provide underflow bucket.
+ DCHECK_GT(declared_min_, 0); // We provide underflow bucket.
DCHECK(declared_min_ <= declared_max_);
- DCHECK(1 < bucket_count_);
+ DCHECK_LT(1u, bucket_count_);
size_t maximal_bucket_count = declared_max_ - declared_min_ + 2;
DCHECK(bucket_count_ <= maximal_bucket_count);
- DCHECK(0 == ranges_[0]);
+ DCHECK_EQ(0, ranges_[0]);
ranges_[bucket_count_] = kSampleType_MAX;
InitializeBucketRange();
DCHECK(ValidateBucketRanges());
@@ -330,7 +326,7 @@ void Histogram::WriteAsciiHeader(const SampleSet& snapshot,
histogram_name().c_str(),
sample_count);
if (0 == sample_count) {
- DCHECK(0 == snapshot.sum());
+ DCHECK_EQ(0, snapshot.sum());
} else {
double average = static_cast<float>(snapshot.sum()) / sample_count;
double variance = static_cast<float>(snapshot.square_sum())/sample_count
@@ -416,7 +412,7 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
int declared_min;
int declared_max;
int histogram_type;
- int flags;
+ int pickle_flags;
std::string histogram_name;
SampleSet sample;
@@ -425,29 +421,25 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
!pickle.ReadInt(&iter, &declared_max) ||
!pickle.ReadSize(&iter, &bucket_count) ||
!pickle.ReadInt(&iter, &histogram_type) ||
- !pickle.ReadInt(&iter, &flags) ||
+ !pickle.ReadInt(&iter, &pickle_flags) ||
!sample.Histogram::SampleSet::Deserialize(&iter, pickle)) {
LOG(ERROR) << "Picke error decoding Histogram: " << histogram_name;
return false;
}
+ Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag);
DCHECK(histogram_type != NOT_VALID_IN_RENDERER);
scoped_refptr<Histogram> render_histogram(NULL);
if (histogram_type == HISTOGRAM) {
- render_histogram = Histogram::HistogramFactoryGet(
- histogram_name, declared_min, declared_max, bucket_count);
+ render_histogram = Histogram::FactoryGet(
+ histogram_name, declared_min, declared_max, bucket_count, flags);
} else if (histogram_type == LINEAR_HISTOGRAM) {
- render_histogram = LinearHistogram::LinearHistogramFactoryGet(
- histogram_name, declared_min, declared_max, bucket_count);
+ render_histogram = LinearHistogram::FactoryGet(
+ histogram_name, declared_min, declared_max, bucket_count, flags);
} else if (histogram_type == BOOLEAN_HISTOGRAM) {
- render_histogram = BooleanHistogram::BooleanHistogramFactoryGet(
- histogram_name);
- } else if (histogram_type == THREAD_SAFE_HISTOGRAM) {
- render_histogram =
- ThreadSafeHistogram::ThreadSafeHistogramFactoryGet(
- histogram_name, declared_min, declared_max, bucket_count);
+ render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags);
} else {
LOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " <<
histogram_type;
@@ -463,9 +455,8 @@ bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
DLOG(INFO) << "Single process mode, histogram observed and not copied: " <<
histogram_name;
} else {
+ DCHECK(flags == (flags & render_histogram->flags()));
render_histogram->AddSampleSet(sample);
- render_histogram->SetFlags(flags & ~kIPCSerializationSourceFlag
- & ~kPlannedLeakFlag);
}
return true;
@@ -496,9 +487,9 @@ void Histogram::SampleSet::Accumulate(Sample value, Count count,
counts_[index] += count;
sum_ += count * value;
square_sum_ += (count * value) * static_cast<int64>(value);
- DCHECK(counts_[index] >= 0);
- DCHECK(sum_ >= 0);
- DCHECK(square_sum_ >= 0);
+ DCHECK_GE(counts_[index], 0);
+ DCHECK_GE(sum_, 0);
+ DCHECK_GE(square_sum_, 0);
}
Count Histogram::SampleSet::TotalCount() const {
@@ -528,7 +519,7 @@ void Histogram::SampleSet::Subtract(const SampleSet& other) {
square_sum_ -= other.square_sum_;
for (size_t index = 0; index < counts_.size(); ++index) {
counts_[index] -= other.counts_[index];
- DCHECK(counts_[index] >= 0);
+ DCHECK_GE(counts_[index], 0);
}
}
@@ -545,9 +536,9 @@ bool Histogram::SampleSet::Serialize(Pickle* pickle) const {
}
bool Histogram::SampleSet::Deserialize(void** iter, const Pickle& pickle) {
- DCHECK(counts_.size() == 0);
- DCHECK(sum_ == 0);
- DCHECK(square_sum_ == 0);
+ DCHECK_EQ(counts_.size(), 0u);
+ DCHECK_EQ(sum_, 0);
+ DCHECK_EQ(square_sum_, 0);
size_t counts_size;
@@ -575,9 +566,9 @@ bool Histogram::SampleSet::Deserialize(void** iter, const Pickle& pickle) {
// buckets.
//------------------------------------------------------------------------------
-scoped_refptr<Histogram> LinearHistogram::LinearHistogramFactoryGet(
+scoped_refptr<Histogram> LinearHistogram::FactoryGet(
const std::string& name, Sample minimum, Sample maximum,
- size_t bucket_count) {
+ size_t bucket_count, Flags flags) {
scoped_refptr<Histogram> histogram(NULL);
if (minimum <= 0)
@@ -598,15 +589,15 @@ scoped_refptr<Histogram> LinearHistogram::LinearHistogramFactoryGet(
DCHECK(LINEAR_HISTOGRAM == histogram->histogram_type());
DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
-
+ histogram->SetFlags(flags);
return histogram;
}
-scoped_refptr<Histogram> LinearHistogram::LinearHistogramFactoryGet(
- const std::string& name, base::TimeDelta minimum, base::TimeDelta maximum,
- size_t bucket_count) {
- return LinearHistogramFactoryGet(name, minimum.InMilliseconds(),
- maximum.InMilliseconds(), bucket_count);
+scoped_refptr<Histogram> LinearHistogram::FactoryGet(const std::string& name,
+ base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count,
+ Flags flags) {
+ return FactoryGet(name, minimum.InMilliseconds(), maximum.InMilliseconds(),
+ bucket_count, flags);
}
LinearHistogram::LinearHistogram(const std::string& name, Sample minimum,
@@ -647,7 +638,7 @@ bool LinearHistogram::PrintEmptyBucket(size_t index) const {
void LinearHistogram::InitializeBucketRange() {
- DCHECK(0 < declared_min()); // 0 is the underflow bucket here.
+ DCHECK_LT(0, declared_min()); // 0 is the underflow bucket here.
double min = declared_min();
double max = declared_max();
size_t i;
@@ -670,8 +661,8 @@ double LinearHistogram::GetBucketSize(Count current, size_t i) const {
// This section provides implementation for BooleanHistogram.
//------------------------------------------------------------------------------
-scoped_refptr<Histogram> BooleanHistogram::BooleanHistogramFactoryGet(
- const std::string& name) {
+scoped_refptr<Histogram> BooleanHistogram::FactoryGet(const std::string& name,
+ Flags flags) {
scoped_refptr<Histogram> histogram(NULL);
if (StatisticsRecorder::FindHistogram(name, &histogram)) {
@@ -686,63 +677,10 @@ scoped_refptr<Histogram> BooleanHistogram::BooleanHistogramFactoryGet(
}
DCHECK(BOOLEAN_HISTOGRAM == histogram->histogram_type());
-
- return histogram;
-}
-
-//------------------------------------------------------------------------------
-// This section provides implementation for ThreadSafeHistogram.
-//------------------------------------------------------------------------------
-
-scoped_refptr<Histogram> ThreadSafeHistogram::ThreadSafeHistogramFactoryGet(
- const std::string& name, Sample minimum, Sample maximum,
- size_t bucket_count) {
- scoped_refptr<Histogram> histogram(NULL);
-
- if (minimum <= 0)
- minimum = 1;
- if (maximum >= kSampleType_MAX)
- maximum = kSampleType_MAX - 1;
-
- if (StatisticsRecorder::FindHistogram(name, &histogram)) {
- DCHECK(histogram.get() != NULL);
- } else {
- histogram = new ThreadSafeHistogram(name, minimum, maximum, bucket_count);
- scoped_refptr<Histogram> registered_histogram(NULL);
- StatisticsRecorder::FindHistogram(name, &registered_histogram);
- if (registered_histogram.get() != NULL &&
- registered_histogram.get() != histogram.get())
- histogram = registered_histogram;
- }
-
- DCHECK(THREAD_SAFE_HISTOGRAM == histogram->histogram_type());
- DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count));
+ histogram->SetFlags(flags);
return histogram;
}
-ThreadSafeHistogram::ThreadSafeHistogram(const std::string& name,
- Sample minimum, Sample maximum, size_t bucket_count)
- : Histogram(name, minimum, maximum, bucket_count),
- lock_() {
- }
-
-void ThreadSafeHistogram::Remove(int value) {
- if (value >= kSampleType_MAX)
- value = kSampleType_MAX - 1;
- size_t index = BucketIndex(value);
- Accumulate(value, -1, index);
-}
-
-void ThreadSafeHistogram::Accumulate(Sample value, Count count, size_t index) {
- AutoLock lock(lock_);
- Histogram::Accumulate(value, count, index);
-}
-
-void ThreadSafeHistogram::SnapshotSample(SampleSet* sample) const {
- AutoLock lock(lock_);
- Histogram::SnapshotSample(sample);
-};
-
//------------------------------------------------------------------------------
// The next section handles global (central) support for all histograms, as well
@@ -862,8 +800,8 @@ void StatisticsRecorder::GetHistogramsForRenderer(Histograms* output) {
histograms_->end() != it;
++it) {
scoped_refptr<Histogram> histogram = it->second;
- if (!(histogram->flags() & kIPCSerializationSourceFlag))
- histogram->SetFlags(kIPCSerializationSourceFlag);
+ if (!(histogram->flags() & Histogram::kIPCSerializationSourceFlag))
+ histogram->SetFlags(Histogram::kIPCSerializationSourceFlag);
output->push_back(histogram);
}
}
diff --git a/base/histogram.h b/base/histogram.h
index 0c94fc0..79de748 100644
--- a/base/histogram.h
+++ b/base/histogram.h
@@ -44,92 +44,59 @@
// Provide easy general purpose histogram in a macro, just like stats counters.
// The first four macros use 50 buckets.
-#define HISTOGRAM_TIMES(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), base::TimeDelta::FromMilliseconds(1), \
- base::TimeDelta::FromSeconds(10), 50); \
- counter->AddTime(sample); \
- } while (0)
+#define HISTOGRAM_TIMES(name, sample) HISTOGRAM_CUSTOM_TIMES( \
+ name, sample, base::TimeDelta::FromMilliseconds(1), \
+ base::TimeDelta::FromSeconds(10), 50)
-#define HISTOGRAM_COUNTS(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 1000000, 50); \
- counter->Add(sample); \
- } while (0)
+#define HISTOGRAM_COUNTS(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 1000000, 50)
-#define HISTOGRAM_COUNTS_100(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 100, 50); \
- counter->Add(sample); \
- } while (0)
+#define HISTOGRAM_COUNTS_100(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 100, 50)
-#define HISTOGRAM_COUNTS_10000(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 10000, 50); \
- counter->Add(sample); \
- } while (0)
+#define HISTOGRAM_COUNTS_10000(name, sample) HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 10000, 50)
#define HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), min, max, bucket_count); \
+ static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
+ name, min, max, bucket_count, Histogram::kNoFlags); \
counter->Add(sample); \
} while (0)
-#define HISTOGRAM_PERCENTAGE(name, under_one_hundred) do { \
- static scoped_refptr<Histogram> counter = \
- LinearHistogram::LinearHistogramFactoryGet(\
- (name), 1, 100, 101); \
- counter->Add(under_one_hundred); \
- } while (0)
+#define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
+ HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
// For folks that need real specific times, use this to select a precise range
// of times you want plotted, and the number of buckets you want used.
#define HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), min, max, bucket_count); \
+ static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
+ name, min, max, bucket_count, Histogram::kNoFlags); \
counter->AddTime(sample); \
} while (0)
// DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES.
#define HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), min, max, bucket_count); \
+ static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
+ name, min, max, bucket_count, Histogram::kNoFlags); \
if ((sample) < (max)) counter->AddTime(sample); \
} while (0)
-//------------------------------------------------------------------------------
-// This macro set is for a histogram that can support both addition and removal
-// of samples. It should be used to render the accumulated asset allocation
-// of some samples. For example, it can sample memory allocation sizes, and
-// memory releases (as negative samples).
-// To simplify the interface, only non-zero values can be sampled, with positive
-// numbers indicating addition, and negative numbers implying dimunition
-// (removal).
-// Note that the underlying ThreadSafeHistogram() uses locking to ensure that
-// counts are precise (no chance of losing an addition or removal event, due to
-// multithread racing). This precision is required to prevent missed-counts from
-// resulting in drift, as the calls to Remove() for a given value should always
-// be equal in number or fewer than the corresponding calls to Add().
-
-#define ASSET_HISTOGRAM_COUNTS(name, sample) do { \
- static scoped_refptr<Histogram> counter = \
- ThreadSafeHistogram::ThreadSafeHistogramFactoryGet(\
- (name), 1, 1000000, 50); \
- if (0 == sample) break; \
- if (sample >= 0) \
- counter->Add(sample); \
- else\
- counter->Remove(-sample); \
+// Support histograming of an enumerated value. The samples should always be
+// less than boundary_value.
+
+#define HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
+ static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \
+ name, 1, boundary_value, boundary_value + 1, Histogram::kNoFlags); \
+ counter->Add(sample); \
} while (0)
+
//------------------------------------------------------------------------------
// Define Debug vs non-debug flavors of macros.
#ifndef NDEBUG
#define DHISTOGRAM_TIMES(name, sample) HISTOGRAM_TIMES(name, sample)
#define DHISTOGRAM_COUNTS(name, sample) HISTOGRAM_COUNTS(name, sample)
-#define DASSET_HISTOGRAM_COUNTS(name, sample) ASSET_HISTOGRAM_COUNTS(name, \
- sample)
#define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) HISTOGRAM_PERCENTAGE(\
name, under_one_hundred)
#define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
@@ -137,21 +104,22 @@
#define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \
HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count)
#define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
- HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count)
+ HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count)
+#define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) \
+ HISTOGRAM_ENUMERATION(name, sample, boundary_value)
#else // NDEBUG
#define DHISTOGRAM_TIMES(name, sample) do {} while (0)
#define DHISTOGRAM_COUNTS(name, sample) do {} while (0)
-#define DASSET_HISTOGRAM_COUNTS(name, sample) do {} while (0)
#define DHISTOGRAM_PERCENTAGE(name, under_one_hundred) do {} while (0)
#define DHISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
do {} while (0)
#define DHISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) \
do {} while (0)
#define DHISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
- do {} while (0)
-
+ do {} while (0)
+#define DHISTOGRAM_ENUMERATION(name, sample, boundary_value) do {} while (0)
#endif // NDEBUG
@@ -161,109 +129,64 @@
// Not all systems support such UMA, but if they do, the following macros
// should work with the service.
-static const int kUmaTargetedHistogramFlag = 0x1;
-
-// This indicates the histogram is pickled to be sent across an IPC Channel.
-// If we observe this flag during unpickle method, then we are running in a
-// single process mode.
-static const int kIPCSerializationSourceFlag = 1 << 4;
-
-// Some histograms aren't currently destroyed. Until such users properly
-// decref those histograms, we will mark there histograms as planned to leak so
-// that we can catch any user that directly tries to call delete "directly"
-// rather than using the reference counting features that should take care of
-// this.
-// TODO(jar): Make this flag unnecessary!
-static const int kPlannedLeakFlag = 1 << 5;
-
-#define UMA_HISTOGRAM_TIMES(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), base::TimeDelta::FromMilliseconds(1), \
- base::TimeDelta::FromSeconds(10), 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->AddTime(sample); \
- } while (0)
+#define UMA_HISTOGRAM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
+ name, sample, base::TimeDelta::FromMilliseconds(1), \
+ base::TimeDelta::FromSeconds(10), 50)
-#define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), base::TimeDelta::FromMilliseconds(10), \
- base::TimeDelta::FromMinutes(3), 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->AddTime(sample); \
- } while (0)
+#define UMA_HISTOGRAM_MEDIUM_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
+ name, sample, base::TimeDelta::FromMilliseconds(10), \
+ base::TimeDelta::FromMinutes(3), 50)
// Use this macro when times can routinely be much longer than 10 seconds.
-#define UMA_HISTOGRAM_LONG_TIMES(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), base::TimeDelta::FromMilliseconds(1), \
- base::TimeDelta::FromHours(1), 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->AddTime(sample); \
- } while (0)
+#define UMA_HISTOGRAM_LONG_TIMES(name, sample) UMA_HISTOGRAM_CUSTOM_TIMES( \
+ name, sample, base::TimeDelta::FromMilliseconds(1), \
+ base::TimeDelta::FromHours(1), 50)
#define UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
+ static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
+ name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \
counter->AddTime(sample); \
} while (0)
+// DO NOT USE THIS. It is being phased out, in favor of HISTOGRAM_CUSTOM_TIMES.
#define UMA_HISTOGRAM_CLIPPED_TIMES(name, sample, min, max, bucket_count) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
+ static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
+ name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \
if ((sample) < (max)) counter->AddTime(sample); \
} while (0)
-#define UMA_HISTOGRAM_COUNTS(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 1000000, 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
- } while (0)
+#define UMA_HISTOGRAM_COUNTS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 1000000, 50)
-#define UMA_HISTOGRAM_COUNTS_100(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 100, 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
- } while (0)
+#define UMA_HISTOGRAM_COUNTS_100(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 100, 50)
-#define UMA_HISTOGRAM_COUNTS_10000(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 10000, 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
- } while (0)
+#define UMA_HISTOGRAM_COUNTS_10000(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 10000, 50)
#define UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
+ static scoped_refptr<Histogram> counter = Histogram::FactoryGet( \
+ name, min, max, bucket_count, Histogram::kUmaTargetedHistogramFlag); \
counter->Add(sample); \
} while (0)
-#define UMA_HISTOGRAM_MEMORY_KB(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1000, 500000, 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
- } while (0)
+#define UMA_HISTOGRAM_MEMORY_KB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1000, 500000, 50)
+
+#define UMA_HISTOGRAM_MEMORY_MB(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \
+ name, sample, 1, 1000, 50)
-#define UMA_HISTOGRAM_MEMORY_MB(name, sample) do { \
- static scoped_refptr<Histogram> counter = Histogram::HistogramFactoryGet(\
- (name), 1, 1000, 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
+#define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
+ UMA_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
+
+#define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
+ DCHECK(sample < boundary_value); \
+ static scoped_refptr<Histogram> counter = LinearHistogram::FactoryGet( \
+ name, 1, boundary_value, boundary_value + 1, \
+ Histogram::kUmaTargetedHistogramFlag); \
counter->Add(sample); \
} while (0)
-#define UMA_HISTOGRAM_PERCENTAGE(name, under_one_hundred) do { \
- static scoped_refptr<Histogram> counter = \
- LinearHistogram::LinearHistogramFactoryGet(\
- (name), 1, 100, 101); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(under_one_hundred); \
- } while (0)
//------------------------------------------------------------------------------
@@ -271,7 +194,6 @@ class Pickle;
class Histogram;
class LinearHistogram;
class BooleanHistogram;
-class ThreadSafeHistogram;
namespace disk_cache {
class StatsHistogram;
@@ -287,15 +209,12 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> {
typedef std::vector<Count> Counts;
typedef std::vector<Sample> Ranges;
- static const int kHexRangePrintingFlag;
-
/* These enums are meant to facilitate deserialization of renderer histograms
into the browser. */
enum ClassType {
HISTOGRAM,
LINEAR_HISTOGRAM,
BOOLEAN_HISTOGRAM,
- THREAD_SAFE_HISTOGRAM,
NOT_VALID_IN_RENDERER
};
@@ -304,6 +223,20 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> {
LINEAR
};
+ enum Flags {
+ kNoFlags = 0,
+ kUmaTargetedHistogramFlag = 0x1, // Histogram should be UMA uploaded.
+
+ // Indicate that the histogram was pickled to be sent across an IPC Channel.
+ // If we observe this flag on a histogram being aggregated into after IPC,
+ // then we are running in a single process mode, and the aggregation should
+ // not take place (as we would be aggregating back into the source
+ // histogram!).
+ kIPCSerializationSourceFlag = 0x10,
+
+ kHexRangePrintingFlag = 0x8000, // Fancy bucket-naming supported.
+ };
+
struct DescriptionPair {
Sample sample;
const char* description; // Null means end of a list of pairs.
@@ -348,10 +281,11 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> {
//----------------------------------------------------------------------------
// minimum should start from 1. 0 is invalid as a minimum. 0 is an implicit
// default underflow bucket.
- static scoped_refptr<Histogram> HistogramFactoryGet(const std::string& name,
- Sample minimum, Sample maximum, size_t bucket_count);
- static scoped_refptr<Histogram> HistogramFactoryGet(const std::string& name,
- base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count);
+ static scoped_refptr<Histogram> FactoryGet(const std::string& name,
+ Sample minimum, Sample maximum, size_t bucket_count, Flags flags);
+ static scoped_refptr<Histogram> FactoryGet(const std::string& name,
+ base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count,
+ Flags flags);
void Add(int value);
@@ -365,9 +299,6 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> {
void AddSampleSet(const SampleSet& sample);
- // This method is an interface, used only by ThreadSafeHistogram.
- virtual void Remove(int value) { DCHECK(false); }
-
// This method is an interface, used only by LinearHistogram.
virtual void SetRangeDescriptions(const DescriptionPair descriptions[])
{ DCHECK(false); }
@@ -380,8 +311,8 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> {
// Support generic flagging of Histograms.
// 0x1 Currently used to mark this histogram to be recorded by UMA..
// 0x8000 means print ranges in hex.
- void SetFlags(int flags) { flags_ |= flags; }
- void ClearFlags(int flags) { flags_ &= ~flags; }
+ void SetFlags(Flags flags) { flags_ = static_cast<Flags> (flags_ | flags); }
+ void ClearFlags(Flags flags) { flags_ = static_cast<Flags>(flags_ & ~flags); }
int flags() const { return flags_; }
// Convenience methods for serializing/deserializing the histograms.
@@ -510,7 +441,7 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> {
size_t bucket_count_; // Dimension of counts_[].
// Flag the histogram for recording by UMA via metric_services.h.
- int flags_;
+ Flags flags_;
// For each index, show the least value that can be stored in the
// corresponding bucket. We also append one extra element in this array,
@@ -539,12 +470,11 @@ class LinearHistogram : public Histogram {
/* minimum should start from 1. 0 is as minimum is invalid. 0 is an implicit
default underflow bucket. */
- static scoped_refptr<Histogram> LinearHistogramFactoryGet(
- const std::string& name, Sample minimum, Sample maximum,
- size_t bucket_count);
- static scoped_refptr<Histogram> LinearHistogramFactoryGet(
- const std::string& name, base::TimeDelta minimum,
- base::TimeDelta maximum, size_t bucket_count);
+ static scoped_refptr<Histogram> FactoryGet(const std::string& name,
+ Sample minimum, Sample maximum, size_t bucket_count, Flags flags);
+ static scoped_refptr<Histogram> FactoryGet(const std::string& name,
+ base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count,
+ Flags flags);
protected:
LinearHistogram(const std::string& name, Sample minimum,
@@ -582,8 +512,8 @@ class LinearHistogram : public Histogram {
// BooleanHistogram is a histogram for booleans.
class BooleanHistogram : public LinearHistogram {
public:
- static scoped_refptr<Histogram> BooleanHistogramFactoryGet(
- const std::string& name);
+ static scoped_refptr<Histogram> FactoryGet(const std::string& name,
+ Flags flags);
virtual ClassType histogram_type() const { return BOOLEAN_HISTOGRAM; }
@@ -591,45 +521,13 @@ class BooleanHistogram : public LinearHistogram {
private:
explicit BooleanHistogram(const std::string& name)
- : LinearHistogram(name, 1, 2, 3) {
+ : LinearHistogram(name, 1, 2, 3) {
}
DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
};
//------------------------------------------------------------------------------
-// This section provides implementation for ThreadSafeHistogram.
-//------------------------------------------------------------------------------
-
-class ThreadSafeHistogram : public Histogram {
- public:
- static scoped_refptr<Histogram> ThreadSafeHistogramFactoryGet(
- const std::string& name, Sample minimum, Sample maximum,
- size_t bucket_count);
-
- virtual ClassType histogram_type() const { return THREAD_SAFE_HISTOGRAM; }
-
- // Provide the analog to Add()
- virtual void Remove(int value);
-
- protected:
- ThreadSafeHistogram(const std::string& name, Sample minimum,
- Sample maximum, size_t bucket_count);
-
- virtual ~ThreadSafeHistogram() {}
-
- // Provide locked versions to get precise counts.
- virtual void Accumulate(Sample value, Count count, size_t index);
-
- virtual void SnapshotSample(SampleSet* sample) const;
-
- private:
- mutable Lock lock_;
-
- DISALLOW_COPY_AND_ASSIGN(ThreadSafeHistogram);
-};
-
-//------------------------------------------------------------------------------
// StatisticsRecorder handles all histograms in the system. It provides a
// general place for histograms to register, and supports a global API for
// accessing (i.e., dumping, or graphing) the data in all the histograms.
diff --git a/base/histogram_unittest.cc b/base/histogram_unittest.cc
index 4d5de51..f702a2e 100644
--- a/base/histogram_unittest.cc
+++ b/base/histogram_unittest.cc
@@ -19,17 +19,15 @@ class HistogramTest : public testing::Test {
// Check for basic syntax and use.
TEST(HistogramTest, StartupShutdownTest) {
// Try basic construction
- scoped_refptr<Histogram> histogram =
- Histogram::HistogramFactoryGet("TestHistogram", 1, 1000, 10);
- scoped_refptr<Histogram> histogram1 =
- Histogram::HistogramFactoryGet("Test1Histogram", 1, 1000, 10);
-
- scoped_refptr<Histogram> linear_histogram =
- LinearHistogram::LinearHistogramFactoryGet("TestLinearHistogram", 1, 1000,
- 10);
- scoped_refptr<Histogram> linear_histogram1 =
- LinearHistogram::LinearHistogramFactoryGet("Test1LinearHistogram", 1,
- 1000, 10);
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "TestHistogram", 1, 1000, 10, Histogram::kNoFlags);
+ scoped_refptr<Histogram> histogram1 = Histogram::FactoryGet(
+ "Test1Histogram", 1, 1000, 10, Histogram::kNoFlags);
+
+ scoped_refptr<Histogram> linear_histogram = LinearHistogram::FactoryGet(
+ "TestLinearHistogram", 1, 1000, 10, Histogram::kNoFlags);
+ scoped_refptr<Histogram> linear_histogram1 = LinearHistogram::FactoryGet(
+ "Test1LinearHistogram", 1, 1000, 10, Histogram::kNoFlags);
// Use standard macros (but with fixed samples)
HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1));
@@ -38,7 +36,7 @@ TEST(HistogramTest, StartupShutdownTest) {
DHISTOGRAM_TIMES("Test4Histogram", TimeDelta::FromDays(1));
DHISTOGRAM_COUNTS("Test5Histogram", 30);
- ASSET_HISTOGRAM_COUNTS("Test6Histogram", 129);
+ HISTOGRAM_ENUMERATION("Test6Histogram", 129, 130);
// Try to construct samples.
Histogram::SampleSet sample1;
@@ -63,23 +61,21 @@ TEST(HistogramTest, RecordedStartupTest) {
EXPECT_EQ(0U, histograms.size());
// Try basic construction
- scoped_refptr<Histogram> histogram =
- Histogram::HistogramFactoryGet("TestHistogram", 1, 1000, 10);
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "TestHistogram", 1, 1000, 10, Histogram::kNoFlags);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(1U, histograms.size());
- scoped_refptr<Histogram> histogram1 =
- Histogram::HistogramFactoryGet("Test1Histogram", 1, 1000, 10);
+ scoped_refptr<Histogram> histogram1 = Histogram::FactoryGet(
+ "Test1Histogram", 1, 1000, 10, Histogram::kNoFlags);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(2U, histograms.size());
- scoped_refptr<Histogram> linear_histogram =
- LinearHistogram::LinearHistogramFactoryGet(
- "TestLinearHistogram", 1, 1000, 10);
- scoped_refptr<Histogram> linear_histogram1 =
- LinearHistogram::LinearHistogramFactoryGet(
- "Test1LinearHistogram", 1, 1000, 10);
+ scoped_refptr<Histogram> linear_histogram = LinearHistogram::FactoryGet(
+ "TestLinearHistogram", 1, 1000, 10, Histogram::kNoFlags);
+ scoped_refptr<Histogram> linear_histogram1 = LinearHistogram::FactoryGet(
+ "Test1LinearHistogram", 1, 1000, 10, Histogram::kNoFlags);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(4U, histograms.size());
@@ -91,7 +87,7 @@ TEST(HistogramTest, RecordedStartupTest) {
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(6U, histograms.size());
- ASSET_HISTOGRAM_COUNTS("TestAssetHistogram", 1000);
+ HISTOGRAM_ENUMERATION("TestEnumerationHistogram", 20, 200);
histograms.clear();
StatisticsRecorder::GetHistograms(&histograms); // Load up lists
EXPECT_EQ(7U, histograms.size());
@@ -114,8 +110,8 @@ TEST(HistogramTest, RangeTest) {
recorder.GetHistograms(&histograms);
EXPECT_EQ(0U, histograms.size());
- scoped_refptr<Histogram> histogram = Histogram::HistogramFactoryGet(
- "Histogram", 1, 64, 8); // As mentioned in header file.
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
// Check that we got a nice exponential when there was enough rooom.
EXPECT_EQ(0, histogram->ranges(0));
int power_of_2 = 1;
@@ -125,51 +121,48 @@ TEST(HistogramTest, RangeTest) {
}
EXPECT_EQ(INT_MAX, histogram->ranges(8));
- scoped_refptr<Histogram> short_histogram =
- Histogram::HistogramFactoryGet("Histogram Shortened", 1, 7, 8);
+ scoped_refptr<Histogram> short_histogram = Histogram::FactoryGet(
+ "Histogram Shortened", 1, 7, 8, Histogram::kNoFlags);
// Check that when the number of buckets is short, we get a linear histogram
// for lack of space to do otherwise.
for (int i = 0; i < 8; i++)
EXPECT_EQ(i, short_histogram->ranges(i));
EXPECT_EQ(INT_MAX, short_histogram->ranges(8));
- scoped_refptr<Histogram> linear_histogram =
- LinearHistogram::LinearHistogramFactoryGet("Linear", 1, 7, 8);
+ scoped_refptr<Histogram> linear_histogram = LinearHistogram::FactoryGet(
+ "Linear", 1, 7, 8, Histogram::kNoFlags);
// We also get a nice linear set of bucket ranges when we ask for it
for (int i = 0; i < 8; i++)
EXPECT_EQ(i, linear_histogram->ranges(i));
EXPECT_EQ(INT_MAX, linear_histogram->ranges(8));
- scoped_refptr<Histogram> linear_broad_histogram =
- LinearHistogram::LinearHistogramFactoryGet(
- "Linear widened", 2, 14, 8);
+ scoped_refptr<Histogram> linear_broad_histogram = LinearHistogram::FactoryGet(
+ "Linear widened", 2, 14, 8, Histogram::kNoFlags);
// ...but when the list has more space, then the ranges naturally spread out.
for (int i = 0; i < 8; i++)
EXPECT_EQ(2 * i, linear_broad_histogram->ranges(i));
EXPECT_EQ(INT_MAX, linear_broad_histogram->ranges(8));
- scoped_refptr<Histogram> threadsafe_histogram =
- ThreadSafeHistogram::ThreadSafeHistogramFactoryGet("ThreadSafe", 1, 32,
- 15);
+ scoped_refptr<Histogram> transitioning_histogram =
+ Histogram::FactoryGet("LinearAndExponential", 1, 32, 15,
+ Histogram::kNoFlags);
// When space is a little tight, we transition from linear to exponential.
- // This is what happens in both the basic histogram, and the threadsafe
- // variant (which is derived).
- EXPECT_EQ(0, threadsafe_histogram->ranges(0));
- EXPECT_EQ(1, threadsafe_histogram->ranges(1));
- EXPECT_EQ(2, threadsafe_histogram->ranges(2));
- EXPECT_EQ(3, threadsafe_histogram->ranges(3));
- EXPECT_EQ(4, threadsafe_histogram->ranges(4));
- EXPECT_EQ(5, threadsafe_histogram->ranges(5));
- EXPECT_EQ(6, threadsafe_histogram->ranges(6));
- EXPECT_EQ(7, threadsafe_histogram->ranges(7));
- EXPECT_EQ(9, threadsafe_histogram->ranges(8));
- EXPECT_EQ(11, threadsafe_histogram->ranges(9));
- EXPECT_EQ(14, threadsafe_histogram->ranges(10));
- EXPECT_EQ(17, threadsafe_histogram->ranges(11));
- EXPECT_EQ(21, threadsafe_histogram->ranges(12));
- EXPECT_EQ(26, threadsafe_histogram->ranges(13));
- EXPECT_EQ(32, threadsafe_histogram->ranges(14));
- EXPECT_EQ(INT_MAX, threadsafe_histogram->ranges(15));
+ EXPECT_EQ(0, transitioning_histogram->ranges(0));
+ EXPECT_EQ(1, transitioning_histogram->ranges(1));
+ EXPECT_EQ(2, transitioning_histogram->ranges(2));
+ EXPECT_EQ(3, transitioning_histogram->ranges(3));
+ EXPECT_EQ(4, transitioning_histogram->ranges(4));
+ EXPECT_EQ(5, transitioning_histogram->ranges(5));
+ EXPECT_EQ(6, transitioning_histogram->ranges(6));
+ EXPECT_EQ(7, transitioning_histogram->ranges(7));
+ EXPECT_EQ(9, transitioning_histogram->ranges(8));
+ EXPECT_EQ(11, transitioning_histogram->ranges(9));
+ EXPECT_EQ(14, transitioning_histogram->ranges(10));
+ EXPECT_EQ(17, transitioning_histogram->ranges(11));
+ EXPECT_EQ(21, transitioning_histogram->ranges(12));
+ EXPECT_EQ(26, transitioning_histogram->ranges(13));
+ EXPECT_EQ(32, transitioning_histogram->ranges(14));
+ EXPECT_EQ(INT_MAX, transitioning_histogram->ranges(15));
recorder.GetHistograms(&histograms);
EXPECT_EQ(5U, histograms.size());
@@ -178,8 +171,8 @@ TEST(HistogramTest, RangeTest) {
// Make sure histogram handles out-of-bounds data gracefully.
TEST(HistogramTest, BoundsTest) {
const size_t kBucketCount = 50;
- scoped_refptr<Histogram> histogram = Histogram::HistogramFactoryGet("Bounded",
- 10, 100, kBucketCount);
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "Bounded", 10, 100, kBucketCount, Histogram::kNoFlags);
// Put two samples "out of bounds" above and below.
histogram->Add(5);
@@ -201,8 +194,8 @@ TEST(HistogramTest, BoundsTest) {
// Check to be sure samples land as expected is "correct" buckets.
TEST(HistogramTest, BucketPlacementTest) {
- scoped_refptr<Histogram> histogram = Histogram::HistogramFactoryGet(
- "Histogram", 1, 64, 8); // As mentioned in header file.
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ "Histogram", 1, 64, 8, Histogram::kNoFlags); // As per header file.
// Check that we got a nice exponential since there was enough rooom.
EXPECT_EQ(0, histogram->ranges(0));
@@ -231,84 +224,5 @@ TEST(HistogramTest, BucketPlacementTest) {
EXPECT_EQ(i + 1, sample.counts(i));
}
-static const char kAssetTestHistogramName[] = "AssetCountTest";
-static const char kAssetTestDebugHistogramName[] = "DAssetCountTest";
-void AssetCountFunction(int sample) {
- ASSET_HISTOGRAM_COUNTS(kAssetTestHistogramName, sample);
- DASSET_HISTOGRAM_COUNTS(kAssetTestDebugHistogramName, sample);
-}
-// Check that asset can be added and removed from buckets.
-TEST(HistogramTest, AssetCountTest) {
- // Start up a recorder system to identify all histograms.
- StatisticsRecorder recorder;
-
- // Call through the macro to instantiate the static variables.
- AssetCountFunction(100); // Put a sample in the bucket for 100.
-
- // Find the histogram.
- StatisticsRecorder::Histograms histogram_list;
- StatisticsRecorder::GetHistograms(&histogram_list);
- ASSERT_NE(0U, histogram_list.size());
- const Histogram* our_histogram = NULL;
- const Histogram* our_debug_histogram = NULL;
- for (StatisticsRecorder::Histograms::iterator it = histogram_list.begin();
- it != histogram_list.end();
- ++it) {
- if (!(*it)->histogram_name().compare(kAssetTestHistogramName))
- our_histogram = *it;
- else if (!(*it)->histogram_name().compare(kAssetTestDebugHistogramName)) {
- our_debug_histogram = *it;
- }
- }
- ASSERT_TRUE(our_histogram);
-#ifndef NDEBUG
- EXPECT_TRUE(our_debug_histogram);
-#else
- EXPECT_FALSE(our_debug_histogram);
-#endif
- // Verify it has a 1 in exactly one bucket (where we put the sample).
- Histogram::SampleSet sample;
- our_histogram->SnapshotSample(&sample);
- int match_count = 0;
- for (size_t i = 0; i < our_histogram->bucket_count(); ++i) {
- if (sample.counts(i) > 0) {
- EXPECT_LT(++match_count, 2) << "extra count in bucket " << i;
- }
- }
- EXPECT_EQ(1, match_count);
-
- // Remove our sample.
- AssetCountFunction(-100); // Remove a sample from the bucket for 100.
- our_histogram->SnapshotSample(&sample); // Extract data set.
-
- // Verify that the bucket is now empty, as are all the other buckets.
- for (size_t i = 0; i < our_histogram->bucket_count(); ++i) {
- EXPECT_EQ(0, sample.counts(i)) << "extra count in bucket " << i;
- }
-
- if (!our_debug_histogram)
- return; // This is a production build.
-
- // Repeat test with debug histogram. Note that insertion and deletion above
- // should have cancelled each other out.
- AssetCountFunction(100); // Add a sample into the bucket for 100.
- our_debug_histogram->SnapshotSample(&sample);
- match_count = 0;
- for (size_t i = 0; i < our_debug_histogram->bucket_count(); ++i) {
- if (sample.counts(i) > 0) {
- EXPECT_LT(++match_count, 2) << "extra count in bucket " << i;
- }
- }
- EXPECT_EQ(1, match_count);
-
- // Remove our sample.
- AssetCountFunction(-100); // Remove a sample from the bucket for 100.
- our_debug_histogram->SnapshotSample(&sample); // Extract data set.
-
- // Verify that the bucket is now empty, as are all the other buckets.
- for (size_t i = 0; i < our_debug_histogram->bucket_count(); ++i) {
- EXPECT_EQ(0, sample.counts(i)) << "extra count in bucket " << i;
- }
-}
} // namespace
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 64913e5..9799100 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -265,7 +265,7 @@ void MessageLoop::PostTask_Helper(
pending_task.delayed_run_time =
Time::Now() + TimeDelta::FromMilliseconds(delay_ms);
} else {
- DCHECK(delay_ms == 0) << "delay should not be negative";
+ DCHECK_EQ(delay_ms, 0) << "delay should not be negative";
}
// Warning: Don't try to short-circuit, and handle this thread's tasks more
@@ -531,13 +531,10 @@ void MessageLoop::StartHistogrammer() {
if (enable_histogrammer_ && !message_histogram_.get()
&& StatisticsRecorder::WasStarted()) {
DCHECK(!thread_name_.empty());
- message_histogram_ =
- LinearHistogram::LinearHistogramFactoryGet(
- ("MsgLoop:" + thread_name_),
- kLeastNonZeroMessageId,
- kMaxMessageId,
- kNumberOfDistinctMessagesDisplayed);
- message_histogram_->SetFlags(message_histogram_->kHexRangePrintingFlag);
+ message_histogram_ = LinearHistogram::FactoryGet("MsgLoop:" + thread_name_,
+ kLeastNonZeroMessageId, kMaxMessageId,
+ kNumberOfDistinctMessagesDisplayed,
+ message_histogram_->kHexRangePrintingFlag);
message_histogram_->SetRangeDescriptions(event_descriptions_);
}
}
diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm
index ce7be61..f373e11 100644
--- a/chrome/browser/chrome_browser_application_mac.mm
+++ b/chrome/browser/chrome_browser_application_mac.mm
@@ -112,11 +112,8 @@ size_t BinForException(NSException* exception) {
}
void RecordExceptionWithUma(NSException* exception) {
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet("OSX.NSException",
- 0, kUnknownNSException, kUnknownNSException + 1);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(BinForException(exception));
+ UMA_HISTOGRAM_ENUMERATION("OSX.NSException",
+ BinForException(exception), kUnknownNSException);
}
void Terminate() {
diff --git a/chrome/browser/chrome_browser_application_mac_unittest.mm b/chrome/browser/chrome_browser_application_mac_unittest.mm
index 7fc134e..d5f26c5 100644
--- a/chrome/browser/chrome_browser_application_mac_unittest.mm
+++ b/chrome/browser/chrome_browser_application_mac_unittest.mm
@@ -65,7 +65,7 @@ TEST(ChromeApplicationMacTest, RecordException) {
// We should have exactly the right number of exceptions.
StatisticsRecorder::GetSnapshot("OSX.NSException", &histograms);
EXPECT_EQ(1U, histograms.size());
- EXPECT_EQ(kUmaTargetedHistogramFlag, histograms[0]->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histograms[0]->flags());
Histogram::SampleSet sample;
histograms[0]->SnapshotSample(&sample);
EXPECT_EQ(4, sample.counts(0));
diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc
index b266002..fbefc33 100644
--- a/chrome/browser/diagnostics/sqlite_diagnostics.cc
+++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc
@@ -43,11 +43,7 @@ class BasicSqliteErrrorHandler : public sql::ErrorDelegate {
static void RecordErrorInHistogram(int error) {
// The histogram values from sqlite result codes go currently from 1 to
// 26 currently but 50 gives them room to grow.
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet(kHistogramNames[unique], 1,
- 50, 51);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(error);
+ UMA_HISTOGRAM_ENUMERATION(kHistogramNames[unique], error, 50);
}
};
diff --git a/chrome/browser/jankometer.cc b/chrome/browser/jankometer.cc
index 6d396ef..d0473da 100644
--- a/chrome/browser/jankometer.cc
+++ b/chrome/browser/jankometer.cc
@@ -92,14 +92,12 @@ class JankObserver : public base::RefCountedThreadSafe<JankObserver>,
slow_processing_counter_(std::string("Chrome.SlowMsg") + thread_name),
queueing_delay_counter_(std::string("Chrome.DelayMsg") + thread_name),
total_time_watchdog_(excessive_duration, thread_name, watchdog_enable) {
- process_times_ = Histogram::HistogramFactoryGet(
- (std::string("Chrome.ProcMsgL ") + thread_name),
- 1, 3600000, 50);
- total_times_ = Histogram::HistogramFactoryGet(
- (std::string("Chrome.TotalMsgL ") + thread_name),
- 1, 3600000, 50);
- process_times_->SetFlags(kUmaTargetedHistogramFlag);
- total_times_->SetFlags(kUmaTargetedHistogramFlag);
+ process_times_ = Histogram::FactoryGet(
+ std::string("Chrome.ProcMsgL ") + thread_name,
+ 1, 3600000, 50, Histogram::kUmaTargetedHistogramFlag);
+ total_times_ = Histogram::FactoryGet(
+ std::string("Chrome.TotalMsgL ") + thread_name,
+ 1, 3600000, 50, Histogram::kUmaTargetedHistogramFlag);
}
// Attaches the observer to the current thread's message loop. You can only
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 2a1b589..610792c 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -1877,7 +1877,7 @@ void MetricsService::RecordCurrentHistograms() {
for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
histograms.end() != it;
++it) {
- if ((*it)->flags() & kUmaTargetedHistogramFlag)
+ if ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag)
// TODO(petersont): Only record historgrams if they are not precluded by
// the UMA response data.
// Bug http://code.google.com/p/chromium/issues/detail?id=2739.
diff --git a/chrome/browser/net/dns_host_info.cc b/chrome/browser/net/dns_host_info.cc
index 755f54d..8946f7f 100644
--- a/chrome/browser/net/dns_host_info.cc
+++ b/chrome/browser/net/dns_host_info.cc
@@ -104,10 +104,9 @@ void DnsHostInfo::RemoveFromQueue() {
}
// Make a custom linear histogram for the region from 0 to boundary.
const size_t kBucketCount = 52;
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet("DNS.QueueRecycledUnder2",
- TimeDelta(), kBoundary, kBucketCount);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
+ static scoped_refptr<Histogram> histogram = LinearHistogram::FactoryGet(
+ "DNS.QueueRecycledUnder2", TimeDelta(), kBoundary, kBucketCount,
+ Histogram::kUmaTargetedHistogramFlag);
histogram->AddTime(queue_duration_);
}
diff --git a/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc b/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc
index 8d03b6f..845d448 100644
--- a/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc
+++ b/chrome/browser/net/websocket_experiment/websocket_experiment_runner.cc
@@ -28,36 +28,27 @@ static const int kWebSocketTimeSec = 10;
static const int kTimeBucketCount = 50;
// TODO(ukai): Use new thread-safe-reference-counted Histograms.
-#define UPDATE_HISTOGRAM(name, sample, min, max, bucket_count) do { \
+#define UPDATE_HISTOGRAM_ENUMS(name, sample, boundary_value) do { \
switch (task_state_) { \
case STATE_RUN_WS: \
{ \
- static scoped_refptr<Histogram> counter = \
- LinearHistogram::LinearHistogramFactoryGet(\
- "WebSocketExperiment.Basic." name, \
- min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
+ UMA_HISTOGRAM_ENUMERATION( \
+ "WebSocketExperiment.Basic." name, \
+ sample, boundary_value); \
} \
break; \
case STATE_RUN_WSS: \
{ \
- static scoped_refptr<Histogram> counter = \
- LinearHistogram::LinearHistogramFactoryGet(\
- "WebSocketExperiment.Secure." name, \
- min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
+ UMA_HISTOGRAM_ENUMERATION( \
+ "WebSocketExperiment.Secure." name, \
+ sample, boundary_value); \
} \
break; \
case STATE_RUN_WS_NODEFAULT_PORT: \
{ \
- static scoped_refptr<Histogram> counter = \
- LinearHistogram::LinearHistogramFactoryGet(\
- "WebSocketExperiment.NoDefaultPort." name, \
- min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
+ UMA_HISTOGRAM_ENUMERATION( \
+ "WebSocketExperiment.NoDefaultPort." name, \
+ sample, boundary_value); \
} \
break; \
default: \
@@ -70,32 +61,23 @@ static const int kTimeBucketCount = 50;
switch (task_state_) { \
case STATE_RUN_WS: \
{ \
- static scoped_refptr<Histogram> counter = \
- Histogram::HistogramFactoryGet(\
- "WebSocketExperiment.Basic." name, \
- min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->AddTime(sample); \
+ UMA_HISTOGRAM_CUSTOM_TIMES( \
+ "WebSocketExperiment.Basic." name, \
+ sample, min, max, bucket_count); \
} \
break; \
case STATE_RUN_WSS: \
{ \
- static scoped_refptr<Histogram> counter = \
- Histogram::HistogramFactoryGet(\
- "WebSocketExperiment.Secure." name, \
- min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->AddTime(sample); \
+ UMA_HISTOGRAM_CUSTOM_TIMES( \
+ "WebSocketExperiment.Secure." name, \
+ sample, min, max, bucket_count); \
} \
break; \
case STATE_RUN_WS_NODEFAULT_PORT: \
{ \
- static scoped_refptr<Histogram> counter = \
- Histogram::HistogramFactoryGet(\
- "WebSocketExperiment.NoDefaultPort." name, \
- min, max, bucket_count); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->AddTime(sample); \
+ UMA_HISTOGRAM_CUSTOM_TIMES( \
+ "WebSocketExperiment.NoDefaultPort." name, \
+ sample, min, max, bucket_count); \
} \
break; \
default: \
@@ -277,9 +259,8 @@ void WebSocketExperimentRunner::UpdateTaskResultHistogram(
DCHECK(task);
const WebSocketExperimentTask::Result& task_result = task->result();
- UPDATE_HISTOGRAM("LastState", task_result.last_state,
- 1, WebSocketExperimentTask::NUM_STATES,
- WebSocketExperimentTask::NUM_STATES + 1);
+ UPDATE_HISTOGRAM_ENUMS("LastState", task_result.last_state,
+ WebSocketExperimentTask::NUM_STATES);
UPDATE_HISTOGRAM_TIMES("UrlFetch", task_result.url_fetch,
base::TimeDelta::FromMilliseconds(1),
diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc
index 6cf4430..d58bed5 100644
--- a/chrome/browser/renderer_host/buffered_resource_handler.cc
+++ b/chrome/browser/renderer_host/buffered_resource_handler.cc
@@ -30,22 +30,19 @@ const int kMaxBytesToSniff = 512;
void RecordSnifferMetrics(bool sniffing_blocked,
bool we_would_like_to_sniff,
const std::string& mime_type) {
- static scoped_refptr<Histogram> nosniff_usage =
- BooleanHistogram::BooleanHistogramFactoryGet("nosniff.usage");
- nosniff_usage->SetFlags(kUmaTargetedHistogramFlag);
+ static scoped_refptr<Histogram> nosniff_usage = BooleanHistogram::FactoryGet(
+ "nosniff.usage", Histogram::kUmaTargetedHistogramFlag);
nosniff_usage->AddBoolean(sniffing_blocked);
if (sniffing_blocked) {
static scoped_refptr<Histogram> nosniff_otherwise =
- BooleanHistogram::BooleanHistogramFactoryGet(
- "nosniff.otherwise");
- nosniff_otherwise->SetFlags(kUmaTargetedHistogramFlag);
+ BooleanHistogram::FactoryGet("nosniff.otherwise",
+ Histogram::kUmaTargetedHistogramFlag);
nosniff_otherwise->AddBoolean(we_would_like_to_sniff);
static scoped_refptr<Histogram> nosniff_empty_mime_type =
- BooleanHistogram::BooleanHistogramFactoryGet(
- "nosniff.empty_mime_type");
- nosniff_empty_mime_type->SetFlags(kUmaTargetedHistogramFlag);
+ BooleanHistogram::FactoryGet("nosniff.empty_mime_type",
+ Histogram::kUmaTargetedHistogramFlag);
nosniff_empty_mime_type->AddBoolean(mime_type.empty());
}
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
index 3f559c0..04aa1b1 100644
--- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
@@ -66,14 +66,11 @@ enum SafeBrowsingBlockingPageEvent {
SHOW,
PROCEED,
DONT_PROCEED,
+ UNUSED_ENUM,
};
void RecordSafeBrowsingBlockingPageStats(SafeBrowsingBlockingPageEvent event) {
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet("interstial.safe_browsing",
- 1, 2, 3);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(event);
+ UMA_HISTOGRAM_ENUMERATION("interstial.safe_browsing", event, UNUSED_ENUM);
}
} // namespace
diff --git a/chrome/browser/ssl/ssl_blocking_page.cc b/chrome/browser/ssl/ssl_blocking_page.cc
index d0f3d6a..c443600 100644
--- a/chrome/browser/ssl/ssl_blocking_page.cc
+++ b/chrome/browser/ssl/ssl_blocking_page.cc
@@ -31,14 +31,11 @@ enum SSLBlockingPageEvent {
SHOW,
PROCEED,
DONT_PROCEED,
+ UNUSED_ENUM,
};
void RecordSSLBlockingPageStats(SSLBlockingPageEvent event) {
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet(
- "interstial.ssl", 1, 2, 3);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(event);
+ UMA_HISTOGRAM_ENUMERATION("interstial.ssl", event, UNUSED_ENUM);
}
} // namespace
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index ae824c28..02bf47c 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -467,12 +467,7 @@ void ProfileSyncService::RemoveObserver(Observer* observer) {
}
void ProfileSyncService::SyncEvent(SyncEventCodes code) {
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet("Sync.EventCodes",
- MIN_SYNC_EVENT_CODE + 1, MAX_SYNC_EVENT_CODE - 1,
- MAX_SYNC_EVENT_CODE);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(code);
+ UMA_HISTOGRAM_ENUMERATION("Sync.EventCodes", code, MAX_SYNC_EVENT_CODE);
}
bool ProfileSyncService::IsSyncEnabled() {
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index d1ce79d..632adab 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -505,13 +505,11 @@ static void* CreateHistogram(
const char *name, int min, int max, size_t buckets) {
if (min <= 0)
min = 1;
- scoped_refptr<Histogram> histogram =
- Histogram::HistogramFactoryGet(name, min, max, buckets);
- // We verify this was not being destructed by setting a novel "PlannedLeak"
- // flag and watching out for the flag in the destructor.
- histogram->SetFlags(kUmaTargetedHistogramFlag | kPlannedLeakFlag);
+ scoped_refptr<Histogram> histogram = Histogram::FactoryGet(
+ name, min, max, buckets, Histogram::kUmaTargetedHistogramFlag);
// We'll end up leaking these histograms, unless there is some code hiding in
// there to do the dec-ref.
+ // TODO(jar): Handle reference counting in webkit glue.
histogram->AddRef();
return histogram.get();
}
diff --git a/net/base/connection_type_histograms.cc b/net/base/connection_type_histograms.cc
index 81affa5..7326a92 100644
--- a/net/base/connection_type_histograms.cc
+++ b/net/base/connection_type_histograms.cc
@@ -22,30 +22,20 @@ namespace net {
// expansion.
void UpdateConnectionTypeHistograms(ConnectionType type, bool success) {
static bool had_connection_type[NUM_OF_CONNECTION_TYPES];
- static scoped_refptr<Histogram> had_histogram =
- LinearHistogram::LinearHistogramFactoryGet("Net.HadConnectionType2",
- 1, NUM_OF_CONNECTION_TYPES,
- NUM_OF_CONNECTION_TYPES + 1);
- static scoped_refptr<Histogram> success_histogram =
- LinearHistogram::LinearHistogramFactoryGet("Net.ConnectionTypeCount2",
- 1, NUM_OF_CONNECTION_TYPES,
- NUM_OF_CONNECTION_TYPES + 1);
- static scoped_refptr<Histogram> failed_histogram =
- LinearHistogram::LinearHistogramFactoryGet("Net.ConnectionTypeFailCount2",
- 1, NUM_OF_CONNECTION_TYPES,
- NUM_OF_CONNECTION_TYPES + 1);
if (type >= 0 && type < NUM_OF_CONNECTION_TYPES) {
if (!had_connection_type[type]) {
had_connection_type[type] = true;
- had_histogram->SetFlags(kUmaTargetedHistogramFlag);
- had_histogram->Add(type);
+ UMA_HISTOGRAM_ENUMERATION("Net.HadConnectionType2",
+ type, NUM_OF_CONNECTION_TYPES);
}
- Histogram* histogram;
- histogram = success ? success_histogram.get() : failed_histogram.get();
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(type);
+ if (success)
+ UMA_HISTOGRAM_ENUMERATION("Net.ConnectionTypeCount2",
+ type, NUM_OF_CONNECTION_TYPES);
+ else
+ UMA_HISTOGRAM_ENUMERATION("Net.ConnectionTypeFailCount2",
+ type, NUM_OF_CONNECTION_TYPES);
} else {
NOTREACHED(); // Someone's logging an invalid type!
}
diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc
index df0f171..8e063cb 100644
--- a/net/base/mime_sniffer.cc
+++ b/net/base/mime_sniffer.cc
@@ -213,9 +213,8 @@ static const MagicNumber kSniffableTags[] = {
static scoped_refptr<Histogram> UMASnifferHistogramGet(const char* name,
int array_size) {
scoped_refptr<Histogram> counter =
- LinearHistogram::LinearHistogramFactoryGet(
- name, 1, array_size - 1, array_size);
- counter->SetFlags(kUmaTargetedHistogramFlag);
+ LinearHistogram::FactoryGet(name, 1, array_size - 1, array_size,
+ Histogram::kUmaTargetedHistogramFlag);
return counter;
}
diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc
index 126a1b6..b279749 100644
--- a/net/base/sdch_manager.cc
+++ b/net/base/sdch_manager.cc
@@ -32,11 +32,7 @@ SdchManager* SdchManager::Global() {
// static
void SdchManager::SdchErrorRecovery(ProblemCodes problem) {
- static scoped_refptr<Histogram> histogram =
- LinearHistogram::LinearHistogramFactoryGet("Sdch3.ProblemCodes_4",
- MIN_PROBLEM_CODE + 1, MAX_PROBLEM_CODE - 1, MAX_PROBLEM_CODE);
- histogram->SetFlags(kUmaTargetedHistogramFlag);
- histogram->Add(problem);
+ UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE);
}
// static
diff --git a/net/disk_cache/histogram_macros.h b/net/disk_cache/histogram_macros.h
index 6d63dc8..17cd345 100644
--- a/net/disk_cache/histogram_macros.h
+++ b/net/disk_cache/histogram_macros.h
@@ -25,13 +25,8 @@
#define UMA_HISTOGRAM_AGE_MS(name, initial_time)\
UMA_HISTOGRAM_TIMES(name, Time::Now() - initial_time)
-#define UMA_HISTOGRAM_CACHE_ERROR(name, sample) do { \
- static scoped_refptr<Histogram> counter = \
- LinearHistogram::LinearHistogramFactoryGet(\
- (name), 1, 49, 50); \
- counter->SetFlags(kUmaTargetedHistogramFlag); \
- counter->Add(sample); \
- } while (0)
+#define UMA_HISTOGRAM_CACHE_ERROR(name, sample) \
+ UMA_HISTOGRAM_ENUMERATION(name, sample, 50)
#ifdef NET_DISK_CACHE_BACKEND_IMPL_CC_
#define BACKEND_OBJ this
diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc
index 44f1aa1..ec87b8c 100644
--- a/net/ftp/ftp_network_transaction.cc
+++ b/net/ftp/ftp_network_transaction.cc
@@ -1146,18 +1146,14 @@ int FtpNetworkTransaction::DoDataReadComplete(int result) {
return result;
}
-// We're using a histogram as a group of counters. We're only interested in
-// the values of the counters. Ignore the shape, average, and standard
-// deviation of the histograms because they are meaningless.
+// We're using a histogram as a group of counters, with one bucket for each
+// enumeration value. We're only interested in the values of the counters.
+// Ignore the shape, average, and standard deviation of the histograms because
+// they are meaningless.
//
-// We use two groups of counters. In the first group (counter1), each counter
-// is a boolean (0 or 1) that indicates whether the user has seen an error
-// of that type during that session. In the second group (counter2), each
-// counter is the number of errors of that type the user has seen during
-// that session.
-//
-// Each histogram has an unused bucket at the end to allow seamless future
-// expansion.
+// We use two histograms. In the first histogram we tally whether the user has
+// seen an error of that type during the session. In the second histogram we
+// tally the total number of times the users sees each errer.
void FtpNetworkTransaction::RecordDataConnectionError(int result) {
// Gather data for http://crbug.com/3073. See how many users have trouble
// establishing FTP data connection in passive FTP mode.
@@ -1205,23 +1201,15 @@ void FtpNetworkTransaction::RecordDataConnectionError(int result) {
break;
};
static bool had_error_type[NUM_OF_NET_ERROR_TYPES];
- static scoped_refptr<Histogram> error_flagged =
- LinearHistogram::LinearHistogramFactoryGet(
- "Net.FtpDataConnectionErrorHappened",
- 1, NUM_OF_NET_ERROR_TYPES, NUM_OF_NET_ERROR_TYPES + 1);
- static scoped_refptr<Histogram> error_counter =
- LinearHistogram::LinearHistogramFactoryGet(
- "Net.FtpDataConnectionErrorCount",
- 1, NUM_OF_NET_ERROR_TYPES, NUM_OF_NET_ERROR_TYPES + 1);
DCHECK(type >= 0 && type < NUM_OF_NET_ERROR_TYPES);
if (!had_error_type[type]) {
had_error_type[type] = true;
- error_flagged->SetFlags(kUmaTargetedHistogramFlag);
- error_flagged->Add(type);
+ UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened",
+ type, NUM_OF_NET_ERROR_TYPES);
}
- error_counter->SetFlags(kUmaTargetedHistogramFlag);
- error_counter->Add(type);
+ UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount",
+ type, NUM_OF_NET_ERROR_TYPES);
}
} // namespace net
diff --git a/net/ftp/ftp_server_type_histograms.cc b/net/ftp/ftp_server_type_histograms.cc
index 60ab9b9..de90d72 100644
--- a/net/ftp/ftp_server_type_histograms.cc
+++ b/net/ftp/ftp_server_type_histograms.cc
@@ -8,38 +8,26 @@
namespace net {
-// We're using a histogram as a group of counters. We're only interested in
-// the values of the counters. Ignore the shape, average, and standard
-// deviation of the histograms because they are meaningless.
+// We're using a histogram as a group of counters, with one bucket for each
+// enumeration value. We're only interested in the values of the counters.
+// Ignore the shape, average, and standard deviation of the histograms because
+// they are meaningless.
//
-// We use two groups of counters. In the first group (counter1), each counter
-// is a boolean (0 or 1) that indicates whether the user has seen an FTP server
-// of that type during that session. In the second group (counter2), each
-// counter is the number of transactions with FTP server of that type the user
-// has made during that session.
-//
-// Each histogram has an unused bucket at the end to allow seamless future
-// expansion.
+// We use two histograms. In the first histogram we tally whether the user has
+// seen an FTP server of a given type during that session. In the second
+// histogram we tally the number of transactions with FTP server of a given type
+// the user has made during that session.
void UpdateFtpServerTypeHistograms(FtpServerType type) {
static bool had_server_type[NUM_OF_SERVER_TYPES];
- static scoped_refptr<Histogram> counter1 =
- LinearHistogram::LinearHistogramFactoryGet("Net.HadFtpServerType",
- 1, NUM_OF_SERVER_TYPES,
- NUM_OF_SERVER_TYPES + 1);
- static scoped_refptr<Histogram> counter2 =
- LinearHistogram::LinearHistogramFactoryGet("Net.FtpServerTypeCount",
- 1, NUM_OF_SERVER_TYPES,
- NUM_OF_SERVER_TYPES + 1);
-
if (type >= 0 && type < NUM_OF_SERVER_TYPES) {
if (!had_server_type[type]) {
had_server_type[type] = true;
- counter1->SetFlags(kUmaTargetedHistogramFlag);
- counter1->Add(type);
+ UMA_HISTOGRAM_ENUMERATION("Net.HadFtpServerType",
+ type, NUM_OF_SERVER_TYPES);
}
}
- counter2->SetFlags(kUmaTargetedHistogramFlag);
- counter2->Add(type);
+ UMA_HISTOGRAM_ENUMERATION("Net.FtpServerTypeCount",
+ type, NUM_OF_SERVER_TYPES);
}
} // namespace net
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index eb50716..d61188a 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -1157,22 +1157,13 @@ void HttpNetworkTransaction::LogTCPConnectedMetrics(
100);
}
- static scoped_refptr<Histogram> tcp_socket_type_counter =
- LinearHistogram::LinearHistogramFactoryGet(
- "Net.TCPSocketType",
- 1, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1);
- tcp_socket_type_counter->SetFlags(kUmaTargetedHistogramFlag);
- tcp_socket_type_counter->Add(handle.reuse_type());
+ UMA_HISTOGRAM_ENUMERATION("Net.TCPSocketType", handle.reuse_type(),
+ ClientSocketHandle::NUM_TYPES);
if (use_late_binding_histogram) {
- static scoped_refptr<Histogram> tcp_socket_type_counter2 =
- LinearHistogram::LinearHistogramFactoryGet(
- FieldTrial::MakeName("Net.TCPSocketType",
- "SocketLateBinding").data(),
- 1, ClientSocketHandle::NUM_TYPES,
- ClientSocketHandle::NUM_TYPES + 1);
- tcp_socket_type_counter2->SetFlags(kUmaTargetedHistogramFlag);
- tcp_socket_type_counter2->Add(handle.reuse_type());
+ UMA_HISTOGRAM_ENUMERATION(
+ FieldTrial::MakeName("Net.TCPSocketType", "SocketLateBinding"),
+ handle.reuse_type(), ClientSocketHandle::NUM_TYPES);
}
UMA_HISTOGRAM_CLIPPED_TIMES(
@@ -1230,22 +1221,14 @@ void HttpNetworkTransaction::LogIOErrorMetrics(
static const bool use_late_binding_histogram =
!FieldTrial::MakeName("", "SocketLateBinding").empty();
- static scoped_refptr<Histogram> io_error_socket_type_counter =
- LinearHistogram::LinearHistogramFactoryGet(
- "Net.IOError_SocketReuseType",
- 1, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1);
- io_error_socket_type_counter->SetFlags(kUmaTargetedHistogramFlag);
- io_error_socket_type_counter->Add(handle.reuse_type());
+ UMA_HISTOGRAM_ENUMERATION("Net.IOError_SocketReuseType",
+ handle.reuse_type(), ClientSocketHandle::NUM_TYPES);
if (use_late_binding_histogram) {
- static scoped_refptr<Histogram> io_error_socket_type_counter =
- LinearHistogram::LinearHistogramFactoryGet(
- FieldTrial::MakeName("Net.IOError_SocketReuseType",
- "SocketLateBinding").data(),
- 1, ClientSocketHandle::NUM_TYPES,
- ClientSocketHandle::NUM_TYPES + 1);
- io_error_socket_type_counter->SetFlags(kUmaTargetedHistogramFlag);
- io_error_socket_type_counter->Add(handle.reuse_type());
+ UMA_HISTOGRAM_ENUMERATION(
+ FieldTrial::MakeName("Net.IOError_SocketReuseType",
+ "SocketLateBinding"),
+ handle.reuse_type(), ClientSocketHandle::NUM_TYPES);
}
switch (handle.reuse_type()) {
diff --git a/net/socket_stream/socket_stream_metrics.cc b/net/socket_stream/socket_stream_metrics.cc
index 6220eb5..625a491 100644
--- a/net/socket_stream/socket_stream_metrics.cc
+++ b/net/socket_stream/socket_stream_metrics.cc
@@ -83,21 +83,13 @@ void SocketStreamMetrics::OnClose() {
}
void SocketStreamMetrics::CountProtocolType(ProtocolType protocol_type) {
- static scoped_refptr<Histogram> counter =
- LinearHistogram::LinearHistogramFactoryGet(
- "Net.SocketStream.ProtocolType",
- 0, NUM_PROTOCOL_TYPES, NUM_PROTOCOL_TYPES + 1);
- counter->SetFlags(kUmaTargetedHistogramFlag);
- counter->Add(protocol_type);
+ UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ProtocolType",
+ protocol_type, NUM_PROTOCOL_TYPES);
}
void SocketStreamMetrics::CountConnectionType(ConnectionType connection_type) {
- static scoped_refptr<Histogram> counter =
- LinearHistogram::LinearHistogramFactoryGet(
- "Net.SocketStream.ConnectionType",
- 1, NUM_CONNECTION_TYPES, NUM_CONNECTION_TYPES + 1);
- counter->SetFlags(kUmaTargetedHistogramFlag);
- counter->Add(connection_type);
+ UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ConnectionType",
+ connection_type, NUM_CONNECTION_TYPES);
}
diff --git a/net/socket_stream/socket_stream_metrics_unittest.cc b/net/socket_stream/socket_stream_metrics_unittest.cc
index e29ee3f..7d44f79 100644
--- a/net/socket_stream/socket_stream_metrics_unittest.cc
+++ b/net/socket_stream/socket_stream_metrics_unittest.cc
@@ -42,7 +42,7 @@ TEST(SocketStreamMetricsTest, ProtocolType) {
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.ProtocolType", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
Histogram::SampleSet sample;
histogram->SnapshotSample(&sample);
@@ -75,7 +75,7 @@ TEST(SocketStreamMetricsTest, ConnectionType) {
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.ConnectionType", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
Histogram::SampleSet sample;
histogram->SnapshotSample(&sample);
@@ -134,46 +134,46 @@ TEST(SocketStreamMetricsTest, OtherNumbers) {
// ConnectionLatency.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.ConnectionLatency", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
// We don't check the contents of the histogram as it's time sensitive.
// ConnectionEstablish.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.ConnectionEstablish", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
// We don't check the contents of the histogram as it's time sensitive.
// Duration.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.Duration", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
// We don't check the contents of the histogram as it's time sensitive.
// ReceivedBytes.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.ReceivedBytes", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
histogram->SnapshotSample(&sample);
EXPECT_EQ(11, sample.sum() - original_received_bytes); // 11 bytes read.
// ReceivedCounts.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.ReceivedCounts", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
histogram->SnapshotSample(&sample);
EXPECT_EQ(2, sample.sum() - original_received_counts); // 2 read requests.
// SentBytes.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.SentBytes", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
histogram->SnapshotSample(&sample);
EXPECT_EQ(222, sample.sum() - original_sent_bytes); // 222 bytes sent.
// SentCounts.
ASSERT_TRUE(StatisticsRecorder::FindHistogram(
"Net.SocketStream.SentCounts", &histogram));
- EXPECT_EQ(kUmaTargetedHistogramFlag, histogram->flags());
+ EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags());
histogram->SnapshotSample(&sample);
EXPECT_EQ(3, sample.sum() - original_sent_counts); // 3 write requests.
}