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..59205e3e70de49c2c477b87429003d0df45cc810 100644 |
| --- a/base/metrics/histogram_base.cc |
| +++ b/base/metrics/histogram_base.cc |
| @@ -34,9 +34,8 @@ std::string HistogramTypeToString(HistogramType type) { |
| return "CUSTOM_HISTOGRAM"; |
| case SPARSE_HISTOGRAM: |
| return "SPARSE_HISTOGRAM"; |
| - default: |
| - NOTREACHED(); |
| } |
| + NOTREACHED(); |
| return "UNKNOWN"; |
| } |
| @@ -62,6 +61,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 +122,30 @@ void HistogramBase::WriteJSON(std::string* output) const { |
| serializer.Serialize(root); |
| } |
| +// static |
| +void HistogramBase::EnableActivityReportHistogram( |
| + const std::string& process_type) { |
| + DCHECK(!report_histogram_); |
| + size_t existing = StatisticsRecorder::GetHistogramCount(); |
| + if (existing != 0) { |
| + DLOG(WARNING) << existing |
| + << " histograms were created before reporting was enabled."; |
| + } |
| + |
| + std::string name = |
| + "UMA.Histograms.Activity" + |
| + (process_type.empty() ? process_type : "." + process_type); |
| + |
| + // Calling FactoryGet() here rather than using a histogram-macro works |
| + // around some problems with tests that could end up seeing the results |
| + // histogram when not expected due to a bad interaction between |
| + // HistogramTester and StatisticsRecorder. |
| + 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 +187,47 @@ void HistogramBase::WriteAsciiBucketValue(Count current, |
| StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); |
| } |
| +// static |
| +void HistogramBase::ReportHistogramActivity(const HistogramBase& histogram, |
| + ReportActivity activity) { |
| + if (!report_histogram_) |
| + return; |
| + |
| + const int32_t flags = histogram.flags_; |
| + HistogramReport report_type = HISTOGRAM_REPORT_MAX; |
| + switch (activity) { |
| + case HISTOGRAM_CREATED: |
| + report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_CREATED); |
| + switch (histogram.GetHistogramType()) { |
| + case HISTOGRAM: |
| + report_type = HISTOGRAM_REPORT_TYPE_LOGARITHMIC; |
| + break; |
| + case LINEAR_HISTOGRAM: |
| + report_type = HISTOGRAM_REPORT_TYPE_LINEAR; |
| + break; |
| + case BOOLEAN_HISTOGRAM: |
| + report_type = HISTOGRAM_REPORT_TYPE_BOOLEAN; |
| + break; |
| + case CUSTOM_HISTOGRAM: |
| + report_type = HISTOGRAM_REPORT_TYPE_CUSTOM; |
| + break; |
| + case SPARSE_HISTOGRAM: |
| + report_type = HISTOGRAM_REPORT_TYPE_SPARSE; |
| + break; |
| + } |
| + report_histogram_->Add(report_type); |
| + if (flags & kIsPersistent) |
| + report_histogram_->Add(HISTOGRAM_REPORT_FLAG_PERSISTENT); |
| + if (flags & (kUmaStabilityHistogramFlag & ~kUmaTargetedHistogramFlag)) |
|
grt (UTC plus 2)
2016/03/09 04:04:43
is the ~kUmaTargetedHistogramFlag necessary? from
bcwhite
2016/03/09 14:01:57
Yes. Without it, it will also match those marked
bcwhite
2016/03/09 14:03:50
I'll rewrite it to be "(flags & mask) == mask" to
bcwhite
2016/03/09 16:04:26
Done.
|
| + report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_STABILITY); |
| + else if (flags & kUmaTargetedHistogramFlag) |
| + report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_TARGETED); |
| + break; |
| + |
| + case HISTOGRAM_LOOKUP: |
| + report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP); |
| + break; |
| + } |
| +} |
| + |
| } // namespace base |