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

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

Issue 1780993002: Break global impact of PersistentHistogramAllocator into a separate class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-hp
Patch Set: fixed bad formatting from upstream scoped_ptr change 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 | « no previous file | base/metrics/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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 // See header file for details and examples. 8 // See header file for details and examples.
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 HistogramBase::Sample minimum_; 140 HistogramBase::Sample minimum_;
141 HistogramBase::Sample maximum_; 141 HistogramBase::Sample maximum_;
142 uint32_t bucket_count_; 142 uint32_t bucket_count_;
143 int32_t flags_; 143 int32_t flags_;
144 144
145 private: 145 private:
146 DISALLOW_COPY_AND_ASSIGN(Factory); 146 DISALLOW_COPY_AND_ASSIGN(Factory);
147 }; 147 };
148 148
149 HistogramBase* Histogram::Factory::Build() { 149 HistogramBase* Histogram::Factory::Build() {
150 // Import histograms from known persistent storage. Histograms could have
151 // been added by other processes and they must be fetched and recognized
152 // locally in order to be found by FindHistograms() below. If the persistent
153 // memory segment is not shared between processes, this call does nothing.
154 PersistentHistogramAllocator::ImportGlobalHistograms();
155
156 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_); 150 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name_);
157 if (!histogram) { 151 if (!histogram) {
158 // To avoid racy destruction at shutdown, the following will be leaked. 152 // To avoid racy destruction at shutdown, the following will be leaked.
159 const BucketRanges* created_ranges = CreateRanges(); 153 const BucketRanges* created_ranges = CreateRanges();
160 const BucketRanges* registered_ranges = 154 const BucketRanges* registered_ranges =
161 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges); 155 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(created_ranges);
162 156
163 // In most cases, the bucket-count, minimum, and maximum values are known 157 // In most cases, the bucket-count, minimum, and maximum values are known
164 // when the code is written and so are passed in explicitly. In other 158 // when the code is written and so are passed in explicitly. In other
165 // cases (such as with a CustomHistogram), they are calculated dynamically 159 // cases (such as with a CustomHistogram), they are calculated dynamically
166 // at run-time. In the latter case, those ctor parameters are zero and 160 // at run-time. In the latter case, those ctor parameters are zero and
167 // the results extracted from the result of CreateRanges(). 161 // the results extracted from the result of CreateRanges().
168 if (bucket_count_ == 0) { 162 if (bucket_count_ == 0) {
169 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count()); 163 bucket_count_ = static_cast<uint32_t>(registered_ranges->bucket_count());
170 minimum_ = registered_ranges->range(1); 164 minimum_ = registered_ranges->range(1);
171 maximum_ = registered_ranges->range(bucket_count_ - 1); 165 maximum_ = registered_ranges->range(bucket_count_ - 1);
172 } 166 }
173 167
174 // Try to create the histogram using a "persistent" allocator. As of 168 // Try to create the histogram using a "persistent" allocator. As of
175 // 2016-02-25, the availability of such is controlled by a base::Feature 169 // 2016-02-25, the availability of such is controlled by a base::Feature
176 // that is off by default. If the allocator doesn't exist or if 170 // that is off by default. If the allocator doesn't exist or if
177 // allocating from it fails, code below will allocate the histogram from 171 // allocating from it fails, code below will allocate the histogram from
178 // the process heap. 172 // the process heap.
179 PersistentHistogramAllocator::Reference histogram_ref = 0; 173 PersistentHistogramAllocator::Reference histogram_ref = 0;
180 std::unique_ptr<HistogramBase> tentative_histogram; 174 std::unique_ptr<HistogramBase> tentative_histogram;
181 PersistentHistogramAllocator* allocator = 175 PersistentHistogramAllocator* allocator = GlobalHistogramAllocator::Get();
182 PersistentHistogramAllocator::GetGlobalAllocator();
183 if (allocator) { 176 if (allocator) {
184 tentative_histogram = allocator->AllocateHistogram( 177 tentative_histogram = allocator->AllocateHistogram(
185 histogram_type_, 178 histogram_type_,
186 name_, 179 name_,
187 minimum_, 180 minimum_,
188 maximum_, 181 maximum_,
189 registered_ranges, 182 registered_ranges,
190 flags_, 183 flags_,
191 &histogram_ref); 184 &histogram_ref);
192 } 185 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 const std::string& name, 275 const std::string& name,
283 Sample minimum, 276 Sample minimum,
284 Sample maximum, 277 Sample maximum,
285 const BucketRanges* ranges, 278 const BucketRanges* ranges,
286 HistogramBase::AtomicCount* counts, 279 HistogramBase::AtomicCount* counts,
287 HistogramBase::AtomicCount* logged_counts, 280 HistogramBase::AtomicCount* logged_counts,
288 uint32_t counts_size, 281 uint32_t counts_size,
289 HistogramSamples::Metadata* meta, 282 HistogramSamples::Metadata* meta,
290 HistogramSamples::Metadata* logged_meta) { 283 HistogramSamples::Metadata* logged_meta) {
291 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts, 284 return WrapUnique(new Histogram(name, minimum, maximum, ranges, counts,
292 logged_counts, counts_size, meta, 285 logged_counts, counts_size, meta,
293 logged_meta)); 286 logged_meta));
294 } 287 }
295 288
296 // Calculate what range of values are held in each bucket. 289 // Calculate what range of values are held in each bucket.
297 // We have to be careful that we don't pick a ratio between starting points in 290 // We have to be careful that we don't pick a ratio between starting points in
298 // consecutive buckets that is sooo small, that the integer bounds are the same 291 // consecutive buckets that is sooo small, that the integer bounds are the same
299 // (effectively making one bucket get no values). We need to avoid: 292 // (effectively making one bucket get no values). We need to avoid:
300 // ranges(i) == ranges(i + 1) 293 // ranges(i) == ranges(i + 1)
301 // To avoid that, we just do a fine-grained bucket width as far as we need to 294 // To avoid that, we just do a fine-grained bucket width as far as we need to
302 // until we get a ratio that moves us along at least 2 units at a time. From 295 // until we get a ratio that moves us along at least 2 units at a time. From
303 // that bucket onward we do use the exponential growth of buckets. 296 // that bucket onward we do use the exponential growth of buckets.
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 Sample sample = custom_ranges[i]; 1165 Sample sample = custom_ranges[i];
1173 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) 1166 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1)
1174 return false; 1167 return false;
1175 if (sample != 0) 1168 if (sample != 0)
1176 has_valid_range = true; 1169 has_valid_range = true;
1177 } 1170 }
1178 return has_valid_range; 1171 return has_valid_range;
1179 } 1172 }
1180 1173
1181 } // namespace base 1174 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698