Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: net/disk_cache/histogram_macros.h

Issue 6780035: Use lock-free lazy initialization for static histogram references (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/mime_sniffer.cc ('k') | net/disk_cache/stats.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_HISTOGRAM_MACROS_H_ 11 #ifndef NET_DISK_CACHE_HISTOGRAM_MACROS_H_
12 #define NET_DISK_CACHE_HISTOGRAM_MACROS_H_ 12 #define NET_DISK_CACHE_HISTOGRAM_MACROS_H_
13 #pragma once 13 #pragma once
14 14
15 // ----------------------------------------------------------------------------- 15 // -----------------------------------------------------------------------------
16 16
17 // These histograms follow the definition of UMA_HISTOGRAMN_XXX except that 17 // These histograms follow the definition of UMA_HISTOGRAMN_XXX except that
18 // whenever the name changes (the experiment group changes), the histrogram 18 // whenever the name changes (the experiment group changes), the histrogram
19 // object is re-created. 19 // object is re-created.
20 // Note: These macros are only run on one thread, so the declarations of
21 // |counter| was made static (i.e., there will be no race for reinitialization).
20 22
21 #define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ 23 #define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
22 do { \ 24 do { \
23 scoped_refptr<base::Histogram> counter; \ 25 static base::Histogram* counter(NULL); \
24 if (!counter || name != counter->histogram_name()) \ 26 if (!counter || name != counter->histogram_name()) \
25 counter = base::Histogram::FactoryGet( \ 27 counter = base::Histogram::FactoryGet( \
26 name, min, max, bucket_count, \ 28 name, min, max, bucket_count, \
27 base::Histogram::kUmaTargetedHistogramFlag); \ 29 base::Histogram::kUmaTargetedHistogramFlag); \
28 counter->Add(sample); \ 30 counter->Add(sample); \
29 } while (0) 31 } while (0)
30 32
31 #define CACHE_HISTOGRAM_COUNTS(name, sample) CACHE_HISTOGRAM_CUSTOM_COUNTS( \ 33 #define CACHE_HISTOGRAM_COUNTS(name, sample) CACHE_HISTOGRAM_CUSTOM_COUNTS( \
32 name, sample, 1, 1000000, 50) 34 name, sample, 1, 1000000, 50)
33 35
34 #define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \ 36 #define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \
35 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50) 37 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50)
36 38
37 #define CACHE_HISTOGRAM_COUNTS_50000(name, sample) \ 39 #define CACHE_HISTOGRAM_COUNTS_50000(name, sample) \
38 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 50000000, 50) 40 CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 50000000, 50)
39 41
40 #define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ 42 #define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
41 do { \ 43 do { \
42 scoped_refptr<base::Histogram> counter; \ 44 static base::Histogram* counter(NULL); \
43 if (!counter || name != counter->histogram_name()) \ 45 if (!counter || name != counter->histogram_name()) \
44 counter = base::Histogram::FactoryTimeGet( \ 46 counter = base::Histogram::FactoryTimeGet( \
45 name, min, max, bucket_count, \ 47 name, min, max, bucket_count, \
46 base::Histogram::kUmaTargetedHistogramFlag); \ 48 base::Histogram::kUmaTargetedHistogramFlag); \
47 counter->AddTime(sample); \ 49 counter->AddTime(sample); \
48 } while (0) 50 } while (0)
49 51
50 #define CACHE_HISTOGRAM_TIMES(name, sample) CACHE_HISTOGRAM_CUSTOM_TIMES( \ 52 #define CACHE_HISTOGRAM_TIMES(name, sample) CACHE_HISTOGRAM_CUSTOM_TIMES( \
51 name, sample, base::TimeDelta::FromMilliseconds(1), \ 53 name, sample, base::TimeDelta::FromMilliseconds(1), \
52 base::TimeDelta::FromSeconds(10), 50) 54 base::TimeDelta::FromSeconds(10), 50)
53 55
54 #define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ 56 #define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
55 scoped_refptr<base::Histogram> counter; \ 57 static base::Histogram* counter(NULL); \
56 if (!counter || name != counter->histogram_name()) \ 58 if (!counter || name != counter->histogram_name()) \
57 counter = base::LinearHistogram::FactoryGet( \ 59 counter = base::LinearHistogram::FactoryGet( \
58 name, 1, boundary_value, boundary_value + 1, \ 60 name, 1, boundary_value, boundary_value + 1, \
59 base::Histogram::kUmaTargetedHistogramFlag); \ 61 base::Histogram::kUmaTargetedHistogramFlag); \
60 counter->Add(sample); \ 62 counter->Add(sample); \
61 } while (0) 63 } while (0)
62 64
63 #define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ 65 #define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
64 CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) 66 CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
65 67
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 case net::APP_CACHE:\ 113 case net::APP_CACHE:\
112 CACHE_HISTOGRAM_##type(my_name.data(), sample);\ 114 CACHE_HISTOGRAM_##type(my_name.data(), sample);\
113 break;\ 115 break;\
114 default:\ 116 default:\
115 NOTREACHED();\ 117 NOTREACHED();\
116 break;\ 118 break;\
117 }\ 119 }\
118 } 120 }
119 121
120 #endif // NET_DISK_CACHE_HISTOGRAM_MACROS_H_ 122 #endif // NET_DISK_CACHE_HISTOGRAM_MACROS_H_
OLDNEW
« no previous file with comments | « net/base/mime_sniffer.cc ('k') | net/disk_cache/stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698