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

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

Issue 1909673002: Support negative sample values in PersistentHistogramMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get kAllSamples value directly from PersistentSampleMap class Created 4 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
« no previous file with comments | « no previous file | base/metrics/persistent_sample_map.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // PersistentSampleMap implements HistogramSamples interface. It is used 5 // PersistentSampleMap implements HistogramSamples interface. It is used
6 // by the SparseHistogram class to store samples in persistent memory which 6 // by the SparseHistogram class to store samples in persistent memory which
7 // allows it to be shared between processes or live across restarts. 7 // allows it to be shared between processes or live across restarts.
8 8
9 #ifndef BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ 9 #ifndef BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
10 #define BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ 10 #define BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
11 11
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 16
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/gtest_prod_util.h"
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/metrics/histogram_base.h" 20 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/histogram_samples.h" 21 #include "base/metrics/histogram_samples.h"
21 #include "base/metrics/persistent_memory_allocator.h" 22 #include "base/metrics/persistent_memory_allocator.h"
22 23
23 namespace base { 24 namespace base {
24 25
25 class PersistentHistogramAllocator; 26 class PersistentHistogramAllocator;
26 class PersistentSampleMapRecords; 27 class PersistentSampleMapRecords;
27 class PersistentSparseHistogramDataManager; 28 class PersistentSparseHistogramDataManager;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL 75 // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL
75 // if sample does not exist. 76 // if sample does not exist.
76 HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value); 77 HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value);
77 78
78 // Gets a pointer to a "count" corresponding to a given |value|, creating 79 // Gets a pointer to a "count" corresponding to a given |value|, creating
79 // the sample (initialized to zero) if it does not already exists. 80 // the sample (initialized to zero) if it does not already exists.
80 HistogramBase::Count* GetOrCreateSampleCountStorage( 81 HistogramBase::Count* GetOrCreateSampleCountStorage(
81 HistogramBase::Sample value); 82 HistogramBase::Sample value);
82 83
83 private: 84 private:
84 enum : HistogramBase::Sample { kAllSamples = -1 }; 85 FRIEND_TEST_ALL_PREFIXES(PersistentSampleMapTest, PersistenceTest);
86
87 // Since all values are possible in a SparseHistogram, the value of
88 // kAllSamples is chosen to be something unlikely. In the case that this
89 // value is used within the sample map, it is still safe.
90 enum : HistogramBase::Sample { kAllSamples = -10000 };
Alexei Svitkine (slow) 2016/04/20 21:51:18 Can we avoid having this constant completely? For
Alexei Svitkine (slow) 2016/04/20 21:51:55 Or a separate boolean parameter?
bcwhite 2016/04/21 10:33:15 Sure, though the two parameters would generally be
85 91
86 // Imports samples from persistent memory by iterating over all sample 92 // Imports samples from persistent memory by iterating over all sample
87 // records found therein, adding them to the sample_counts_ map. If a 93 // records found therein, adding them to the sample_counts_ map. If a
88 // count for the sample |until_value| is found, stop the import and return 94 // count for the sample |until_value| is found, stop the import and return
89 // a pointer to that counter. If that value is not found, null will be 95 // a pointer to that counter. If that value is not found, null will be
90 // returned after all currently available samples have been loaded. Pass 96 // returned after all currently available samples have been loaded. Pass
91 // kAllSamples to force the importing of all available samples. 97 // kAllSamples to force the importing of all available samples.
92 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value); 98 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value);
93 99
94 // All created/loaded sample values and their associated counts. The storage 100 // All created/loaded sample values and their associated counts. The storage
95 // for the actual Count numbers is owned by the |records_| object and its 101 // for the actual Count numbers is owned by the |records_| object and its
96 // underlying allocator. 102 // underlying allocator.
97 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_; 103 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_;
98 104
99 // The object that manages records inside persistent memory. This is owned 105 // The object that manages records inside persistent memory. This is owned
100 // externally (typically by a PersistentHistogramAllocator) and is expected 106 // externally (typically by a PersistentHistogramAllocator) and is expected
101 // to live beyond the life of this object. 107 // to live beyond the life of this object.
102 PersistentSampleMapRecords* records_; 108 PersistentSampleMapRecords* records_;
103 109
104 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap); 110 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap);
105 }; 111 };
106 112
107 } // namespace base 113 } // namespace base
108 114
109 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ 115 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/persistent_sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698