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

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

Issue 1734033003: Add support for persistent sparse histograms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 9 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_histogram_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
(Empty)
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
3 // found in the LICENSE file.
4
5 // PersistentSampleMap implements HistogramSamples interface. It is used
6 // by the SparseHistogram class to store samples in persistent memory which
7 // allows it to be shared between processes or live across restarts.
8
9 #ifndef BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
10 #define BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
11
12 #include <stdint.h>
13
14 #include <map>
15
16 #include "base/compiler_specific.h"
17 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/histogram_samples.h"
21 #include "base/metrics/persistent_memory_allocator.h"
22
23 namespace base {
24
25 // The logic here is similar to that of SampleMap but with different data
26 // structures. Changes here likely need to be duplicated there.
27 class BASE_EXPORT PersistentSampleMap : public HistogramSamples {
28 public:
29 PersistentSampleMap(uint64_t id,
30 PersistentMemoryAllocator* allocator,
31 Metadata* meta);
32 ~PersistentSampleMap() override;
33
34 // HistogramSamples:
35 void Accumulate(HistogramBase::Sample value,
36 HistogramBase::Count count) override;
37 HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
38 HistogramBase::Count TotalCount() const override;
39 scoped_ptr<SampleCountIterator> Iterator() const override;
40
41 protected:
42 // Performs arithemetic. |op| is ADD or SUBTRACT.
43 bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override;
44
45 // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL
46 // if sample does not exist.
47 HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value);
48
49 // Gets a pointer to a "count" corresponding to a given |value|, creating
50 // the sample (initialized to zero) if it does not already exists.
51 HistogramBase::Count* GetOrCreateSampleCountStorage(
52 HistogramBase::Sample value);
53
54 private:
55 enum : HistogramBase::Sample { kAllSamples = -1 };
56
57 // Imports samples from persistent memory by iterating over all sample
58 // 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
60 // 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
62 // kAllSamples to force the importing of all available samples.
63 HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value);
64
65 // All created/loaded sample values and their associated counts. The storage
66 // for the actual Count numbers is owned by the |allocator_|.
67 std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_;
68
69 // The persistent memory allocator holding samples and an iterator through it.
70 PersistentMemoryAllocator* allocator_;
71 PersistentMemoryAllocator::Iterator sample_iter_;
72
73 DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap);
74 };
75
76 } // namespace base
77
78 #endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
OLDNEW
« no previous file with comments | « base/metrics/persistent_histogram_allocator.cc ('k') | base/metrics/persistent_sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698