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

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

Issue 18337014: Add a HistogramRecorder class and use cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove an empty line. Created 7 years, 5 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
OLDNEW
(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/statistics_recorder.h"
8 #include "base/stl_util.h"
9
10 namespace base {
11
12 HistogramRecorder::HistogramRecorder(
13 const std::string& prefix) {
14 // Record any histogram data that exists when the object is created so it can
15 // be subtracted later.
16 StatisticsRecorder::Initialize();
17 StatisticsRecorder::Histograms histograms;
18 StatisticsRecorder::GetSnapshot(prefix, &histograms);
19 for (size_t i = 0; i < histograms.size(); i++) {
20 original_samples_[histograms[i]->histogram_name()] =
21 histograms[i]->SnapshotSamples().release();
22 }
23 }
24
25 HistogramRecorder::~HistogramRecorder() {
26 STLDeleteValues(&original_samples_);
27 STLDeleteValues(&samples_);
28 }
29
30 HistogramSamples* HistogramRecorder::GetHistogramSamples(
31 const std::string& histogram_name) {
32 HistogramBase* histogram = StatisticsRecorder::FindHistogram(histogram_name);
33 if (!histogram)
34 return NULL;
35 HistogramSamples* named_samples = histogram->SnapshotSamples().release();
36 HistogramSamples* named_original_samples = original_samples_[histogram_name];
37 if (named_original_samples)
38 named_samples->Subtract(*named_original_samples);
39 samples_[histogram_name] = named_samples;
40 return named_samples;
41 }
42
43 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698