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

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

Issue 1471073007: Reorganize histograms for persistence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: added GN changes Created 5 years 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
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 #include "base/metrics/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include "base/metrics/metrics_hashes.h"
7 #include "base/metrics/sample_map.h" 8 #include "base/metrics/sample_map.h"
8 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
9 #include "base/pickle.h" 10 #include "base/pickle.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
12 13
13 namespace base { 14 namespace base {
14 15
15 typedef HistogramBase::Count Count; 16 typedef HistogramBase::Count Count;
16 typedef HistogramBase::Sample Sample; 17 typedef HistogramBase::Sample Sample;
17 18
18 // static 19 // static
19 HistogramBase* SparseHistogram::FactoryGet(const std::string& name, 20 HistogramBase* SparseHistogram::FactoryGet(const std::string& name,
20 int32 flags) { 21 int32 flags) {
21 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); 22 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
22 23
23 if (!histogram) { 24 if (!histogram) {
24 // To avoid racy destruction at shutdown, the following will be leaked. 25 // To avoid racy destruction at shutdown, the following will be leaked.
25 HistogramBase* tentative_histogram = new SparseHistogram(name); 26 HistogramBase* tentative_histogram = new SparseHistogram(name);
26 tentative_histogram->SetFlags(flags); 27 tentative_histogram->SetFlags(flags);
27 histogram = 28 histogram =
28 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 29 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram);
29 } 30 }
30 DCHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType()); 31 DCHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType());
31 return histogram; 32 return histogram;
32 } 33 }
33 34
34 SparseHistogram::~SparseHistogram() {} 35 SparseHistogram::~SparseHistogram() {}
35 36
37 uint64_t SparseHistogram::id() const {
38 return samples_.id();
39 }
40
36 HistogramType SparseHistogram::GetHistogramType() const { 41 HistogramType SparseHistogram::GetHistogramType() const {
37 return SPARSE_HISTOGRAM; 42 return SPARSE_HISTOGRAM;
38 } 43 }
39 44
40 bool SparseHistogram::HasConstructionArguments( 45 bool SparseHistogram::HasConstructionArguments(
41 Sample expected_minimum, 46 Sample expected_minimum,
42 Sample expected_maximum, 47 Sample expected_maximum,
43 size_t expected_bucket_count) const { 48 size_t expected_bucket_count) const {
44 // SparseHistogram never has min/max/bucket_count limit. 49 // SparseHistogram never has min/max/bucket_count limit.
45 return false; 50 return false;
(...skipping 10 matching lines...) Expand all
56 } 61 }
57 { 62 {
58 base::AutoLock auto_lock(lock_); 63 base::AutoLock auto_lock(lock_);
59 samples_.Accumulate(value, count); 64 samples_.Accumulate(value, count);
60 } 65 }
61 66
62 FindAndRunCallback(value); 67 FindAndRunCallback(value);
63 } 68 }
64 69
65 scoped_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const { 70 scoped_ptr<HistogramSamples> SparseHistogram::SnapshotSamples() const {
66 scoped_ptr<SampleMap> snapshot(new SampleMap()); 71 scoped_ptr<SampleMap> snapshot(
72 new SampleMap(metrics::HashMetricName(histogram_name())));
67 73
68 base::AutoLock auto_lock(lock_); 74 base::AutoLock auto_lock(lock_);
69 snapshot->Add(samples_); 75 snapshot->Add(samples_);
70 return snapshot.Pass(); 76 return snapshot.Pass();
71 } 77 }
72 78
73 void SparseHistogram::AddSamples(const HistogramSamples& samples) { 79 void SparseHistogram::AddSamples(const HistogramSamples& samples) {
74 base::AutoLock auto_lock(lock_); 80 base::AutoLock auto_lock(lock_);
75 samples_.Add(samples); 81 samples_.Add(samples);
76 } 82 }
(...skipping 11 matching lines...) Expand all
88 94
89 void SparseHistogram::WriteAscii(std::string* output) const { 95 void SparseHistogram::WriteAscii(std::string* output) const {
90 WriteAsciiImpl(true, "\n", output); 96 WriteAsciiImpl(true, "\n", output);
91 } 97 }
92 98
93 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { 99 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const {
94 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); 100 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags());
95 } 101 }
96 102
97 SparseHistogram::SparseHistogram(const std::string& name) 103 SparseHistogram::SparseHistogram(const std::string& name)
98 : HistogramBase(name) {} 104 : HistogramBase(name),
105 samples_(metrics::HashMetricName(name)) {}
99 106
100 HistogramBase* SparseHistogram::DeserializeInfoImpl(PickleIterator* iter) { 107 HistogramBase* SparseHistogram::DeserializeInfoImpl(PickleIterator* iter) {
101 std::string histogram_name; 108 std::string histogram_name;
102 int flags; 109 int flags;
103 if (!iter->ReadString(&histogram_name) || !iter->ReadInt(&flags)) { 110 if (!iter->ReadString(&histogram_name) || !iter->ReadInt(&flags)) {
104 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; 111 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name;
105 return NULL; 112 return NULL;
106 } 113 }
107 114
108 DCHECK(flags & HistogramBase::kIPCSerializationSourceFlag); 115 DCHECK(flags & HistogramBase::kIPCSerializationSourceFlag);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 std::string* output) const { 185 std::string* output) const {
179 StringAppendF(output, 186 StringAppendF(output,
180 "Histogram: %s recorded %d samples", 187 "Histogram: %s recorded %d samples",
181 histogram_name().c_str(), 188 histogram_name().c_str(),
182 total_count); 189 total_count);
183 if (flags() & ~kHexRangePrintingFlag) 190 if (flags() & ~kHexRangePrintingFlag)
184 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag); 191 StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag);
185 } 192 }
186 193
187 } // namespace base 194 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698