1 // Copyright 2016 The Chromium Authors
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/metrics/histogram_functions.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/histogram_base.h"
9 #include "base/metrics/sparse_histogram.h"
10 #include "base/time/time.h"
11
12 namespace base {
13
UmaHistogramBoolean(const std::string & name,bool sample)14 void UmaHistogramBoolean(const std::string& name, bool sample) {
15 HistogramBase* histogram = BooleanHistogram::FactoryGet(
16 name, HistogramBase::kUmaTargetedHistogramFlag);
17 histogram->Add(sample);
18 }
19
UmaHistogramBoolean(const char * name,bool sample)20 void UmaHistogramBoolean(const char* name, bool sample) {
21 HistogramBase* histogram = BooleanHistogram::FactoryGet(
22 name, HistogramBase::kUmaTargetedHistogramFlag);
23 histogram->Add(sample);
24 }
25
UmaHistogramExactLinear(const std::string & name,int sample,int exclusive_max)26 void UmaHistogramExactLinear(const std::string& name,
27 int sample,
28 int exclusive_max) {
29 HistogramBase* histogram = LinearHistogram::FactoryGet(
30 name, 1, exclusive_max, static_cast<size_t>(exclusive_max + 1),
31 HistogramBase::kUmaTargetedHistogramFlag);
32 histogram->Add(sample);
33 }
34
UmaHistogramExactLinear(const char * name,int sample,int exclusive_max)35 void UmaHistogramExactLinear(const char* name, int sample, int exclusive_max) {
36 HistogramBase* histogram = LinearHistogram::FactoryGet(
37 name, 1, exclusive_max, static_cast<size_t>(exclusive_max + 1),
38 HistogramBase::kUmaTargetedHistogramFlag);
39 histogram->Add(sample);
40 }
41
UmaHistogramPercentage(const std::string & name,int percent)42 void UmaHistogramPercentage(const std::string& name, int percent) {
43 UmaHistogramExactLinear(name, percent, 101);
44 }
45
UmaHistogramPercentage(const char * name,int percent)46 void UmaHistogramPercentage(const char* name, int percent) {
47 UmaHistogramExactLinear(name, percent, 101);
48 }
49
UmaHistogramPercentageObsoleteDoNotUse(const std::string & name,int percent)50 void UmaHistogramPercentageObsoleteDoNotUse(const std::string& name,
51 int percent) {
52 UmaHistogramExactLinear(name, percent, 100);
53 }
54
UmaHistogramPercentageObsoleteDoNotUse(const char * name,int percent)55 void UmaHistogramPercentageObsoleteDoNotUse(const char* name, int percent) {
56 UmaHistogramExactLinear(name, percent, 100);
57 }
58
UmaHistogramCustomCounts(const std::string & name,int sample,int min,int exclusive_max,size_t buckets)59 void UmaHistogramCustomCounts(const std::string& name,
60 int sample,
61 int min,
62 int exclusive_max,
63 size_t buckets) {
64 HistogramBase* histogram =
65 Histogram::FactoryGet(name, min, exclusive_max, buckets,
66 HistogramBase::kUmaTargetedHistogramFlag);
67 histogram->Add(sample);
68 }
69
UmaHistogramCustomCounts(const char * name,int sample,int min,int exclusive_max,size_t buckets)70 void UmaHistogramCustomCounts(const char* name,
71 int sample,
72 int min,
73 int exclusive_max,
74 size_t buckets) {
75 HistogramBase* histogram =
76 Histogram::FactoryGet(name, min, exclusive_max, buckets,
77 HistogramBase::kUmaTargetedHistogramFlag);
78 histogram->Add(sample);
79 }
80
UmaHistogramCounts100(const std::string & name,int sample)81 void UmaHistogramCounts100(const std::string& name, int sample) {
82 UmaHistogramCustomCounts(name, sample, 1, 100, 50);
83 }
84
UmaHistogramCounts100(const char * name,int sample)85 void UmaHistogramCounts100(const char* name, int sample) {
86 UmaHistogramCustomCounts(name, sample, 1, 100, 50);
87 }
88
UmaHistogramCounts1000(const std::string & name,int sample)89 void UmaHistogramCounts1000(const std::string& name, int sample) {
90 UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
91 }
92
UmaHistogramCounts1000(const char * name,int sample)93 void UmaHistogramCounts1000(const char* name, int sample) {
94 UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
95 }
96
UmaHistogramCounts10000(const std::string & name,int sample)97 void UmaHistogramCounts10000(const std::string& name, int sample) {
98 UmaHistogramCustomCounts(name, sample, 1, 10000, 50);
99 }
100
UmaHistogramCounts10000(const char * name,int sample)101 void UmaHistogramCounts10000(const char* name, int sample) {
102 UmaHistogramCustomCounts(name, sample, 1, 10000, 50);
103 }
104
UmaHistogramCounts100000(const std::string & name,int sample)105 void UmaHistogramCounts100000(const std::string& name, int sample) {
106 UmaHistogramCustomCounts(name, sample, 1, 100000, 50);
107 }
108
UmaHistogramCounts100000(const char * name,int sample)109 void UmaHistogramCounts100000(const char* name, int sample) {
110 UmaHistogramCustomCounts(name, sample, 1, 100000, 50);
111 }
112
UmaHistogramCounts1M(const std::string & name,int sample)113 void UmaHistogramCounts1M(const std::string& name, int sample) {
114 UmaHistogramCustomCounts(name, sample, 1, 1000000, 50);
115 }
116
UmaHistogramCounts1M(const char * name,int sample)117 void UmaHistogramCounts1M(const char* name, int sample) {
118 UmaHistogramCustomCounts(name, sample, 1, 1000000, 50);
119 }
120
UmaHistogramCounts10M(const std::string & name,int sample)121 void UmaHistogramCounts10M(const std::string& name, int sample) {
122 UmaHistogramCustomCounts(name, sample, 1, 10000000, 50);
123 }
124
UmaHistogramCounts10M(const char * name,int sample)125 void UmaHistogramCounts10M(const char* name, int sample) {
126 UmaHistogramCustomCounts(name, sample, 1, 10000000, 50);
127 }
128
UmaHistogramCustomTimes(const std::string & name,TimeDelta sample,TimeDelta min,TimeDelta max,size_t buckets)129 void UmaHistogramCustomTimes(const std::string& name,
130 TimeDelta sample,
131 TimeDelta min,
132 TimeDelta max,
133 size_t buckets) {
134 HistogramBase* histogram = Histogram::FactoryTimeGet(
135 name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
136 histogram->AddTimeMillisecondsGranularity(sample);
137 }
138
UmaHistogramCustomTimes(const char * name,TimeDelta sample,TimeDelta min,TimeDelta max,size_t buckets)139 void UmaHistogramCustomTimes(const char* name,
140 TimeDelta sample,
141 TimeDelta min,
142 TimeDelta max,
143 size_t buckets) {
144 HistogramBase* histogram = Histogram::FactoryTimeGet(
145 name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
146 histogram->AddTimeMillisecondsGranularity(sample);
147 }
148
UmaHistogramTimes(const std::string & name,TimeDelta sample)149 void UmaHistogramTimes(const std::string& name, TimeDelta sample) {
150 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Seconds(10), 50);
151 }
152
UmaHistogramTimes(const char * name,TimeDelta sample)153 void UmaHistogramTimes(const char* name, TimeDelta sample) {
154 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Seconds(10), 50);
155 }
156
UmaHistogramMediumTimes(const std::string & name,TimeDelta sample)157 void UmaHistogramMediumTimes(const std::string& name, TimeDelta sample) {
158 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Minutes(3), 50);
159 }
160
UmaHistogramMediumTimes(const char * name,TimeDelta sample)161 void UmaHistogramMediumTimes(const char* name, TimeDelta sample) {
162 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Minutes(3), 50);
163 }
164
UmaHistogramLongTimes(const std::string & name,TimeDelta sample)165 void UmaHistogramLongTimes(const std::string& name, TimeDelta sample) {
166 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Hours(1), 50);
167 }
168
UmaHistogramLongTimes(const char * name,TimeDelta sample)169 void UmaHistogramLongTimes(const char* name, TimeDelta sample) {
170 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Hours(1), 50);
171 }
172
UmaHistogramLongTimes100(const std::string & name,TimeDelta sample)173 void UmaHistogramLongTimes100(const std::string& name, TimeDelta sample) {
174 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Hours(1), 100);
175 }
176
UmaHistogramLongTimes100(const char * name,TimeDelta sample)177 void UmaHistogramLongTimes100(const char* name, TimeDelta sample) {
178 UmaHistogramCustomTimes(name, sample, Milliseconds(1), Hours(1), 100);
179 }
180
UmaHistogramCustomMicrosecondsTimes(const std::string & name,TimeDelta sample,TimeDelta min,TimeDelta max,size_t buckets)181 void UmaHistogramCustomMicrosecondsTimes(const std::string& name,
182 TimeDelta sample,
183 TimeDelta min,
184 TimeDelta max,
185 size_t buckets) {
186 HistogramBase* histogram = Histogram::FactoryMicrosecondsTimeGet(
187 name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
188 histogram->AddTimeMicrosecondsGranularity(sample);
189 }
190
UmaHistogramCustomMicrosecondsTimes(const char * name,TimeDelta sample,TimeDelta min,TimeDelta max,size_t buckets)191 void UmaHistogramCustomMicrosecondsTimes(const char* name,
192 TimeDelta sample,
193 TimeDelta min,
194 TimeDelta max,
195 size_t buckets) {
196 HistogramBase* histogram = Histogram::FactoryMicrosecondsTimeGet(
197 name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
198 histogram->AddTimeMicrosecondsGranularity(sample);
199 }
200
UmaHistogramMicrosecondsTimes(const std::string & name,TimeDelta sample)201 void UmaHistogramMicrosecondsTimes(const std::string& name, TimeDelta sample) {
202 UmaHistogramCustomMicrosecondsTimes(name, sample, Microseconds(1),
203 Seconds(10), 50);
204 }
205
UmaHistogramMicrosecondsTimes(const char * name,TimeDelta sample)206 void UmaHistogramMicrosecondsTimes(const char* name, TimeDelta sample) {
207 UmaHistogramCustomMicrosecondsTimes(name, sample, Microseconds(1),
208 Seconds(10), 50);
209 }
210
UmaHistogramMemoryKB(const std::string & name,int sample)211 void UmaHistogramMemoryKB(const std::string& name, int sample) {
212 UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
213 }
214
UmaHistogramMemoryKB(const char * name,int sample)215 void UmaHistogramMemoryKB(const char* name, int sample) {
216 UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
217 }
218
UmaHistogramMemoryMB(const std::string & name,int sample)219 void UmaHistogramMemoryMB(const std::string& name, int sample) {
220 UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
221 }
222
UmaHistogramMemoryMB(const char * name,int sample)223 void UmaHistogramMemoryMB(const char* name, int sample) {
224 UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
225 }
226
UmaHistogramMemoryLargeMB(const std::string & name,int sample)227 void UmaHistogramMemoryLargeMB(const std::string& name, int sample) {
228 UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
229 }
230
UmaHistogramMemoryLargeMB(const char * name,int sample)231 void UmaHistogramMemoryLargeMB(const char* name, int sample) {
232 UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
233 }
234
UmaHistogramSparse(const std::string & name,int sample)235 void UmaHistogramSparse(const std::string& name, int sample) {
236 HistogramBase* histogram = SparseHistogram::FactoryGet(
237 name, HistogramBase::kUmaTargetedHistogramFlag);
238 histogram->Add(sample);
239 }
240
UmaHistogramSparse(const char * name,int sample)241 void UmaHistogramSparse(const char* name, int sample) {
242 HistogramBase* histogram = SparseHistogram::FactoryGet(
243 name, HistogramBase::kUmaTargetedHistogramFlag);
244 histogram->Add(sample);
245 }
246
247 } // namespace base
248