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

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: some 'git cl format' changes 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::EnableCreationReportHistogram(StringPiece process_type) {
128 DCHECK(!report_histogram_);
129 size_t existing = StatisticsRecorder::NumberOfHistograms();
130 if (existing) {
Alexei Svitkine (slow) 2016/03/01 16:41:33 Nit: != 0
bcwhite 2016/03/02 19:14:19 Done.
131 DLOG(WARNING) << existing
132 << " histograms were created before reporting was enabled.";
133 }
134
135 std::string name =
136 "UMA.Histograms." + process_type.as_string() + ".Creations";
137 report_histogram_ = LinearHistogram::FactoryGet(
138 name, 1, HISTOGRAM_REPORT_MAX, HISTOGRAM_REPORT_MAX + 1,
139 kUmaTargetedHistogramFlag);
140 report_histogram_->Add(HISTOGRAM_REPORT_CREATED);
141 }
142
125 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const { 143 void HistogramBase::FindAndRunCallback(HistogramBase::Sample sample) const {
126 if ((flags() & kCallbackExists) == 0) 144 if ((flags() & kCallbackExists) == 0)
127 return; 145 return;
128 146
129 StatisticsRecorder::OnSampleCallback cb = 147 StatisticsRecorder::OnSampleCallback cb =
130 StatisticsRecorder::FindCallback(histogram_name()); 148 StatisticsRecorder::FindCallback(histogram_name());
131 if (!cb.is_null()) 149 if (!cb.is_null())
132 cb.Run(sample); 150 cb.Run(sample);
133 } 151 }
134 152
(...skipping 21 matching lines...) Expand all
156 StringAppendF(&result, "%d", sample); 174 StringAppendF(&result, "%d", sample);
157 return result; 175 return result;
158 } 176 }
159 177
160 void HistogramBase::WriteAsciiBucketValue(Count current, 178 void HistogramBase::WriteAsciiBucketValue(Count current,
161 double scaled_sum, 179 double scaled_sum,
162 std::string* output) const { 180 std::string* output) const {
163 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); 181 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
164 } 182 }
165 183
184 // static
185 void HistogramBase::UpdateReportHistogram(HistogramBase* histogram,
186 bool created) {
187 if (!report_histogram_)
188 return;
189
190 if (created) {
191 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_CREATED);
192 report_histogram_->Add(HISTOGRAM_REPORT_TYPE_GENERAL +
193 histogram->GetHistogramType());
Alexei Svitkine (slow) 2016/03/01 16:41:34 This is a bit fragile - if the histogram type ever
bcwhite 2016/03/02 19:14:19 Done.
194 const int32_t flags = histogram->flags_;
195 if (flags & kIsPersistent)
196 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_PERSISTENT);
197 if (flags & (kUmaStabilityHistogramFlag & ~kUmaTargetedHistogramFlag))
198 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_STABILITY);
199 else if (flags & kUmaTargetedHistogramFlag)
200 report_histogram_->Add(HISTOGRAM_REPORT_FLAG_UMA_TARGETED);
201 } else {
202 report_histogram_->Add(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP);
203 }
204 }
205
166 } // namespace base 206 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698