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

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

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 years, 3 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_base.h ('k') | base/metrics/histogram_base_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
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/histogram_base.h" 5 #include "base/metrics/histogram_base.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set>
10 #include <utility> 11 #include <utility>
11 12
12 #include "base/json/json_string_value_serializer.h" 13 #include "base/json/json_string_value_serializer.h"
14 #include "base/lazy_instance.h"
13 #include "base/logging.h" 15 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/histogram_samples.h" 18 #include "base/metrics/histogram_samples.h"
16 #include "base/metrics/sparse_histogram.h" 19 #include "base/metrics/sparse_histogram.h"
17 #include "base/metrics/statistics_recorder.h" 20 #include "base/metrics/statistics_recorder.h"
18 #include "base/pickle.h" 21 #include "base/pickle.h"
19 #include "base/process/process_handle.h" 22 #include "base/process/process_handle.h"
20 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/synchronization/lock.h"
21 #include "base/values.h" 25 #include "base/values.h"
22 26
23 namespace base { 27 namespace base {
24 28
25 std::string HistogramTypeToString(HistogramType type) { 29 std::string HistogramTypeToString(HistogramType type) {
26 switch (type) { 30 switch (type) {
27 case HISTOGRAM: 31 case HISTOGRAM:
28 return "HISTOGRAM"; 32 return "HISTOGRAM";
29 case LINEAR_HISTOGRAM: 33 case LINEAR_HISTOGRAM:
30 return "LINEAR_HISTOGRAM"; 34 return "LINEAR_HISTOGRAM";
(...skipping 25 matching lines...) Expand all
56 case SPARSE_HISTOGRAM: 60 case SPARSE_HISTOGRAM:
57 return SparseHistogram::DeserializeInfoImpl(iter); 61 return SparseHistogram::DeserializeInfoImpl(iter);
58 default: 62 default:
59 return NULL; 63 return NULL;
60 } 64 }
61 } 65 }
62 66
63 const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX; 67 const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX;
64 HistogramBase* HistogramBase::report_histogram_ = nullptr; 68 HistogramBase* HistogramBase::report_histogram_ = nullptr;
65 69
66 HistogramBase::HistogramBase(const std::string& name) 70 HistogramBase::HistogramBase(const char* name)
67 : histogram_name_(name), 71 : histogram_name_(name), flags_(kNoFlags) {}
68 flags_(kNoFlags) {}
69 72
70 HistogramBase::~HistogramBase() {} 73 HistogramBase::~HistogramBase() {}
71 74
72 void HistogramBase::CheckName(const StringPiece& name) const { 75 void HistogramBase::CheckName(const StringPiece& name) const {
73 DCHECK_EQ(histogram_name(), name); 76 DCHECK_EQ(StringPiece(histogram_name()), name);
74 } 77 }
75 78
76 void HistogramBase::SetFlags(int32_t flags) { 79 void HistogramBase::SetFlags(int32_t flags) {
77 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); 80 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_);
78 subtle::NoBarrier_Store(&flags_, old_flags | flags); 81 subtle::NoBarrier_Store(&flags_, old_flags | flags);
79 } 82 }
80 83
81 void HistogramBase::ClearFlags(int32_t flags) { 84 void HistogramBase::ClearFlags(int32_t flags) {
82 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_); 85 HistogramBase::Count old_flags = subtle::NoBarrier_Load(&flags_);
83 subtle::NoBarrier_Store(&flags_, old_flags & ~flags); 86 subtle::NoBarrier_Store(&flags_, old_flags & ~flags);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 return StringPrintf("%d", sample); 186 return StringPrintf("%d", sample);
184 } 187 }
185 188
186 void HistogramBase::WriteAsciiBucketValue(Count current, 189 void HistogramBase::WriteAsciiBucketValue(Count current,
187 double scaled_sum, 190 double scaled_sum,
188 std::string* output) const { 191 std::string* output) const {
189 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); 192 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
190 } 193 }
191 194
192 // static 195 // static
196 char const* HistogramBase::GetPermanentName(const std::string& name) {
197 // A set of histogram names that provides the "permanent" lifetime required
198 // by histogram objects for those strings that are not already code constants
199 // or held in persistent memory.
200 static LazyInstance<std::set<std::string>>::Leaky permanent_names;
201 static LazyInstance<Lock>::Leaky permanent_names_lock;
202
203 AutoLock lock(permanent_names_lock.Get());
204 auto result = permanent_names.Get().insert(name);
205 return result.first->c_str();
206 }
207
208 // static
193 void HistogramBase::ReportHistogramActivity(const HistogramBase& histogram, 209 void HistogramBase::ReportHistogramActivity(const HistogramBase& histogram,
194 ReportActivity activity) { 210 ReportActivity activity) {
195 if (!report_histogram_) 211 if (!report_histogram_)
196 return; 212 return;
197 213
198 const int32_t flags = histogram.flags_; 214 const int32_t flags = histogram.flags_;
199 HistogramReport report_type = HISTOGRAM_REPORT_MAX; 215 HistogramReport report_type = HISTOGRAM_REPORT_MAX;
200 switch (activity) { 216 switch (activity) {
201 case HISTOGRAM_CREATED: 217 case HISTOGRAM_CREATED:
202 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_CREATED); 218 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_CREATED);
(...skipping 23 matching lines...) Expand all
226 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_TARGETED); 242 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_TARGETED);
227 break; 243 break;
228 244
229 case HISTOGRAM_LOOKUP: 245 case HISTOGRAM_LOOKUP:
230 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP); 246 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP);
231 break; 247 break;
232 } 248 }
233 } 249 }
234 250
235 } // namespace base 251 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698