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

Unified Diff: base/test/histogram_recorder.cc

Issue 18337014: Add a HistogramRecorder class and use cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove an empty line. Created 7 years, 5 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/test/histogram_recorder.cc
diff --git a/base/test/histogram_recorder.cc b/base/test/histogram_recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..568fffa707074315765a855ef6d618ece22fe181
--- /dev/null
+++ b/base/test/histogram_recorder.cc
@@ -0,0 +1,43 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/histogram_recorder.h"
+
+#include "base/metrics/statistics_recorder.h"
+#include "base/stl_util.h"
+
+namespace base {
+
+HistogramRecorder::HistogramRecorder(
+ const std::string& prefix) {
+ // Record any histogram data that exists when the object is created so it can
+ // be subtracted later.
+ StatisticsRecorder::Initialize();
+ StatisticsRecorder::Histograms histograms;
+ StatisticsRecorder::GetSnapshot(prefix, &histograms);
+ for (size_t i = 0; i < histograms.size(); i++) {
+ original_samples_[histograms[i]->histogram_name()] =
+ histograms[i]->SnapshotSamples().release();
+ }
+}
+
+HistogramRecorder::~HistogramRecorder() {
+ STLDeleteValues(&original_samples_);
+ STLDeleteValues(&samples_);
+}
+
+HistogramSamples* HistogramRecorder::GetHistogramSamples(
+ const std::string& histogram_name) {
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
+ if (!histogram)
+ return NULL;
+ HistogramSamples* named_samples = histogram->SnapshotSamples().release();
+ HistogramSamples* named_original_samples = original_samples_[histogram_name];
+ if (named_original_samples)
+ named_samples->Subtract(*named_original_samples);
+ samples_[histogram_name] = named_samples;
+ return named_samples;
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698