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

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

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 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 unified diff | Download patch
« no previous file with comments | « base/metrics/sparse_histogram.h ('k') | base/metrics/sparse_histogram_unittest.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 #include "base/metrics/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/metrics_hashes.h" 10 #include "base/metrics/metrics_hashes.h"
(...skipping 27 matching lines...) Expand all
38 tentative_histogram = allocator->AllocateHistogram( 38 tentative_histogram = allocator->AllocateHistogram(
39 SPARSE_HISTOGRAM, name, 0, 0, nullptr, flags, &histogram_ref); 39 SPARSE_HISTOGRAM, name, 0, 0, nullptr, flags, &histogram_ref);
40 } 40 }
41 41
42 // Handle the case where no persistent allocator is present or the 42 // Handle the case where no persistent allocator is present or the
43 // persistent allocation fails (perhaps because it is full). 43 // persistent allocation fails (perhaps because it is full).
44 if (!tentative_histogram) { 44 if (!tentative_histogram) {
45 DCHECK(!histogram_ref); // Should never have been set. 45 DCHECK(!histogram_ref); // Should never have been set.
46 DCHECK(!allocator); // Shouldn't have failed. 46 DCHECK(!allocator); // Shouldn't have failed.
47 flags &= ~HistogramBase::kIsPersistent; 47 flags &= ~HistogramBase::kIsPersistent;
48 tentative_histogram.reset(new SparseHistogram(name)); 48 tentative_histogram.reset(new SparseHistogram(GetPermanentName(name)));
49 tentative_histogram->SetFlags(flags); 49 tentative_histogram->SetFlags(flags);
50 } 50 }
51 51
52 // Register this histogram with the StatisticsRecorder. Keep a copy of 52 // Register this histogram with the StatisticsRecorder. Keep a copy of
53 // the pointer value to tell later whether the locally created histogram 53 // the pointer value to tell later whether the locally created histogram
54 // was registered or deleted. The type is "void" because it could point 54 // was registered or deleted. The type is "void" because it could point
55 // to released memory after the following line. 55 // to released memory after the following line.
56 const void* tentative_histogram_ptr = tentative_histogram.get(); 56 const void* tentative_histogram_ptr = tentative_histogram.get();
57 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate( 57 histogram = StatisticsRecorder::RegisterOrDeleteDuplicate(
58 tentative_histogram.release()); 58 tentative_histogram.release());
59 59
60 // Persistent histograms need some follow-up processing. 60 // Persistent histograms need some follow-up processing.
61 if (histogram_ref) { 61 if (histogram_ref) {
62 allocator->FinalizeHistogram(histogram_ref, 62 allocator->FinalizeHistogram(histogram_ref,
63 histogram == tentative_histogram_ptr); 63 histogram == tentative_histogram_ptr);
64 } 64 }
65 65
66 ReportHistogramActivity(*histogram, HISTOGRAM_CREATED); 66 ReportHistogramActivity(*histogram, HISTOGRAM_CREATED);
67 } else { 67 } else {
68 ReportHistogramActivity(*histogram, HISTOGRAM_LOOKUP); 68 ReportHistogramActivity(*histogram, HISTOGRAM_LOOKUP);
69 } 69 }
70 70
71 CHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType()); 71 CHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType());
72 return histogram; 72 return histogram;
73 } 73 }
74 74
75 // static 75 // static
76 std::unique_ptr<HistogramBase> SparseHistogram::PersistentCreate( 76 std::unique_ptr<HistogramBase> SparseHistogram::PersistentCreate(
77 PersistentHistogramAllocator* allocator, 77 PersistentHistogramAllocator* allocator,
78 const std::string& name, 78 const char* name,
79 HistogramSamples::Metadata* meta, 79 HistogramSamples::Metadata* meta,
80 HistogramSamples::Metadata* logged_meta) { 80 HistogramSamples::Metadata* logged_meta) {
81 return WrapUnique( 81 return WrapUnique(
82 new SparseHistogram(allocator, name, meta, logged_meta)); 82 new SparseHistogram(allocator, name, meta, logged_meta));
83 } 83 }
84 84
85 SparseHistogram::~SparseHistogram() {} 85 SparseHistogram::~SparseHistogram() {}
86 86
87 uint64_t SparseHistogram::name_hash() const { 87 uint64_t SparseHistogram::name_hash() const {
88 return unlogged_samples_->id(); 88 return unlogged_samples_->id();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 void SparseHistogram::WriteAscii(std::string* output) const { 168 void SparseHistogram::WriteAscii(std::string* output) const {
169 WriteAsciiImpl(true, "\n", output); 169 WriteAsciiImpl(true, "\n", output);
170 } 170 }
171 171
172 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { 172 bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const {
173 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); 173 return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags());
174 } 174 }
175 175
176 SparseHistogram::SparseHistogram(const std::string& name) 176 SparseHistogram::SparseHistogram(const char* name)
177 : HistogramBase(name), 177 : HistogramBase(name),
178 unlogged_samples_(new SampleMap(HashMetricName(name))), 178 unlogged_samples_(new SampleMap(HashMetricName(name))),
179 logged_samples_(new SampleMap(unlogged_samples_->id())) {} 179 logged_samples_(new SampleMap(unlogged_samples_->id())) {}
180 180
181 SparseHistogram::SparseHistogram(PersistentHistogramAllocator* allocator, 181 SparseHistogram::SparseHistogram(PersistentHistogramAllocator* allocator,
182 const std::string& name, 182 const char* name,
183 HistogramSamples::Metadata* meta, 183 HistogramSamples::Metadata* meta,
184 HistogramSamples::Metadata* logged_meta) 184 HistogramSamples::Metadata* logged_meta)
185 : HistogramBase(name), 185 : HistogramBase(name),
186 // While other histogram types maintain a static vector of values with 186 // While other histogram types maintain a static vector of values with
187 // sufficient space for both "active" and "logged" samples, with each 187 // sufficient space for both "active" and "logged" samples, with each
188 // SampleVector being given the appropriate half, sparse histograms 188 // SampleVector being given the appropriate half, sparse histograms
189 // have no such initial allocation. Each sample has its own record 189 // have no such initial allocation. Each sample has its own record
190 // attached to a single PersistentSampleMap by a common 64-bit identifier. 190 // attached to a single PersistentSampleMap by a common 64-bit identifier.
191 // Since a sparse histogram has two sample maps (active and logged), 191 // Since a sparse histogram has two sample maps (active and logged),
192 // there must be two sets of sample records with diffent IDs. The 192 // there must be two sets of sample records with diffent IDs. The
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (graph_it) 270 if (graph_it)
271 WriteAsciiBucketGraph(count, largest_count, output); 271 WriteAsciiBucketGraph(count, largest_count, output);
272 WriteAsciiBucketValue(count, scaled_total_count, output); 272 WriteAsciiBucketValue(count, scaled_total_count, output);
273 output->append(newline); 273 output->append(newline);
274 it->Next(); 274 it->Next();
275 } 275 }
276 } 276 }
277 277
278 void SparseHistogram::WriteAsciiHeader(const Count total_count, 278 void SparseHistogram::WriteAsciiHeader(const Count total_count,
279 std::string* output) const { 279 std::string* output) const {
280 StringAppendF(output, 280 StringAppendF(output, "Histogram: %s recorded %d samples", histogram_name(),
281 "Histogram: %s recorded %d samples",
282 histogram_name().c_str(),
283 total_count); 281 total_count);
284 if (flags()) 282 if (flags())
285 StringAppendF(output, " (flags = 0x%x)", flags()); 283 StringAppendF(output, " (flags = 0x%x)", flags());
286 } 284 }
287 285
288 } // namespace base 286 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sparse_histogram.h ('k') | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698