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