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

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

Issue 1726873002: Report histogram creation results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added message for why not using macro Created 4 years, 9 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
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 <utility> 9 #include <utility>
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 case CUSTOM_HISTOGRAM: 55 case CUSTOM_HISTOGRAM:
56 return CustomHistogram::DeserializeInfoImpl(iter); 56 return CustomHistogram::DeserializeInfoImpl(iter);
57 case SPARSE_HISTOGRAM: 57 case SPARSE_HISTOGRAM:
58 return SparseHistogram::DeserializeInfoImpl(iter); 58 return SparseHistogram::DeserializeInfoImpl(iter);
59 default: 59 default:
60 return NULL; 60 return NULL;
61 } 61 }
62 } 62 }
63 63
64 const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX; 64 const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX;
65 HistogramBase* HistogramBase::report_histogram_ = nullptr;
65 66
66 HistogramBase::HistogramBase(const std::string& name) 67 HistogramBase::HistogramBase(const std::string& name)
67 : histogram_name_(name), 68 : histogram_name_(name),
68 flags_(kNoFlags) {} 69 flags_(kNoFlags) {}
69 70
70 HistogramBase::~HistogramBase() {} 71 HistogramBase::~HistogramBase() {}
71 72
72 void HistogramBase::CheckName(const StringPiece& name) const { 73 void HistogramBase::CheckName(const StringPiece& name) const {
73 DCHECK_EQ(histogram_name(), name); 74 DCHECK_EQ(histogram_name(), name);
74 } 75 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 root.SetString("name", histogram_name()); 116 root.SetString("name", histogram_name());
116 root.SetInteger("count", count); 117 root.SetInteger("count", count);
117 root.SetDouble("sum", static_cast<double>(sum)); 118 root.SetDouble("sum", static_cast<double>(sum));
118 root.SetInteger("flags", flags()); 119 root.SetInteger("flags", flags());
119 root.Set("params", std::move(parameters)); 120 root.Set("params", std::move(parameters));
120 root.Set("buckets", std::move(buckets)); 121 root.Set("buckets", std::move(buckets));
121 root.SetInteger("pid", GetCurrentProcId()); 122 root.SetInteger("pid", GetCurrentProcId());
122 serializer.Serialize(root); 123 serializer.Serialize(root);
123 } 124 }
124 125
126 // static
127 void HistogramBase::EnableActivityReportHistogram(
128 const std::string& process_type) {
129 DCHECK(!report_histogram_);
130 size_t existing = StatisticsRecorder::GetHistogramCount();
131 if (existing != 0) {
132 DLOG(WARNING) << existing
133 << " histograms were created before reporting was enabled.";
134 }
135
136 std::string name =
137 "UMA." + (process_type.empty() ? process_type : process_type + ".") +
138 "Histograms.Activity";
139
140 // Calling FactoryGet() here rather than using a histogram-macro works
141 // around some problems with tests that could end up seeing the results
142 // histogram when not expected due to a bad interaction between
143 // HistogramTester and StatisticsRecorder.
144 report_histogram_ = LinearHistogram::FactoryGet(
145 name, 1, HISTOGRAM_REPORT_MAX, HISTOGRAM_REPORT_MAX + 1,
146 kUmaTargetedHistogramFlag);
147 report_histogram_->Add(HISTOGRAM_REPORT_CREATED);
148 }
149
125 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const { 150 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const {
126 if ((flags() & kCallbackExists) == 0) 151 if ((flags() & kCallbackExists) == 0)
127 return; 152 return;
128 153
129 StatisticsRecorder::OnSampleCallback cb = 154 StatisticsRecorder::OnSampleCallback cb =
130 StatisticsRecorder::FindCallback(histogram_name()); 155 StatisticsRecorder::FindCallback(histogram_name());
131 if (!cb.is_null()) 156 if (!cb.is_null())
132 cb.Run(sample); 157 cb.Run(sample);
133 } 158 }
134 159
(...skipping 21 matching lines...) Expand all
156 StringAppendF(&result, "%d", sample); 181 StringAppendF(&result, "%d", sample);
157 return result; 182 return result;
158 } 183 }
159 184
160 void HistogramBase::WriteAsciiBucketValue(Count current, 185 void HistogramBase::WriteAsciiBucketValue(Count current,
161 double scaled_sum, 186 double scaled_sum,
162 std::string* output) const { 187 std::string* output) const {
163 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); 188 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
164 } 189 }
165 190
191 // static
192 void HistogramBase::ReportHistogramActivity(HistogramBase* histogram,
Alexei Svitkine (slow) 2016/03/07 21:14:51 This param can be const. And in fact you might as
bcwhite 2016/03/07 22:20:41 Done.
193 ReportActivity activity) {
194 if (!report_histogram_)
195 return;
196
197 const int32_t flags = histogram->flags_;
198 HistogramReport report_type;
199 switch (activity) {
200 case HISTOGRAM_CREATED:
201 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_CREATED);
202 switch (histogram->GetHistogramType()) {
203 case HISTOGRAM:
204 report_type = HISTOGRAM_REPORT_TYPE_LOGARITHMIC;
205 break;
206 case LINEAR_HISTOGRAM:
207 report_type = HISTOGRAM_REPORT_TYPE_LINEAR;
208 break;
209 case BOOLEAN_HISTOGRAM:
210 report_type = HISTOGRAM_REPORT_TYPE_BOOLEAN;
211 break;
212 case CUSTOM_HISTOGRAM:
213 report_type = HISTOGRAM_REPORT_TYPE_CUSTOM;
214 break;
215 case SPARSE_HISTOGRAM:
216 report_type = HISTOGRAM_REPORT_TYPE_SPARSE;
217 break;
218 default:
Alexei Svitkine (slow) 2016/03/07 21:14:51 No need for default case. GetHistogramType() retur
bcwhite 2016/03/07 22:20:41 The Windows compiler does not produce such an erro
Alexei Svitkine (slow) 2016/03/08 19:55:30 Other platforms do - specifically clang. Since thi
bcwhite 2016/03/09 01:57:26 Cool. I thought that was the case but was playing
219 NOTREACHED();
220 report_type = HISTOGRAM_REPORT_MAX;
221 break;
222 }
223 report_histogram_->Add(report_type);
224 if (flags & kIsPersistent)
225 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_PERSISTENT);
226 if (flags & (kUmaStabilityHistogramFlag & ~kUmaTargetedHistogramFlag))
227 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_STABILITY);
228 else if (flags & kUmaTargetedHistogramFlag)
229 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_TARGETED);
230 break;
231
232 case HISTOGRAM_LOOKUP:
233 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP);
234 break;
235
236 default:
237 NOTREACHED();
238 }
239 }
240
166 } // namespace base 241 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698