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

Side by Side Diff: base/metrics/sparse_histogram.h

Issue 2373523003: Clean up sparse_histogram.h header (Closed)
Patch Set: Rebase update on Oct 18 Created 4 years, 2 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
« no previous file with comments | « base/metrics/histogram_macros_internal.h ('k') | base/metrics/sparse_histogram_unittest.cc » ('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) 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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 14
15 #include "base/base_export.h" 15 #include "base/base_export.h"
16 #include "base/compiler_specific.h"
17 #include "base/logging.h"
18 #include "base/macros.h" 16 #include "base/macros.h"
19 #include "base/metrics/histogram_base.h" 17 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/sample_map.h" 18 #include "base/metrics/histogram_samples.h"
21 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
22 20
23 namespace base { 21 namespace base {
24 22
25 // Sparse histograms are well suited for recording counts of exact sample values
26 // that are sparsely distributed over a large range.
27 //
28 // The implementation uses a lock and a map, whereas other histogram types use a
29 // vector and no lock. It is thus more costly to add values to, and each value
30 // stored has more overhead, compared to the other histogram types. However it
31 // may be more efficient in memory if the total number of sample values is small
32 // compared to the range of their values.
33 //
34 // UMA_HISTOGRAM_ENUMERATION would be better suited for a smaller range of
35 // enumerations that are (nearly) contiguous. Also for code that is expected to
36 // run often or in a tight loop.
37 //
38 // UMA_HISTOGRAM_SPARSE_SLOWLY is good for sparsely distributed and or
39 // infrequently recorded values.
40 //
41 // For instance, Sqlite.Version.* are SPARSE because for any given database,
42 // there's going to be exactly one version logged, meaning no gain to having a
43 // pre-allocated vector of slots once the fleet gets to version 4 or 5 or 10.
44 // Likewise Sqlite.Error.* are SPARSE, because most databases generate few or no
45 // errors and there are large gaps in the set of possible errors.
46 #define UMA_HISTOGRAM_SPARSE_SLOWLY(name, sample) \
47 do { \
48 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( \
49 name, base::HistogramBase::kUmaTargetedHistogramFlag); \
50 histogram->Add(sample); \
51 } while (0)
52
53 class HistogramSamples; 23 class HistogramSamples;
54 class PersistentHistogramAllocator; 24 class PersistentHistogramAllocator;
25 class Pickle;
26 class PickleIterator;
55 27
56 class BASE_EXPORT SparseHistogram : public HistogramBase { 28 class BASE_EXPORT SparseHistogram : public HistogramBase {
57 public: 29 public:
58 // If there's one with same name, return the existing one. If not, create a 30 // If there's one with same name, return the existing one. If not, create a
59 // new one. 31 // new one.
60 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); 32 static HistogramBase* FactoryGet(const std::string& name, int32_t flags);
61 33
62 // Create a histogram using data in persistent storage. The allocator must 34 // Create a histogram using data in persistent storage. The allocator must
63 // live longer than the created sparse histogram. 35 // live longer than the created sparse histogram.
64 static std::unique_ptr<HistogramBase> PersistentCreate( 36 static std::unique_ptr<HistogramBase> PersistentCreate(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 99
128 std::unique_ptr<HistogramSamples> samples_; 100 std::unique_ptr<HistogramSamples> samples_;
129 std::unique_ptr<HistogramSamples> logged_samples_; 101 std::unique_ptr<HistogramSamples> logged_samples_;
130 102
131 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); 103 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
132 }; 104 };
133 105
134 } // namespace base 106 } // namespace base
135 107
136 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ 108 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram_macros_internal.h ('k') | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698