OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 11 #ifndef NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_H_ |
12 #define NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_H_ | 12 #define NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_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 // the counter is not cached locally. | 17 // the counter is not cached locally. |
18 | 18 |
19 #define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ | 19 #define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ |
20 do { \ | 20 do { \ |
21 base::HistogramBase* counter = base::Histogram::FactoryGet( \ | 21 base::HistogramBase* counter = base::Histogram::FactoryGet( \ |
22 name, min, max, bucket_count, \ | 22 name, \ |
23 base::Histogram::kUmaTargetedHistogramFlag); \ | 23 min, \ |
24 counter->Add(sample); \ | 24 max, \ |
25 } while (0) | 25 bucket_count, \ |
| 26 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 27 counter->Add(sample); \ |
| 28 } while (0) |
26 | 29 |
27 #define CACHE_HISTOGRAM_COUNTS(name, sample) CACHE_HISTOGRAM_CUSTOM_COUNTS( \ | 30 #define CACHE_HISTOGRAM_COUNTS(name, sample) \ |
28 name, sample, 1, 1000000, 50) | 31 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 1000000, 50) |
29 | 32 |
30 #define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \ | 33 #define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \ |
31 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50) | 34 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50) |
32 | 35 |
33 #define CACHE_HISTOGRAM_COUNTS_50000(name, sample) \ | 36 #define CACHE_HISTOGRAM_COUNTS_50000(name, sample) \ |
34 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 50000000, 50) | 37 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 50000000, 50) |
35 | 38 |
36 #define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ | 39 #define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ |
37 do { \ | 40 do { \ |
38 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( \ | 41 base::HistogramBase* counter = base::Histogram::FactoryTimeGet( \ |
39 name, min, max, bucket_count, \ | 42 name, \ |
40 base::Histogram::kUmaTargetedHistogramFlag); \ | 43 min, \ |
41 counter->AddTime(sample); \ | 44 max, \ |
42 } while (0) | 45 bucket_count, \ |
| 46 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 47 counter->AddTime(sample); \ |
| 48 } while (0) |
43 | 49 |
44 #define CACHE_HISTOGRAM_TIMES(name, sample) CACHE_HISTOGRAM_CUSTOM_TIMES( \ | 50 #define CACHE_HISTOGRAM_TIMES(name, sample) \ |
45 name, sample, base::TimeDelta::FromMilliseconds(1), \ | 51 CACHE_HISTOGRAM_CUSTOM_TIMES(name, \ |
46 base::TimeDelta::FromSeconds(10), 50) | 52 sample, \ |
| 53 base::TimeDelta::FromMilliseconds(1), \ |
| 54 base::TimeDelta::FromSeconds(10), \ |
| 55 50) |
47 | 56 |
48 #define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ | 57 #define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \ |
| 58 do { \ |
49 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( \ | 59 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( \ |
50 name, 1, boundary_value, boundary_value + 1, \ | 60 name, \ |
51 base::Histogram::kUmaTargetedHistogramFlag); \ | 61 1, \ |
52 counter->Add(sample); \ | 62 boundary_value, \ |
| 63 boundary_value + 1, \ |
| 64 base::Histogram::kUmaTargetedHistogramFlag); \ |
| 65 counter->Add(sample); \ |
53 } while (0) | 66 } while (0) |
54 | 67 |
55 #define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ | 68 #define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ |
56 CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) | 69 CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) |
57 | 70 |
58 // ----------------------------------------------------------------------------- | 71 // ----------------------------------------------------------------------------- |
59 | 72 |
60 // HISTOGRAM_HOURS will collect time related data with a granularity of hours | 73 // HISTOGRAM_HOURS will collect time related data with a granularity of hours |
61 // and normal values of a few months. | 74 // and normal values of a few months. |
62 #define CACHE_HISTOGRAM_HOURS CACHE_HISTOGRAM_COUNTS_10000 | 75 #define CACHE_HISTOGRAM_HOURS CACHE_HISTOGRAM_COUNTS_10000 |
63 | 76 |
64 // HISTOGRAM_AGE will collect time elapsed since |initial_time|, with a | 77 // HISTOGRAM_AGE will collect time elapsed since |initial_time|, with a |
65 // granularity of hours and normal values of a few months. | 78 // granularity of hours and normal values of a few months. |
66 #define CACHE_HISTOGRAM_AGE(name, initial_time) \ | 79 #define CACHE_HISTOGRAM_AGE(name, initial_time) \ |
67 CACHE_HISTOGRAM_COUNTS_10000(name, \ | 80 CACHE_HISTOGRAM_COUNTS_10000(name, \ |
68 (base::Time::Now() - initial_time).InHours()) | 81 (base::Time::Now() - initial_time).InHours()) |
69 | 82 |
70 // HISTOGRAM_AGE_MS will collect time elapsed since |initial_time|, with the | 83 // HISTOGRAM_AGE_MS will collect time elapsed since |initial_time|, with the |
71 // normal resolution of the UMA_HISTOGRAM_TIMES. | 84 // normal resolution of the UMA_HISTOGRAM_TIMES. |
72 #define CACHE_HISTOGRAM_AGE_MS(name, initial_time)\ | 85 #define CACHE_HISTOGRAM_AGE_MS(name, initial_time) \ |
73 CACHE_HISTOGRAM_TIMES(name, base::TimeTicks::Now() - initial_time) | 86 CACHE_HISTOGRAM_TIMES(name, base::TimeTicks::Now() - initial_time) |
74 | 87 |
75 #define CACHE_HISTOGRAM_CACHE_ERROR(name, sample) \ | 88 #define CACHE_HISTOGRAM_CACHE_ERROR(name, sample) \ |
76 CACHE_HISTOGRAM_ENUMERATION(name, sample, 50) | 89 CACHE_HISTOGRAM_ENUMERATION(name, sample, 50) |
77 | 90 |
78 // Generates a UMA histogram of the given type, generating the proper name for | 91 // Generates a UMA histogram of the given type, generating the proper name for |
79 // it (asking backend_->HistogramName), and adding the provided sample. | 92 // it (asking backend_->HistogramName), and adding the provided sample. |
80 // For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would | 93 // For example, to generate a regualar UMA_HISTOGRAM_COUNTS, this macro would |
81 // be used as: | 94 // be used as: |
82 // CACHE_UMA(COUNTS, "MyName", 0, 20); | 95 // CACHE_UMA(COUNTS, "MyName", 0, 20); |
83 // CACHE_UMA(COUNTS, "MyExperiment", 530, 55); | 96 // CACHE_UMA(COUNTS, "MyExperiment", 530, 55); |
84 // which roughly translates to: | 97 // which roughly translates to: |
85 // UMA_HISTOGRAM_COUNTS("DiskCache.2.MyName", 20); // "2" is the CacheType. | 98 // UMA_HISTOGRAM_COUNTS("DiskCache.2.MyName", 20); // "2" is the CacheType. |
86 // UMA_HISTOGRAM_COUNTS("DiskCache.2.MyExperiment_530", 55); | 99 // UMA_HISTOGRAM_COUNTS("DiskCache.2.MyExperiment_530", 55); |
87 // | 100 // |
88 #define CACHE_UMA(type, name, experiment, sample) {\ | 101 #define CACHE_UMA(type, name, experiment, sample) \ |
89 const std::string my_name =\ | 102 { \ |
90 CACHE_UMA_BACKEND_IMPL_OBJ->HistogramName(name, experiment);\ | 103 const std::string my_name = \ |
91 switch (CACHE_UMA_BACKEND_IMPL_OBJ->cache_type()) {\ | 104 CACHE_UMA_BACKEND_IMPL_OBJ->HistogramName(name, experiment); \ |
92 default:\ | 105 switch (CACHE_UMA_BACKEND_IMPL_OBJ->cache_type()) { \ |
93 NOTREACHED();\ | 106 default: \ |
94 /* Fall-through. */\ | 107 NOTREACHED(); \ |
95 case net::DISK_CACHE:\ | 108 /* Fall-through. */ \ |
96 case net::MEDIA_CACHE:\ | 109 case net::DISK_CACHE: \ |
97 case net::APP_CACHE:\ | 110 case net::MEDIA_CACHE: \ |
98 case net::SHADER_CACHE:\ | 111 case net::APP_CACHE: \ |
99 case net::PNACL_CACHE:\ | 112 case net::SHADER_CACHE: \ |
100 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ | 113 case net::PNACL_CACHE: \ |
101 break;\ | 114 CACHE_HISTOGRAM_##type(my_name.data(), sample); \ |
102 }\ | 115 break; \ |
| 116 } \ |
103 } | 117 } |
104 | 118 |
105 #endif // NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_H_ | 119 #endif // NET_DISK_CACHE_BLOCKFILE_HISTOGRAM_MACROS_H_ |
OLD | NEW |