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

Side by Side Diff: base/metrics/sparse_histogram.cc

Issue 1689833002: Add ownership-transfer to histogram management calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 10 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
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | base/metrics/statistics_recorder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/metrics/metrics_hashes.h" 9 #include "base/metrics/metrics_hashes.h"
10 #include "base/metrics/sample_map.h" 10 #include "base/metrics/sample_map.h"
11 #include "base/metrics/statistics_recorder.h" 11 #include "base/metrics/statistics_recorder.h"
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 typedef HistogramBase::Count Count; 18 typedef HistogramBase::Count Count;
19 typedef HistogramBase::Sample Sample; 19 typedef HistogramBase::Sample Sample;
20 20
21 // static 21 // static
22 HistogramBase* SparseHistogram::FactoryGet(const std::string& name, 22 HistogramBase* SparseHistogram::FactoryGet(const std::string& name,
23 int32_t flags) { 23 int32_t flags) {
24 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); 24 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
25 25
26 if (!histogram) { 26 if (!histogram) {
27 // To avoid racy destruction at shutdown, the following will be leaked. 27 // To avoid racy destruction at shutdown, the following will be leaked.
28 HistogramBase* tentative_histogram = new SparseHistogram(name); 28 scoped_ptr<HistogramBase> tentative_histogram(new SparseHistogram(name));
29 tentative_histogram->SetFlags(flags); 29 tentative_histogram->SetFlags(flags);
30 histogram = 30 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(
31 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 31 std::move(tentative_histogram));
32 } 32 }
33 DCHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType()); 33 DCHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType());
34 return histogram; 34 return histogram;
35 } 35 }
36 36
37 SparseHistogram::~SparseHistogram() {} 37 SparseHistogram::~SparseHistogram() {}
38 38
39 uint64_t SparseHistogram::name_hash() const { 39 uint64_t SparseHistogram::name_hash() const {
40 return samples_.id(); 40 return samples_.id();
41 } 41 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 std::string* output) const { 197 std::string* output) const {
198 StringAppendF(output, 198 StringAppendF(output,
199 "Histogram: %s recorded %d samples", 199 "Histogram: %s recorded %d samples",
200 histogram_name().c_str(), 200 histogram_name().c_str(),
201 total_count); 201 total_count);
202 if (flags() & ~kHexRangePrintingFlag) 202 if (flags() & ~kHexRangePrintingFlag)
203 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); 203 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag);
204 } 204 }
205 205
206 } // namespace base 206 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_unittest.cc ('k') | base/metrics/statistics_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698