Chromium Code Reviews| 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..ee852f71c0c4e98ee3c01bed471a4210986b2ecf |
| --- /dev/null |
| +++ b/base/test/histogram_recorder.cc |
| @@ -0,0 +1,52 @@ |
| +// 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/histogram.h" |
| +#include "base/metrics/statistics_recorder.h" |
| +#include "base/stl_util.h" |
| + |
| +namespace base { |
| + |
| +// static |
| +void HistogramRecorder::Initialize() { |
|
ppi
2013/12/23 16:37:48
Should we drop it and call StatisticsRecorder dire
lpromero
2013/12/23 17:22:54
I liked the encapsulation. Then, when using Histog
ppi
2013/12/23 17:31:38
This is interesting point, but note that when usin
|
| + // Ensure that StatisticsRecorder is initialized. |
| + StatisticsRecorder::Initialize(); |
| +} |
| + |
| +HistogramRecorder::HistogramRecorder() { |
| + // Record any histogram data that exists when the object is created so it can |
| + // be subtracted later. |
| + StatisticsRecorder::Histograms histograms; |
| + StatisticsRecorder::GetSnapshot("", &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_); |
| +} |
| + |
| +// static |
| +bool HistogramRecorder::IsActive() { |
|
ppi
2013/12/23 16:37:48
Should we drop it and call StatisticsRecorder dire
lpromero
2013/12/23 17:22:54
Ditto.
|
| + return StatisticsRecorder::IsActive(); |
| +} |
| + |
| +scoped_ptr<HistogramSamples> |
| + HistogramRecorder::GetHistogramSamplesSinceCreation( |
| + const std::string& histogram_name) { |
| + HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); |
| + if (!histogram) |
| + return scoped_ptr<HistogramSamples>(); |
| + scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); |
| + HistogramSamples* named_original_samples = original_samples_[histogram_name]; |
| + if (named_original_samples) |
| + named_samples->Subtract(*named_original_samples); |
| + return named_samples.Pass(); |
| +} |
| + |
| +} // namespace base |