Chromium Code Reviews| Index: base/metrics/histogram_base.cc |
| diff --git a/base/metrics/histogram_base.cc b/base/metrics/histogram_base.cc |
| index 3a40e6813fc6f5c7669c627e4bbc007e6d7184d3..ffcae1986435d99123951a97c143412448172485 100644 |
| --- a/base/metrics/histogram_base.cc |
| +++ b/base/metrics/histogram_base.cc |
| @@ -62,6 +62,7 @@ HistogramBase* DeserializeHistogramInfo(PickleIterator* iter) { |
| } |
| const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX; |
| +HistogramBase* HistogramBase::report_histogram_ = nullptr; |
| HistogramBase::HistogramBase(const std::string& name) |
| : histogram_name_(name), |
| @@ -122,6 +123,23 @@ void HistogramBase::WriteJSON(std::string* output) const { |
| serializer.Serialize(root); |
| } |
| +// static |
| +void HistogramBase::EnableCreationReportHistogram(StringPiece process_type) { |
| + DCHECK(!report_histogram_); |
| + size_t existing = StatisticsRecorder::NumberOfHistograms(); |
| + if (existing) { |
|
Alexei Svitkine (slow)
2016/03/01 16:41:33
Nit: != 0
bcwhite
2016/03/02 19:14:19
Done.
|
| + DLOG(WARNING) << existing |
| + << " histograms were created before reporting was enabled."; |
| + } |
| + |
| + std::string name = |
| + "UMA.Histograms." + process_type.as_string() + ".Creations"; |
| + report_histogram_ = LinearHistogram::FactoryGet( |
| + name, 1, HISTOGRAM_REPORT_MAX, HISTOGRAM_REPORT_MAX + 1, |
| + kUmaTargetedHistogramFlag); |
| + report_histogram_->Add(HISTOGRAM_REPORT_CREATED); |
| +} |
| + |
| void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const { |
| if ((flags() & kCallbackExists) == 0) |
| return; |
| @@ -163,4 +181,26 @@ void HistogramBase::WriteAsciiBucketValue(Count current, |
| StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); |
| } |
| +// static |
| +void HistogramBase::UpdateReportHistogram(HistogramBase* histogram, |
| + bool created) { |
| + if (!report_histogram_) |
| + return; |
| + |
| + if (created) { |
| + report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_CREATED); |
| + report_histogram_->Add(HISTOGRAM_REPORT_TYPE_GENERAL + |
| + histogram->GetHistogramType()); |
|
Alexei Svitkine (slow)
2016/03/01 16:41:34
This is a bit fragile - if the histogram type ever
bcwhite
2016/03/02 19:14:19
Done.
|
| + const int32_t flags = histogram->flags_; |
| + if (flags & kIsPersistent) |
| + report_histogram_->Add(HISTOGRAM_REPORT_FLAG_PERSISTENT); |
| + if (flags & (kUmaStabilityHistogramFlag & ~kUmaTargetedHistogramFlag)) |
| + report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_STABILITY); |
| + else if (flags & kUmaTargetedHistogramFlag) |
| + report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_TARGETED); |
| + } else { |
| + report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP); |
| + } |
| +} |
| + |
| } // namespace base |