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

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

Issue 1840843004: Improve efficiency of persistent sparse histograms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@improved-pma-iterator
Patch Set: added comment clarifying loop behavior 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 | « base/metrics/persistent_memory_allocator.cc ('k') | 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/macros.h" 18 #include "base/macros.h"
19 #include "base/metrics/histogram_base.h" 19 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/histogram_samples.h" 20 #include "base/metrics/histogram_samples.h"
21 #include "base/metrics/persistent_memory_allocator.h" 21 #include "base/metrics/persistent_memory_allocator.h"
22 22
23 namespace base { 23 namespace base {
24 24
25 class PersistentHistogramAllocator;
26 class PersistentSampleMapRecords;
27 class PersistentSparseHistogramDataManager;
28
25 // The logic here is similar to that of SampleMap but with different data 29 // The logic here is similar to that of SampleMap but with different data
26 // structures. Changes here likely need to be duplicated there. 30 // structures. Changes here likely need to be duplicated there.
27 class BASE_EXPORT PersistentSampleMap : public HistogramSamples { 31 class BASE_EXPORT PersistentSampleMap : public HistogramSamples {
28 public: 32 public:
33 // Constructs a persistent sample map using any of a variety of persistent
34 // data sources. Really, the first two are just convenience methods for
35 // getting at the PersistentSampleMapRecords object for the specified |id|.
36 // The source objects must live longer than this object.
29 PersistentSampleMap(uint64_t id, 37 PersistentSampleMap(uint64_t id,
30 PersistentMemoryAllocator* allocator, 38 PersistentHistogramAllocator* allocator,
31 Metadata* meta); 39 Metadata* meta);
40 PersistentSampleMap(uint64_t id,
41 PersistentSparseHistogramDataManager* manager,
42 Metadata* meta);
43 PersistentSampleMap(uint64_t id,
44 PersistentSampleMapRecords* records,
45 Metadata* meta);
46
32 ~PersistentSampleMap() override; 47 ~PersistentSampleMap() override;
33 48
34 // HistogramSamples: 49 // HistogramSamples:
35 void Accumulate(HistogramBase::Sample value, 50 void Accumulate(HistogramBase::Sample value,
36 HistogramBase::Count count) override; 51 HistogramBase::Count count) override;
37 HistogramBase::Count GetCount(HistogramBase::Sample value) const override; 52 HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
38 HistogramBase::Count TotalCount() const override; 53 HistogramBase::Count TotalCount() const override;
39 std::unique_ptr<SampleCountIterator> Iterator() const override; 54 std::unique_ptr<SampleCountIterator> Iterator() const override;
40 55
56 // Uses a persistent-memory |iterator| to locate and return information about
57 // the next record holding information for a PersistentSampleMap. The record
58 // could be for any Map so return the |sample_map_id| as well.
59 static PersistentMemoryAllocator::Reference GetNextPersistentRecord(
60 PersistentMemoryAllocator::Iterator& iterator,
61 uint64_t* sample_map_id);
62
63 // Creates a new record in an |allocator| storing count information for a
64 // specific sample |value| of a histogram with the given |sample_map_id|.
65 static PersistentMemoryAllocator::Reference CreatePersistentRecord(
66 PersistentMemoryAllocator* allocator,
67 uint64_t sample_map_id,
68 HistogramBase::Sample value);
69
41 protected: 70 protected:
42 // Performs arithemetic. |op| is ADD or SUBTRACT. 71 // Performs arithemetic. |op| is ADD or SUBTRACT.
43 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override; 72 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override;
44 73
45 // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL 74 // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL
46 // if sample does not exist. 75 // if sample does not exist.
47 HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value); 76 HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value);
48 77
49 // Gets a pointer to a "count" corresponding to a given |value|, creating 78 // Gets a pointer to a "count" corresponding to a given |value|, creating
50 // the sample (initialized to zero) if it does not already exists. 79 // the sample (initialized to zero) if it does not already exists.
51 HistogramBase::Count* GetOrCreateSampleCountStorage( 80 HistogramBase::Count* GetOrCreateSampleCountStorage(
52 HistogramBase::Sample value); 81 HistogramBase::Sample value);
53 82
54 private: 83 private:
55 enum : HistogramBase::Sample { kAllSamples = -1 }; 84 enum : HistogramBase::Sample { kAllSamples = -1 };
56 85
57 // Imports samples from persistent memory by iterating over all sample 86 // Imports samples from persistent memory by iterating over all sample
58 // records found therein, adding them to the sample_counts_ map. If a 87 // records found therein, adding them to the sample_counts_ map. If a
59 // count for the sample |until_value| is found, stop the import and return 88 // count for the sample |until_value| is found, stop the import and return
60 // a pointer to that counter. If that value is not found, null will be 89 // a pointer to that counter. If that value is not found, null will be
61 // returned after all currently available samples have been loaded. Pass 90 // returned after all currently available samples have been loaded. Pass
62 // kAllSamples to force the importing of all available samples. 91 // kAllSamples to force the importing of all available samples.
63 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value); 92 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value);
64 93
65 // All created/loaded sample values and their associated counts. The storage 94 // All created/loaded sample values and their associated counts. The storage
66 // for the actual Count numbers is owned by the |allocator_|. 95 // for the actual Count numbers is owned by the |records_| object and its
96 // underlying allocator.
67 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_; 97 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_;
68 98
69 // The persistent memory allocator holding samples and an iterator through it. 99 // The object that manages records inside persistent memory. This is owned
70 PersistentMemoryAllocator* allocator_; 100 // externally (typically by a PersistentHistogramAllocator) and is expected
71 PersistentMemoryAllocator::Iterator sample_iter_; 101 // to live beyond the life of this object.
102 PersistentSampleMapRecords* records_;
72 103
73 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap); 104 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap);
74 }; 105 };
75 106
76 } // namespace base 107 } // namespace base
77 108
78 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_ 109 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
OLDNEW
« no previous file with comments | « base/metrics/persistent_memory_allocator.cc ('k') | base/metrics/persistent_sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698