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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/persistent_sample_map.h
diff --git a/base/metrics/persistent_sample_map.h b/base/metrics/persistent_sample_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..a23b751804d6067611b62d1e41232310591e475c
--- /dev/null
+++ b/base/metrics/persistent_sample_map.h
@@ -0,0 +1,78 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// PersistentSampleMap implements HistogramSamples interface. It is used
+// by the SparseHistogram class to store samples in persistent memory which
+// allows it to be shared between processes or live across restarts.
+
+#ifndef BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
+#define BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
+
+#include <stdint.h>
+
+#include <map>
+
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram_base.h"
+#include "base/metrics/histogram_samples.h"
+#include "base/metrics/persistent_memory_allocator.h"
+
+namespace base {
+
+// The logic here is similar to that of SampleMap but with different data
+// structures. Changes here likely need to be duplicated there.
+class BASE_EXPORT PersistentSampleMap : public HistogramSamples {
+ public:
+ PersistentSampleMap(uint64_t id,
+ PersistentMemoryAllocator* allocator,
+ Metadata* meta);
+ ~PersistentSampleMap() override;
+
+ // HistogramSamples:
+ void Accumulate(HistogramBase::Sample value,
+ HistogramBase::Count count) override;
+ HistogramBase::Count GetCount(HistogramBase::Sample value) const override;
+ HistogramBase::Count TotalCount() const override;
+ scoped_ptr<SampleCountIterator> Iterator() const override;
+
+ protected:
+ // Performs arithemetic. |op| is ADD or SUBTRACT.
+ bool AddSubtractImpl(SampleCountIterator* iter, Operator op) override;
+
+ // Gets a pointer to a "count" corresponding to a given |value|. Returns NULL
+ // if sample does not exist.
+ HistogramBase::Count* GetSampleCountStorage(HistogramBase::Sample value);
+
+ // Gets a pointer to a "count" corresponding to a given |value|, creating
+ // the sample (initialized to zero) if it does not already exists.
+ HistogramBase::Count* GetOrCreateSampleCountStorage(
+ HistogramBase::Sample value);
+
+ private:
+ enum : HistogramBase::Sample { kAllSamples = -1 };
+
+ // Imports samples from persistent memory by iterating over all sample
+ // records found therein, adding them to the sample_counts_ map. If a
+ // count for the sample |until_value| is found, stop the import and return
+ // a pointer to that counter. If that value is not found, null will be
+ // returned after all currently available samples have been loaded. Pass
+ // kAllSamples to force the importing of all available samples.
+ HistogramBase::Count* ImportSamples(HistogramBase::Sample until_value);
+
+ // All created/loaded sample values and their associated counts. The storage
+ // for the actual Count numbers is owned by the |allocator_|.
+ std::map<HistogramBase::Sample, HistogramBase::Count*> sample_counts_;
+
+ // The persistent memory allocator holding samples and an iterator through it.
+ PersistentMemoryAllocator* allocator_;
+ PersistentMemoryAllocator::Iterator sample_iter_;
+
+ DISALLOW_COPY_AND_ASSIGN(PersistentSampleMap);
+};
+
+} // namespace base
+
+#endif // BASE_METRICS_PERSISTENT_SAMPLE_MAP_H_
« 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