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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 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/sample_vector_unittest.cc ('k') | base/metrics/sparse_histogram.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 (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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory>
12 #include <string> 13 #include <string>
13 14
14 #include "base/base_export.h" 15 #include "base/base_export.h"
15 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/metrics/histogram_base.h" 19 #include "base/metrics/histogram_base.h"
20 #include "base/metrics/sample_map.h" 20 #include "base/metrics/sample_map.h"
21 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
22 22
23 namespace base { 23 namespace base {
24 24
25 // Sparse histograms are well suited for recording counts of exact sample values 25 // Sparse histograms are well suited for recording counts of exact sample values
26 // that are sparsely distributed over a large range. 26 // that are sparsely distributed over a large range.
27 // 27 //
28 // The implementation uses a lock and a map, whereas other histogram types use a 28 // The implementation uses a lock and a map, whereas other histogram types use a
(...skipping 24 matching lines...) Expand all
53 class HistogramSamples; 53 class HistogramSamples;
54 class PersistentMemoryAllocator; 54 class PersistentMemoryAllocator;
55 55
56 class BASE_EXPORT SparseHistogram : public HistogramBase { 56 class BASE_EXPORT SparseHistogram : public HistogramBase {
57 public: 57 public:
58 // If there's one with same name, return the existing one. If not, create a 58 // If there's one with same name, return the existing one. If not, create a
59 // new one. 59 // new one.
60 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); 60 static HistogramBase* FactoryGet(const std::string& name, int32_t flags);
61 61
62 // Create a histogram using data in persistent storage. 62 // Create a histogram using data in persistent storage.
63 static scoped_ptr<HistogramBase> PersistentCreate( 63 static std::unique_ptr<HistogramBase> PersistentCreate(
64 PersistentMemoryAllocator* allocator, 64 PersistentMemoryAllocator* allocator,
65 const std::string& name, 65 const std::string& name,
66 HistogramSamples::Metadata* meta, 66 HistogramSamples::Metadata* meta,
67 HistogramSamples::Metadata* logged_meta); 67 HistogramSamples::Metadata* logged_meta);
68 68
69 ~SparseHistogram() override; 69 ~SparseHistogram() override;
70 70
71 // HistogramBase implementation: 71 // HistogramBase implementation:
72 uint64_t name_hash() const override; 72 uint64_t name_hash() const override;
73 HistogramType GetHistogramType() const override; 73 HistogramType GetHistogramType() const override;
74 bool HasConstructionArguments(Sample expected_minimum, 74 bool HasConstructionArguments(Sample expected_minimum,
75 Sample expected_maximum, 75 Sample expected_maximum,
76 uint32_t expected_bucket_count) const override; 76 uint32_t expected_bucket_count) const override;
77 void Add(Sample value) override; 77 void Add(Sample value) override;
78 void AddCount(Sample value, int count) override; 78 void AddCount(Sample value, int count) override;
79 void AddSamples(const HistogramSamples& samples) override; 79 void AddSamples(const HistogramSamples& samples) override;
80 bool AddSamplesFromPickle(base::PickleIterator* iter) override; 80 bool AddSamplesFromPickle(base::PickleIterator* iter) override;
81 scoped_ptr<HistogramSamples> SnapshotSamples() const override; 81 std::unique_ptr<HistogramSamples> SnapshotSamples() const override;
82 scoped_ptr<HistogramSamples> SnapshotDelta() override; 82 std::unique_ptr<HistogramSamples> SnapshotDelta() override;
83 void WriteHTMLGraph(std::string* output) const override; 83 void WriteHTMLGraph(std::string* output) const override;
84 void WriteAscii(std::string* output) const override; 84 void WriteAscii(std::string* output) const override;
85 85
86 protected: 86 protected:
87 // HistogramBase implementation: 87 // HistogramBase implementation:
88 bool SerializeInfoImpl(base::Pickle* pickle) const override; 88 bool SerializeInfoImpl(base::Pickle* pickle) const override;
89 89
90 private: 90 private:
91 // Clients should always use FactoryGet to create SparseHistogram. 91 // Clients should always use FactoryGet to create SparseHistogram.
92 explicit SparseHistogram(const std::string& name); 92 explicit SparseHistogram(const std::string& name);
(...skipping 20 matching lines...) Expand all
113 // Write a common header message describing this histogram. 113 // Write a common header message describing this histogram.
114 void WriteAsciiHeader(const Count total_count, 114 void WriteAsciiHeader(const Count total_count,
115 std::string* output) const; 115 std::string* output) const;
116 116
117 // For constuctor calling. 117 // For constuctor calling.
118 friend class SparseHistogramTest; 118 friend class SparseHistogramTest;
119 119
120 // Protects access to |samples_|. 120 // Protects access to |samples_|.
121 mutable base::Lock lock_; 121 mutable base::Lock lock_;
122 122
123 scoped_ptr<HistogramSamples> samples_; 123 std::unique_ptr<HistogramSamples> samples_;
124 scoped_ptr<HistogramSamples> logged_samples_; 124 std::unique_ptr<HistogramSamples> logged_samples_;
125 125
126 DISALLOW_COPY_AND_ASSIGN(SparseHistogram); 126 DISALLOW_COPY_AND_ASSIGN(SparseHistogram);
127 }; 127 };
128 128
129 } // namespace base 129 } // namespace base
130 130
131 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_ 131 #endif // BASE_METRICS_SPARSE_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « base/metrics/sample_vector_unittest.cc ('k') | base/metrics/sparse_histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698