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

Side by Side Diff: base/test/statistics_delta_reader.cc

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/test/statistics_delta_reader.h ('k') | base/test/statistics_delta_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/test/statistics_delta_reader.h"
6
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"
11
12 namespace base {
13
14 StatisticsDeltaReader::StatisticsDeltaReader() {
15 StatisticsRecorder::Initialize(); // Safe to call multiple times.
16
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();
24 }
25 }
26
27 StatisticsDeltaReader::~StatisticsDeltaReader() {
28 STLDeleteValues(&original_samples_);
29 }
30
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();
42 }
43
44 } // namespace base
OLDNEW
« no previous file with comments | « base/test/statistics_delta_reader.h ('k') | base/test/statistics_delta_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698