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

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

Issue 11022002: Add SampleMap and use it in SparseHistogram (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Support redundant_count Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_ 5 #ifndef BASE_METRICS_SPARSE_HISTOGRAM_H_
6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_ 6 #define BASE_METRICS_SPARSE_HISTOGRAM_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "base/metrics/histogram_base.h" 15 #include "base/metrics/histogram_base.h"
16 #include "base/metrics/sample_map.h"
15 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
16 18
17 namespace base { 19 namespace base {
18 20
19 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase { 21 class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase {
20 public: 22 public:
21 // If there's one with same name, return the existing one. If not, create a 23 // If there's one with same name, return the existing one. If not, create a
22 // new one. 24 // new one.
23 static HistogramBase* FactoryGet(const std::string& name, int32 flags); 25 static HistogramBase* FactoryGet(const std::string& name, int32 flags);
24 26
25 virtual ~SparseHistogram(); 27 virtual ~SparseHistogram();
26 28
29 // HistogramBase implementation:
27 virtual void Add(Sample value) OVERRIDE; 30 virtual void Add(Sample value) OVERRIDE;
28
29 virtual void SnapshotSample(std::map<Sample, Count>* sample) const;
30 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; 31 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE;
31 virtual void WriteAscii(std::string* output) const OVERRIDE; 32 virtual void WriteAscii(std::string* output) const OVERRIDE;
32 33
34 virtual scoped_ptr<SampleMap> SnapshotSamples() const;
35
33 protected: 36 protected:
34 // Clients should always use FactoryGet to create SparseHistogram. 37 // Clients should always use FactoryGet to create SparseHistogram.
35 SparseHistogram(const std::string& name); 38 SparseHistogram(const std::string& name);
jar (doing other things) 2012/10/05 01:27:36 nit: make private, unless we have a subclass using
kaiwang 2012/10/05 03:16:17 Done.
36 39
37 private: 40 private:
38 friend class SparseHistogramTest; // For constuctor calling. 41 friend class SparseHistogramTest; // For constuctor calling.
39 42
40 std::map<Sample, Count> samples_; 43 // Protects access to |sample_counts_| and |redundant_count_|.
41
42 // Protects access to above map.
43 mutable base::Lock lock_; 44 mutable base::Lock lock_;
45 std::map<HistogramBase::Sample, HistogramBase::Count> sample_counts_;
46 HistogramBase::Count redundant_count_;
44 47
45 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); 48 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
46 }; 49 };
47 50
48 } // namespace base 51 } // namespace base
49 52
50 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ 53 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698