OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_ | 5 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_ |
6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_ | 6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram_base.h" | 16 #include "base/metrics/histogram_base.h" |
17 #include "base/metrics/sample_map.h" | 17 #include "base/metrics/sample_map.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 | 21 |
22 // The common code for different SparseHistogram macros. | 22 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ |
23 #define HISTOGRAM_SPARSE_COMMON(name, sample, flag) \ | |
24 do { \ | 23 do { \ |
25 base::HistogramBase* histogram( \ | 24 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \ |
26 base::SparseHistogram::FactoryGet(name, flag)); \ | 25 name, base::HistogramBase::kUmaTargetedHistogramFlag); \ |
27 DCHECK_EQ(histogram->histogram_name(), name); \ | |
28 histogram->Add(sample); \ | 26 histogram->Add(sample); \ |
29 } while (0) | 27 } while (0) |
30 | 28 |
31 #define HISTOGRAM_SPARSE_SLOWLY(name, sample) \ | |
32 HISTOGRAM_SPARSE_COMMON(name, sample, base::HistogramBase::kNoFlags) | |
33 | |
34 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \ | |
35 HISTOGRAM_SPARSE_COMMON(name, sample, \ | |
36 base::HistogramBase::kUmaTargetedHistogramFlag) | |
37 | |
38 //------------------------------------------------------------------------------ | |
39 // Define debug only version of macros. | |
40 #ifndef NDEBUG | |
41 | |
42 #define DHISTOGRAM_SPARSE_SLOWLY(name, sample) \ | |
43 HISTOGRAM_SPARSE_SLOWLY(name, sample) | |
44 | |
45 #else // NDEBUG | |
46 | |
47 #define DHISTOGRAM_SPARSE_SLOWLY(name, sample) \ | |
48 while (0) { \ | |
49 static_cast<void>(name); \ | |
50 static_cast<void>(sample); \ | |
51 } | |
52 | |
53 #endif // NDEBUG | |
54 | |
55 class HistogramSamples; | 29 class HistogramSamples; |
56 | 30 |
57 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { | 31 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { |
58 public: | 32 public: |
59 // If there's one with same name, return the existing one. If not, create a | 33 // If there's one with same name, return the existing one. If not, create a |
60 // new one. | 34 // new one. |
61 static HistogramBase* FactoryGet(const std::string& name, int32 flags); | 35 static HistogramBase* FactoryGet(const std::string& name, int32 flags); |
62 | 36 |
63 virtual ~SparseHistogram(); | 37 virtual ~SparseHistogram(); |
64 | 38 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 mutable base::Lock lock_; | 82 mutable base::Lock lock_; |
109 | 83 |
110 SampleMap samples_; | 84 SampleMap samples_; |
111 | 85 |
112 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); | 86 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); |
113 }; | 87 }; |
114 | 88 |
115 } // namespace base | 89 } // namespace base |
116 | 90 |
117 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ | 91 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ |
OLD | NEW |