Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / base / test / statistics_delta_reader.cc
blob93ce1ad647255b082fb1bca18f75e150786b729e
1 // Copyright 2014 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.
5 #include "base/test/statistics_delta_reader.h"
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h"
10 #include "base/stl_util.h"
12 namespace base {
14 StatisticsDeltaReader::StatisticsDeltaReader() {
15 StatisticsRecorder::Initialize(); // Safe to call multiple times.
17 // Record any histogram data that exists when the object is created so it can
18 // be subtracted later.
19 StatisticsRecorder::Histograms histograms;
20 StatisticsRecorder::GetSnapshot(std::string(), &histograms);
21 for (size_t i = 0; i < histograms.size(); ++i) {
22 original_samples_[histograms[i]->histogram_name()] =
23 histograms[i]->SnapshotSamples().release();
27 StatisticsDeltaReader::~StatisticsDeltaReader() {
28 STLDeleteValues(&original_samples_);
31 scoped_ptr<HistogramSamples>
32 StatisticsDeltaReader::GetHistogramSamplesSinceCreation(
33 const std::string& histogram_name) {
34 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
35 if (!histogram)
36 return scoped_ptr<HistogramSamples>();
37 scoped_ptr<HistogramSamples> named_samples(histogram->SnapshotSamples());
38 HistogramSamples* named_original_samples = original_samples_[histogram_name];
39 if (named_original_samples)
40 named_samples->Subtract(*named_original_samples);
41 return named_samples.Pass();
44 } // namespace base