Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Unified Diff: base/metrics/histogram_base.cc

Issue 1726873002: Report histogram creation results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added message for why not using macro Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram_base.cc
diff --git a/base/metrics/histogram_base.cc b/base/metrics/histogram_base.cc
index 3a40e6813fc6f5c7669c627e4bbc007e6d7184d3..c4c3ed24172dd29d660149d4216193144d513316 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,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." + (process_type.empty() ? process_type : process_type + ".") +
+ "Histograms.Activity";
+
+ // 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 +188,54 @@ void HistogramBase::WriteAsciiBucketValue(Count current,
StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
}
+// static
+void HistogramBase::ReportHistogramActivity(HistogramBase* histogram,
Alexei Svitkine (slow) 2016/03/07 21:14:51 This param can be const. And in fact you might as
bcwhite 2016/03/07 22:20:41 Done.
+ ReportActivity activity) {
+ if (!report_histogram_)
+ return;
+
+ const int32_t flags = histogram->flags_;
+ HistogramReport report_type;
+ 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;
+ default:
Alexei Svitkine (slow) 2016/03/07 21:14:51 No need for default case. GetHistogramType() retur
bcwhite 2016/03/07 22:20:41 The Windows compiler does not produce such an erro
Alexei Svitkine (slow) 2016/03/08 19:55:30 Other platforms do - specifically clang. Since thi
bcwhite 2016/03/09 01:57:26 Cool. I thought that was the case but was playing
+ NOTREACHED();
+ report_type = HISTOGRAM_REPORT_MAX;
+ break;
+ }
+ report_histogram_->Add(report_type);
+ 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);
+ break;
+
+ case HISTOGRAM_LOOKUP:
+ report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP);
+ break;
+
+ default:
+ NOTREACHED();
+ }
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698