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