Chromium Code Reviews| 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/statistics_delta_reader.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 StatisticsDeltaReader::StatisticsDeltaReader() { | |
| 14 // Record any histogram data that exists when the object is created so it can | |
| 15 // be subtracted later. | |
| 16 StatisticsRecorder::Histograms histograms; | |
| 17 StatisticsRecorder::GetSnapshot("", &histograms); | |
|
Ilya Sherman
2014/01/06 23:31:35
nit: "" -> std::string()
lpromero
2014/01/07 10:20:02
Done.
| |
| 18 for (size_t i = 0; i < histograms.size(); i++) { | |
|
Ilya Sherman
2014/01/06 23:31:35
nit: i++ -> ++i
lpromero
2014/01/07 10:20:02
Done.
| |
| 19 original_samples_[histograms[i]->histogram_name()] = | |
| 20 histograms[i]->SnapshotSamples().release(); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 StatisticsDeltaReader::~StatisticsDeltaReader() { | |
| 25 STLDeleteValues(&original_samples_); | |
| 26 } | |
| 27 | |
| 28 scoped_ptr<HistogramSamples> | |
| 29 StatisticsDeltaReader::GetHistogramSamplesSinceCreation( | |
| 30 const std::string& histogram_name) { | |
| 31 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name); | |
| 32 if (!histogram) | |
| 33 return scoped_ptr<HistogramSamples>(); | |
| 34 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples()); | |
| 35 HistogramSamples* named_original_samples = original_samples_[histogram_name]; | |
| 36 if (named_original_samples) | |
| 37 named_samples->Subtract(*named_original_samples); | |
| 38 return named_samples.Pass(); | |
| 39 } | |
| 40 | |
| 41 } // namespace base | |
| OLD | NEW |