OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/histogram_recorder.h" |
| 6 |
| 7 #include "base/metrics/histogram.h" |
| 8 #include "base/metrics/statistics_recorder.h" |
| 9 #include "base/stl_util.h" |
| 10 |
| 11 namespace base { |
| 12 |
| 13 // static |
| 14 void HistogramRecorder::Initialize() { |
| 15 // Ensure that StatisticsRecorder is initialized. |
| 16 StatisticsRecorder::Initialize(); |
| 17 } |
| 18 |
| 19 HistogramRecorder::HistogramRecorder() { |
| 20 // Record any histogram data that exists when the object is created so it can |
| 21 // be subtracted later. |
| 22 StatisticsRecorder::Histograms histograms; |
| 23 StatisticsRecorder::GetSnapshot("", &histograms); |
| 24 for (size_t i = 0; i < histograms.size(); i++) { |
| 25 original_samples_[histograms[i]->histogram_name()] = |
| 26 histograms[i]->SnapshotSamples().release(); |
| 27 } |
| 28 } |
| 29 |
| 30 HistogramRecorder::~HistogramRecorder() { |
| 31 STLDeleteValues(&original_samples_); |
| 32 } |
| 33 |
| 34 // static |
| 35 bool HistogramRecorder::IsActive() { |
| 36 return StatisticsRecorder::IsActive(); |
| 37 } |
| 38 |
| 39 scoped_ptr<HistogramSamples> |
| 40 HistogramRecorder::GetHistogramSamplesSinceCreation( |
| 41 const std::string& histogram_name) { |
| 42 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); |
| 43 if (!histogram) |
| 44 return scoped_ptr<HistogramSamples>(); |
| 45 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); |
| 46 HistogramSamples* named_original_samples = original_samples_[histogram_name]; |
| 47 if (named_original_samples) |
| 48 named_samples->Subtract(*named_original_samples); |
| 49 return named_samples.Pass(); |
| 50 } |
| 51 |
| 52 } // namespace base |
OLD | NEW |