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

Unified Diff: base/metrics/statistics_recorder.cc

Issue 2658163002: Merge histograms from providers into StatisticsRecorder for display. (Closed)
Patch Set: some cleanup; added test Created 3 years, 11 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/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index 482845045f2bfcf08596846aabb032c277b0f048..3c1665c7e268f4cfbdfecbe39e200518b8518fcd 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -87,6 +87,7 @@ StatisticsRecorder::~StatisticsRecorder() {
histograms_ = existing_histograms_.release();
callbacks_ = existing_callbacks_.release();
ranges_ = existing_ranges_.release();
+ providers_ = existing_providers_.release();
}
// static
@@ -113,6 +114,12 @@ bool StatisticsRecorder::IsActive() {
}
// static
+void StatisticsRecorder::RegisterHistogramProvider(
+ const WeakPtr<HistogramProvider>& provider) {
+ providers_->push_back(provider);
+}
+
+// static
HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
HistogramBase* histogram) {
HistogramBase* histogram_to_delete = nullptr;
@@ -307,6 +314,18 @@ HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) {
}
// static
+void StatisticsRecorder::ImportProvidedHistograms() {
Alexei Svitkine (slow) 2017/01/27 16:22:03 Can you add a thread check here?
bcwhite 2017/01/27 18:05:31 Not sure if I can because base/ doesn't generally
Alexei Svitkine (slow) 2017/01/27 18:06:57 Can you add base::ThreadChecker as a member and us
bcwhite 2017/01/27 18:12:57 These are static methods so there's no object to h
+ if (!providers_)
+ return;
+
+ // Merge histogram data from each provider in turn.
+ for (const WeakPtr<HistogramProvider>& provider : *providers_) {
+ if (provider)
Alexei Svitkine (slow) 2017/01/27 16:22:03 Nit: Maybe add a comment here to mention this is c
bcwhite 2017/01/27 18:05:31 Done.
+ provider->MergeHistogramDeltas();
+ }
+}
+
+// static
StatisticsRecorder::HistogramIterator StatisticsRecorder::begin(
bool include_persistent) {
DCHECK(histograms_);
@@ -346,6 +365,8 @@ void StatisticsRecorder::GetSnapshot(const std::string& query,
if (!histograms_)
return;
+ ImportGlobalPersistentHistograms();
+
for (const auto& entry : *histograms_) {
if (entry.second->histogram_name().find(query) != std::string::npos)
snapshot->push_back(entry.second);
@@ -458,10 +479,12 @@ StatisticsRecorder::StatisticsRecorder() {
existing_histograms_.reset(histograms_);
existing_callbacks_.reset(callbacks_);
existing_ranges_.reset(ranges_);
+ existing_providers_.reset(providers_);
histograms_ = new HistogramMap;
callbacks_ = new CallbackMap;
ranges_ = new RangesMap;
+ providers_ = new HistogramProviders;
InitLogOnShutdownWithoutLock();
}
@@ -479,14 +502,17 @@ void StatisticsRecorder::Reset() {
std::unique_ptr<HistogramMap> histograms_deleter;
std::unique_ptr<CallbackMap> callbacks_deleter;
std::unique_ptr<RangesMap> ranges_deleter;
+ std::unique_ptr<HistogramProviders> providers_deleter;
{
base::AutoLock auto_lock(lock_.Get());
histograms_deleter.reset(histograms_);
callbacks_deleter.reset(callbacks_);
ranges_deleter.reset(ranges_);
+ providers_deleter.reset(providers_);
histograms_ = nullptr;
callbacks_ = nullptr;
ranges_ = nullptr;
+ providers_ = nullptr;
}
// We are going to leak the histograms and the ranges.
}
@@ -506,6 +532,8 @@ StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = nullptr;
// static
StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = nullptr;
// static
+StatisticsRecorder::HistogramProviders* StatisticsRecorder::providers_;
+// static
base::LazyInstance<base::Lock>::Leaky StatisticsRecorder::lock_ =
LAZY_INSTANCE_INITIALIZER;

Powered by Google App Engine
This is Rietveld 408576698