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

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

Issue 1719363002: Collect information about failing histogram factory calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 9 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/metrics_hashes.cc ('k') | base/metrics/statistics_recorder.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/persistent_histogram_allocator.h" 5 #include "base/metrics/persistent_histogram_allocator.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 RecordCreateHistogramResult(CREATE_HISTOGRAM_SUCCESS); 288 RecordCreateHistogramResult(CREATE_HISTOGRAM_SUCCESS);
289 return histogram; 289 return histogram;
290 } 290 }
291 291
292 // Copy the histogram_data to local storage because anything in persistent 292 // Copy the histogram_data to local storage because anything in persistent
293 // memory cannot be trusted as it could be changed at any moment by a 293 // memory cannot be trusted as it could be changed at any moment by a
294 // malicious actor that shares access. The contents of histogram_data are 294 // malicious actor that shares access. The contents of histogram_data are
295 // validated below; the local copy is to ensure that the contents cannot 295 // validated below; the local copy is to ensure that the contents cannot
296 // be externally changed between validation and use. 296 // be externally changed between validation and use.
297 PersistentHistogramData histogram_data = *histogram_data_ptr; 297 PersistentHistogramData histogram_data = *histogram_data_ptr;
298 CHECK_EQ(histogram_data.histogram_type, histogram_data_ptr->histogram_type);
299 CHECK_EQ(histogram_data.flags, histogram_data_ptr->flags);
300 CHECK_EQ(histogram_data.minimum, histogram_data_ptr->minimum);
301 CHECK_EQ(histogram_data.maximum, histogram_data_ptr->maximum);
302 CHECK_EQ(histogram_data.bucket_count, histogram_data_ptr->bucket_count);
303 CHECK_EQ(histogram_data.ranges_checksum, histogram_data_ptr->ranges_checksum);
298 304
299 HistogramBase::Sample* ranges_data = 305 HistogramBase::Sample* ranges_data =
300 memory_allocator_->GetAsObject<HistogramBase::Sample>( 306 memory_allocator_->GetAsObject<HistogramBase::Sample>(
301 histogram_data.ranges_ref, kTypeIdRangesArray); 307 histogram_data.ranges_ref, kTypeIdRangesArray);
302 308
303 const uint32_t max_buckets = 309 const uint32_t max_buckets =
304 std::numeric_limits<uint32_t>::max() / sizeof(HistogramBase::Sample); 310 std::numeric_limits<uint32_t>::max() / sizeof(HistogramBase::Sample);
305 size_t required_bytes = 311 size_t required_bytes =
306 (histogram_data.bucket_count + 1) * sizeof(HistogramBase::Sample); 312 (histogram_data.bucket_count + 1) * sizeof(HistogramBase::Sample);
307 size_t allocated_bytes = 313 size_t allocated_bytes =
(...skipping 30 matching lines...) Expand all
338 NOTREACHED(); 344 NOTREACHED();
339 return nullptr; 345 return nullptr;
340 } 346 }
341 347
342 // After the main "counts" array is a second array using for storing what 348 // After the main "counts" array is a second array using for storing what
343 // was previously logged. This is used to calculate the "delta" during 349 // was previously logged. This is used to calculate the "delta" during
344 // snapshot operations. 350 // snapshot operations.
345 HistogramBase::AtomicCount* logged_data = 351 HistogramBase::AtomicCount* logged_data =
346 counts_data + histogram_data.bucket_count; 352 counts_data + histogram_data.bucket_count;
347 353
354 CHECK_LT(0, histogram_data.minimum);
355 CHECK_LT(0, histogram_data.maximum);
348 std::string name(histogram_data_ptr->name); 356 std::string name(histogram_data_ptr->name);
349 scoped_ptr<HistogramBase> histogram; 357 scoped_ptr<HistogramBase> histogram;
350 switch (histogram_data.histogram_type) { 358 switch (histogram_data.histogram_type) {
351 case HISTOGRAM: 359 case HISTOGRAM:
352 histogram = Histogram::PersistentCreate( 360 histogram = Histogram::PersistentCreate(
353 name, histogram_data.minimum, histogram_data.maximum, ranges, 361 name, histogram_data.minimum, histogram_data.maximum, ranges,
354 counts_data, logged_data, histogram_data.bucket_count, 362 counts_data, logged_data, histogram_data.bucket_count,
355 &histogram_data_ptr->samples_metadata, 363 &histogram_data_ptr->samples_metadata,
356 &histogram_data_ptr->logged_metadata); 364 &histogram_data_ptr->logged_metadata);
357 DCHECK(histogram); 365 DCHECK(histogram);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 scoped_ptr<HistogramBase> histogram = 586 scoped_ptr<HistogramBase> histogram =
579 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); 587 g_allocator->GetNextHistogramWithIgnore(&iter, last_created);
580 if (!histogram) 588 if (!histogram)
581 break; 589 break;
582 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); 590 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release());
583 } 591 }
584 } 592 }
585 } 593 }
586 594
587 } // namespace base 595 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/metrics_hashes.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698