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

Unified Diff: base/metrics/sample_map.h

Issue 11022002: Add SampleMap and use it in SparseHistogram (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 3 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
Index: base/metrics/sample_map.h
diff --git a/base/metrics/sample_map.h b/base/metrics/sample_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..a604b04514d4b3cf3f3076e71eb127c0336b421b
--- /dev/null
+++ b/base/metrics/sample_map.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 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.
+
+// SampleMap implements HistogramSamples interface. It is used by the
+// SparseHistogram class to store samples.
+
+#ifndef BASE_METRICS_SAMPLE_MAP_H_
+#define BASE_METRICS_SAMPLE_MAP_H_
+
+#include <map>
+
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram_base.h"
+#include "base/metrics/histogram_samples.h"
+#include "base/synchronization/lock.h"
+
+namespace base {
+
+class BASE_EXPORT_PRIVATE SampleMap : public HistogramSamples {
+ public:
+ SampleMap();
+ virtual ~SampleMap();
+
+ // HistogramSamples implementation:
+ virtual void Accumulate(HistogramBase::Sample value,
+ HistogramBase::Count count) OVERRIDE;
+ virtual HistogramBase::Count GetCount(
+ HistogramBase::Sample value) const OVERRIDE;
+ virtual HistogramBase::Count TotalCount() const OVERRIDE;
+ virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE;
+
+ protected:
+ virtual bool AddSubtractImpl(
+ SampleCountIterator* iter,
+ HistogramSamples::Instruction instruction) OVERRIDE;
+
+ private:
+ std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_;
jar (doing other things) 2012/10/01 23:10:38 nit: I'd prefer to see a typedef... as this map na
kaiwang 2012/10/02 02:57:56 Seems there's no way to make it a private typedef
jar (doing other things) 2012/10/02 17:41:10 Moving Sample and Count SGTM. It will surely help
+
+ // Protects access to above map.
+ mutable base::Lock lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(SampleMap);
+};
+
+class BASE_EXPORT_PRIVATE SampleMapIterator : public SampleCountIterator {
+ public:
+ SampleMapIterator(
+ const std::map<HistogramBase::Sample, HistogramBase::Count>&
+ sample_counts);
+
+ virtual ~SampleMapIterator();
+
+ // SampleCountIterator implementation:
+ virtual bool Done() const OVERRIDE;
+ virtual void Next() OVERRIDE;
+ virtual void Get(HistogramBase::Sample* min,
+ HistogramBase::Sample* max,
+ HistogramBase::Count* count) const OVERRIDE;
+ private:
+ std::map<HistogramBase::Sample, HistogramBase::Count>::const_iterator iter_;
+ const std::map<HistogramBase::Sample, HistogramBase::Count>::const_iterator
+ end_;
+};
+
+} // namespace base
+
+#endif // BASE_METRICS_SAMPLE_MAP_H_
« no previous file with comments | « base/base.gypi ('k') | base/metrics/sample_map.cc » ('j') | base/metrics/sample_map.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698