• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors. All rights reserved.
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 
UmaHistogramExactLinear(const std::string & name,int sample,int value_max)20 void UmaHistogramExactLinear(const std::string& name,
21                              int sample,
22                              int value_max) {
23   HistogramBase* histogram =
24       LinearHistogram::FactoryGet(name, 1, value_max, value_max + 1,
25                                   HistogramBase::kUmaTargetedHistogramFlag);
26   histogram->Add(sample);
27 }
28 
UmaHistogramPercentage(const std::string & name,int percent)29 void UmaHistogramPercentage(const std::string& name, int percent) {
30   UmaHistogramExactLinear(name, percent, 100);
31 }
32 
UmaHistogramCustomCounts(const std::string & name,int sample,int min,int max,int buckets)33 void UmaHistogramCustomCounts(const std::string& name,
34                               int sample,
35                               int min,
36                               int max,
37                               int buckets) {
38   HistogramBase* histogram = Histogram::FactoryGet(
39       name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
40   histogram->Add(sample);
41 }
42 
UmaHistogramCounts100(const std::string & name,int sample)43 void UmaHistogramCounts100(const std::string& name, int sample) {
44   UmaHistogramCustomCounts(name, sample, 1, 100, 50);
45 }
46 
UmaHistogramCounts1000(const std::string & name,int sample)47 void UmaHistogramCounts1000(const std::string& name, int sample) {
48   UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
49 }
50 
UmaHistogramCounts10000(const std::string & name,int sample)51 void UmaHistogramCounts10000(const std::string& name, int sample) {
52   UmaHistogramCustomCounts(name, sample, 1, 10000, 50);
53 }
54 
UmaHistogramCounts100000(const std::string & name,int sample)55 void UmaHistogramCounts100000(const std::string& name, int sample) {
56   UmaHistogramCustomCounts(name, sample, 1, 100000, 50);
57 }
58 
UmaHistogramCounts1M(const std::string & name,int sample)59 void UmaHistogramCounts1M(const std::string& name, int sample) {
60   UmaHistogramCustomCounts(name, sample, 1, 1000000, 50);
61 }
62 
UmaHistogramCounts10M(const std::string & name,int sample)63 void UmaHistogramCounts10M(const std::string& name, int sample) {
64   UmaHistogramCustomCounts(name, sample, 1, 10000000, 50);
65 }
66 
UmaHistogramCustomTimes(const std::string & name,TimeDelta sample,TimeDelta min,TimeDelta max,int buckets)67 void UmaHistogramCustomTimes(const std::string& name,
68                              TimeDelta sample,
69                              TimeDelta min,
70                              TimeDelta max,
71                              int buckets) {
72   HistogramBase* histogram = Histogram::FactoryTimeGet(
73       name, min, max, buckets, HistogramBase::kUmaTargetedHistogramFlag);
74   histogram->AddTimeMillisecondsGranularity(sample);
75 }
76 
UmaHistogramTimes(const std::string & name,TimeDelta sample)77 void UmaHistogramTimes(const std::string& name, TimeDelta sample) {
78   UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
79                           TimeDelta::FromSeconds(10), 50);
80 }
81 
UmaHistogramMediumTimes(const std::string & name,TimeDelta sample)82 void UmaHistogramMediumTimes(const std::string& name, TimeDelta sample) {
83   UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
84                           TimeDelta::FromMinutes(3), 50);
85 }
86 
UmaHistogramLongTimes(const std::string & name,TimeDelta sample)87 void UmaHistogramLongTimes(const std::string& name, TimeDelta sample) {
88   UmaHistogramCustomTimes(name, sample, TimeDelta::FromMilliseconds(1),
89                           TimeDelta::FromHours(1), 50);
90 }
91 
UmaHistogramMemoryKB(const std::string & name,int sample)92 void UmaHistogramMemoryKB(const std::string& name, int sample) {
93   UmaHistogramCustomCounts(name, sample, 1000, 500000, 50);
94 }
95 
UmaHistogramMemoryMB(const std::string & name,int sample)96 void UmaHistogramMemoryMB(const std::string& name, int sample) {
97   UmaHistogramCustomCounts(name, sample, 1, 1000, 50);
98 }
99 
UmaHistogramMemoryLargeMB(const std::string & name,int sample)100 void UmaHistogramMemoryLargeMB(const std::string& name, int sample) {
101   UmaHistogramCustomCounts(name, sample, 1, 64000, 100);
102 }
103 
UmaHistogramSparse(const std::string & name,int sample)104 void UmaHistogramSparse(const std::string& name, int sample) {
105   HistogramBase* histogram = SparseHistogram::FactoryGet(
106       name, HistogramBase::kUmaTargetedHistogramFlag);
107   histogram->Add(sample);
108 }
109 
110 }  // namespace base
111