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

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: test needs to clear out statistics-recorder before releasing histogram memory 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 4783462e7535ea841b9899630529a086603759db..41e5bbf46efbb5050391cbf1edea3d262d6fd4c4 100644
--- a/base/metrics/histogram_snapshot_manager.cc
+++ b/base/metrics/histogram_snapshot_manager.cc
@@ -11,8 +11,6 @@
#include "base/stl_util.h"
namespace {
-// A flag to indicate that a new inconsistency has been added to the set.
-// It is used to know if the value needs to be sent upstream and cleared after.
const int kNewInconsistency = (int)0x80000000;
grt (UTC plus 2) 2016/02/15 15:42:39 nit: replace c-style cast with a C++ cast
bcwhite 2016/02/15 19:22:10 Done.
} // namespace
@@ -33,8 +31,9 @@ void HistogramSnapshotManager::StartDeltas() {
DCHECK(!preparing_deltas_);
preparing_deltas_ = true;
+ DCHECK(owned_histograms_.empty());
+
#ifdef DEBUG
- for (const auto& iter : known_histograms) {
CHECK(!iter->second.histogram);
CHECK(!iter->second.accumulated_samples);
CHECK(!(iter->second.inconsistencies & kNewInconsistency));
@@ -43,11 +42,25 @@ void HistogramSnapshotManager::StartDeltas() {
}
void HistogramSnapshotManager::PrepareDelta(HistogramBase* histogram) {
- PrepareSamples(histogram, histogram->SnapshotDelta());
+ PrepareSamples(histogram, histogram->SnapshotDelta(), false);
+}
+
+void HistogramSnapshotManager::PrepareDeltaTakingOwnership(
+ scoped_ptr<HistogramBase> histogram) {
+ // Snapshot must be done before releasing the pointer.
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotDelta();
+ PrepareSamples(histogram.release(), std::move(samples), true);
}
void HistogramSnapshotManager::PrepareOnce(const HistogramBase* histogram) {
- PrepareSamples(histogram, histogram->SnapshotSamples());
+ PrepareSamples(histogram, histogram->SnapshotSamples(), false);
+}
+
+void HistogramSnapshotManager::PrepareOnceTakingOwnership(
+ scoped_ptr<const HistogramBase> histogram) {
+ // Snapshot must be done before releasing the pointer.
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
+ PrepareSamples(histogram.release(), std::move(samples), true);
}
void HistogramSnapshotManager::FinishDeltas() {
@@ -82,22 +95,33 @@ void HistogramSnapshotManager::FinishDeltas() {
sample_info->histogram = nullptr;
grt (UTC plus 2) 2016/02/15 15:42:39 just curious: should |inconsistencies| also be cle
bcwhite 2016/02/15 19:22:10 It needs to remain to prevent multiple reports of
grt (UTC plus 2) 2016/02/15 19:53:55 groovy, thanks
}
+ owned_histograms_.clear();
preparing_deltas_ = false;
}
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(make_scoped_ptr(histogram));
}
// Crash if we detect that our histograms have been overwritten. This may be

Powered by Google App Engine
This is Rietveld 408576698