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

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

Issue 1693463003: Track number of instances with a corrupt allocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | tools/metrics/histograms/histograms.xml » ('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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/histogram_persistence.h" 5 #include "base/metrics/histogram_persistence.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 28 matching lines...) Expand all
39 39
40 // Could not allocate histogram memory due to lack of space. 40 // Could not allocate histogram memory due to lack of space.
41 CREATE_HISTOGRAM_ALLOCATOR_FULL, 41 CREATE_HISTOGRAM_ALLOCATOR_FULL,
42 42
43 // Could not allocate histogram memory due to unknown error. 43 // Could not allocate histogram memory due to unknown error.
44 CREATE_HISTOGRAM_ALLOCATOR_ERROR, 44 CREATE_HISTOGRAM_ALLOCATOR_ERROR,
45 45
46 // Histogram was of unknown type. 46 // Histogram was of unknown type.
47 CREATE_HISTOGRAM_UNKNOWN_TYPE, 47 CREATE_HISTOGRAM_UNKNOWN_TYPE,
48 48
49 // Instance has detected a corrupt allocator (recorded only once).
50 CREATE_HISTOGRAM_ALLOCATOR_NEWLY_CORRUPT,
51
49 // Always keep this at the end. 52 // Always keep this at the end.
50 CREATE_HISTOGRAM_MAX 53 CREATE_HISTOGRAM_MAX
51 }; 54 };
52 55
53 // Type identifiers used when storing in persistent memory so they can be 56 // Type identifiers used when storing in persistent memory so they can be
54 // identified during extraction; the first 4 bytes of the SHA1 of the name 57 // identified during extraction; the first 4 bytes of the SHA1 of the name
55 // is used as a unique integer. A "version number" is added to the base 58 // is used as a unique integer. A "version number" is added to the base
56 // so that, if the structure of that object changes, stored older versions 59 // so that, if the structure of that object changes, stored older versions
57 // will be safely ignored. 60 // will be safely ignored.
58 enum : uint32_t { 61 enum : uint32_t {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 HistogramType histogram_type, 338 HistogramType histogram_type,
336 const std::string& name, 339 const std::string& name,
337 int minimum, 340 int minimum,
338 int maximum, 341 int maximum,
339 const BucketRanges* bucket_ranges, 342 const BucketRanges* bucket_ranges,
340 int32_t flags, 343 int32_t flags,
341 PersistentMemoryAllocator::Reference* ref_ptr) { 344 PersistentMemoryAllocator::Reference* ref_ptr) {
342 if (!allocator) 345 if (!allocator)
343 return nullptr; 346 return nullptr;
344 347
348 // If the allocator is corrupt, don't waste time trying anything else.
349 // This also allows differentiating on the dashboard between allocations
350 // failed due to a corrupt allocator and the number of process instances
351 // with one, the latter being idicated by "newly corrupt", below.
352 if (allocator->IsCorrupt()) {
353 RecordCreateHistogramResult(CREATE_HISTOGRAM_ALLOCATOR_CORRUPT);
354 return nullptr;
355 }
356
345 size_t bucket_count = bucket_ranges->bucket_count(); 357 size_t bucket_count = bucket_ranges->bucket_count();
346 // An overflow such as this, perhaps as the result of a milicious actor, 358 // An overflow such as this, perhaps as the result of a milicious actor,
347 // could lead to writing beyond the allocation boundary and into other 359 // could lead to writing beyond the allocation boundary and into other
348 // memory. Just fail the allocation and let the caller deal with it. 360 // memory. Just fail the allocation and let the caller deal with it.
349 if (bucket_count > std::numeric_limits<int32_t>::max() / 361 if (bucket_count > std::numeric_limits<int32_t>::max() /
350 sizeof(HistogramBase::AtomicCount)) { 362 sizeof(HistogramBase::AtomicCount)) {
351 NOTREACHED(); 363 NOTREACHED();
352 return nullptr; 364 return nullptr;
353 } 365 }
354 size_t counts_bytes = bucket_count * sizeof(HistogramBase::AtomicCount); 366 size_t counts_bytes = bucket_count * sizeof(HistogramBase::AtomicCount);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 HistogramBase* histogram = 405 HistogramBase* histogram =
394 CreatePersistentHistogram(allocator, histogram_data); 406 CreatePersistentHistogram(allocator, histogram_data);
395 DCHECK(histogram); 407 DCHECK(histogram);
396 if (ref_ptr != nullptr) 408 if (ref_ptr != nullptr)
397 *ref_ptr = histogram_ref; 409 *ref_ptr = histogram_ref;
398 return histogram; 410 return histogram;
399 } 411 }
400 412
401 CreateHistogramResultType result; 413 CreateHistogramResultType result;
402 if (allocator->IsCorrupt()) { 414 if (allocator->IsCorrupt()) {
415 RecordCreateHistogramResult(CREATE_HISTOGRAM_ALLOCATOR_NEWLY_CORRUPT);
403 result = CREATE_HISTOGRAM_ALLOCATOR_CORRUPT; 416 result = CREATE_HISTOGRAM_ALLOCATOR_CORRUPT;
404 } else if (allocator->IsFull()) { 417 } else if (allocator->IsFull()) {
405 result = CREATE_HISTOGRAM_ALLOCATOR_FULL; 418 result = CREATE_HISTOGRAM_ALLOCATOR_FULL;
406 } else { 419 } else {
407 result = CREATE_HISTOGRAM_ALLOCATOR_ERROR; 420 result = CREATE_HISTOGRAM_ALLOCATOR_ERROR;
408 } 421 }
409 RecordCreateHistogramResult(result); 422 RecordCreateHistogramResult(result);
410 NOTREACHED() << "error=" << result; 423 NOTREACHED() << "error=" << result;
411 424
412 return nullptr; 425 return nullptr;
(...skipping 17 matching lines...) Expand all
430 for (;;) { 443 for (;;) {
431 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter); 444 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter);
432 if (!histogram) 445 if (!histogram)
433 break; 446 break;
434 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram); 447 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram);
435 } 448 }
436 } 449 }
437 } 450 }
438 451
439 } // namespace base 452 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698