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

Unified Diff: base/metrics/histogram_snapshot_manager.cc

Issue 1537743006: Persist setup metrics and have Chrome report them during UMA upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: address (many) comments by Greg Created 4 years, 10 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_snapshot_manager.cc
diff --git a/base/metrics/histogram_snapshot_manager.cc b/base/metrics/histogram_snapshot_manager.cc
index f641d44f1154bff8d15930b94f93caa93b1298d0..7778ca09ce5330458f7b8399eb50cdfb02809339 100644
--- a/base/metrics/histogram_snapshot_manager.cc
+++ b/base/metrics/histogram_snapshot_manager.cc
@@ -31,6 +31,8 @@ void HistogramSnapshotManager::StartDeltas() {
DCHECK(!preparing_deltas_);
preparing_deltas_ = true;
+ DCHECK(owned_histograms_.empty());
+
#ifdef DEBUG
for (auto iter : known_histograms) {
CHECK(!iter->second.histogram);
@@ -41,26 +43,46 @@ void HistogramSnapshotManager::StartDeltas() {
}
void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) {
- PrepareSamples(histogram, histogram->SnapshotDelta());
+ PrepareSamples(histogram, histogram->SnapshotDelta(), false);
+}
+
+void HistogramSnapshotManager::PrepareDeltaTakingOwnership(
+ HistogramBase* histogram) {
+ PrepareSamples(histogram, histogram->SnapshotDelta(), true);
}
void HistogramSnapshotManager::PrepareOnce(const HistogramBase* histogram) {
- PrepareSamples(histogram, histogram->SnapshotSamples());
+ PrepareSamples(histogram, histogram->SnapshotSamples(), false);
+}
+
+void HistogramSnapshotManager::PrepareOnceTakingOwnership(
+ const HistogramBase* histogram) {
+ PrepareSamples(histogram, histogram->SnapshotSamples(), true);
}
void HistogramSnapshotManager::PrepareSamples(
const HistogramBase* histogram,
- scoped_ptr<HistogramSamples> samples) {
+ scoped_ptr<HistogramSamples> samples,
+ bool take_ownership) {
DCHECK(histogram_flattener_);
+ scoped_ptr<const HistogramBase> owned_histogram;
// Get information known about this histogram.
SampleInfo* sample_info = &known_histograms_[histogram->name_hash()];
if (sample_info->histogram) {
DCHECK_EQ(sample_info->histogram->histogram_name(),
histogram->histogram_name()) << "hash collision";
+ // Passed histogram won't be needed past end of this method so store
+ // it in a scoped_ptr that will release it when returning.
+ if (take_ownership)
+ owned_histogram.reset(histogram);
} else {
// First time this histogram has been seen; datafill.
sample_info->histogram = histogram;
+ // The histogram data will be needed up until "finished" so store
+ // in member vector for releasing when that is done.
+ if (take_ownership)
+ owned_histograms_.push_back(histogram);
}
// Crash if we detect that our histograms have been overwritten. This may be
@@ -131,6 +153,10 @@ void HistogramSnapshotManager::FinishDeltas() {
sample_info->histogram = nullptr;
}
+ STLDeleteContainerPointers(owned_histograms_.begin(),
+ owned_histograms_.end());
+ owned_histograms_.clear();
+
preparing_deltas_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698