OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file contains macros to simplify histogram reporting from the disk | 5 // This file contains macros to simplify histogram reporting from the disk |
6 // cache. The main issue is that we want to have separate histograms for each | 6 // cache. The main issue is that we want to have separate histograms for each |
7 // type of cache (regular vs. media, etc), without adding the complexity of | 7 // type of cache (regular vs. media, etc), without adding the complexity of |
8 // keeping track of a potentially large number of histogram objects that have to | 8 // keeping track of a potentially large number of histogram objects that have to |
9 // survive the backend object that created them. | 9 // survive the backend object that created them. |
10 | 10 |
11 #ifndef NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_V3_H_ | 11 #ifndef NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_V3_H_ |
12 #define NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_V3_H_ | 12 #define NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_V3_H_ |
13 | 13 |
14 // ----------------------------------------------------------------------------- | 14 // ----------------------------------------------------------------------------- |
15 | 15 |
16 // These histograms follow the definition of UMA_HISTOGRAMN_XXX except that | 16 // These histograms follow the definition of UMA_HISTOGRAMN_XXX except that |
17 // whenever the name changes (the experiment group changes), the histrogram | 17 // whenever the name changes (the experiment group changes), the histrogram |
18 // object is re-created. | 18 // object is re-created. |
19 // Note: These macros are only run on one thread, so the declarations of | 19 // Note: These macros are only run on one thread, so the declarations of |
gavinp
2014/03/17 15:06:28
Nit: I would just eliminate this entire comment he
| |
20 // |counter| was made static (i.e., there will be no race for reinitialization). | 20 // |counter| could be static (since there will be no race for reinitialization), |
21 // but as they are used (with new names every time) in CACHE_UMA that | |
22 // would not work and if CACHE_UMA is made to have one instance for every | |
23 // cache, they will generate too much non-reusable machine code. | |
21 | 24 |
22 #define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ | 25 #define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ |
23 do { \ | 26 do { \ |
24 static base::HistogramBase* counter(NULL); \ | 27 base::HistogramBase* counter(NULL); \ |
25 if (!counter || name != counter->histogram_name()) \ | 28 if (!counter || name != counter->histogram_name()) \ |
26 counter = base::Histogram::FactoryGet( \ | 29 counter = base::Histogram::FactoryGet( \ |
27 name, min, max, bucket_count, \ | 30 name, min, max, bucket_count, \ |
28 base::Histogram::kUmaTargetedHistogramFlag); \ | 31 base::Histogram::kUmaTargetedHistogramFlag); \ |
29 counter->Add(sample); \ | 32 counter->Add(sample); \ |
30 } while (0) | 33 } while (0) |
31 | 34 |
32 #define CACHE_HISTOGRAM_COUNTS(name, sample) CACHE_HISTOGRAM_CUSTOM_COUNTS( \ | 35 #define CACHE_HISTOGRAM_COUNTS(name, sample) CACHE_HISTOGRAM_CUSTOM_COUNTS( \ |
33 name, sample, 1, 1000000, 50) | 36 name, sample, 1, 1000000, 50) |
34 | 37 |
35 #define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \ | 38 #define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \ |
36 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50) | 39 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50) |
37 | 40 |
38 #define CACHE_HISTOGRAM_COUNTS_50000(name, sample) \ | 41 #define CACHE_HISTOGRAM_COUNTS_50000(name, sample) \ |
39 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 50000000, 50) | 42 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 50000000, 50) |
40 | 43 |
41 #define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ | 44 #define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ |
42 do { \ | 45 do { \ |
43 static base::HistogramBase* counter(NULL); \ | 46 base::HistogramBase* counter(NULL); \ |
44 if (!counter || name != counter->histogram_name()) \ | 47 if (!counter || name != counter->histogram_name()) \ |
45 counter = base::Histogram::FactoryTimeGet( \ | 48 counter = base::Histogram::FactoryTimeGet( \ |
46 name, min, max, bucket_count, \ | 49 name, min, max, bucket_count, \ |
47 base::Histogram::kUmaTargetedHistogramFlag); \ | 50 base::Histogram::kUmaTargetedHistogramFlag); \ |
48 counter->AddTime(sample); \ | 51 counter->AddTime(sample); \ |
49 } while (0) | 52 } while (0) |
50 | 53 |
51 #define CACHE_HISTOGRAM_TIMES(name, sample) CACHE_HISTOGRAM_CUSTOM_TIMES( \ | 54 #define CACHE_HISTOGRAM_TIMES(name, sample) CACHE_HISTOGRAM_CUSTOM_TIMES( \ |
52 name, sample, base::TimeDelta::FromMilliseconds(1), \ | 55 name, sample, base::TimeDelta::FromMilliseconds(1), \ |
53 base::TimeDelta::FromSeconds(10), 50) | 56 base::TimeDelta::FromSeconds(10), 50) |
54 | 57 |
55 #define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 58 #define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ |
56 static base::HistogramBase* counter(NULL); \ | 59 base::HistogramBase* counter(NULL); \ |
57 if (!counter || name != counter->histogram_name()) \ | 60 if (!counter || name != counter->histogram_name()) \ |
58 counter = base::LinearHistogram::FactoryGet( \ | 61 counter = base::LinearHistogram::FactoryGet( \ |
59 name, 1, boundary_value, boundary_value + 1, \ | 62 name, 1, boundary_value, boundary_value + 1, \ |
60 base::Histogram::kUmaTargetedHistogramFlag); \ | 63 base::Histogram::kUmaTargetedHistogramFlag); \ |
61 counter->Add(sample); \ | 64 counter->Add(sample); \ |
62 } while (0) | 65 } while (0) |
63 | 66 |
64 #define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ | 67 #define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ |
65 CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) | 68 CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) |
66 | 69 |
(...skipping 21 matching lines...) Expand all Loading... | |
88 // it (asking backend_->HistogramName), and adding the provided sample. | 91 // it (asking backend_->HistogramName), and adding the provided sample. |
89 // For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would | 92 // For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would |
90 // be used as: | 93 // be used as: |
91 // CACHE_UMA(COUNTS, "MyName", 20); | 94 // CACHE_UMA(COUNTS, "MyName", 20); |
92 // which may translate to: | 95 // which may translate to: |
93 // UMA_HISTOGRAM_COUNTS("DiskCache3.MyName_AppCache", 20); | 96 // UMA_HISTOGRAM_COUNTS("DiskCache3.MyName_AppCache", 20); |
94 // | 97 // |
95 #define CACHE_UMA(type, name, sample) {\ | 98 #define CACHE_UMA(type, name, sample) {\ |
96 const std::string my_name =\ | 99 const std::string my_name =\ |
97 CACHE_UMA_BACKEND_IMPL_OBJ->HistogramName(name);\ | 100 CACHE_UMA_BACKEND_IMPL_OBJ->HistogramName(name);\ |
98 switch (CACHE_UMA_BACKEND_IMPL_OBJ->cache_type()) {\ | 101 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ |
99 case net::DISK_CACHE:\ | |
100 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ | |
101 break;\ | |
102 case net::MEDIA_CACHE:\ | |
103 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ | |
104 break;\ | |
105 case net::APP_CACHE:\ | |
106 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ | |
107 break;\ | |
108 case net::SHADER_CACHE:\ | |
109 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ | |
110 break;\ | |
111 case net::PNACL_CACHE:\ | |
112 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ | |
113 break;\ | |
114 default:\ | |
115 break;\ | |
116 }\ | |
117 } | 102 } |
118 | 103 |
119 #endif // NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_V3_H_ | 104 #endif // NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_V3_H_ |
OLD | NEW |