| Index: base/metrics/persistent_sample_map.cc
|
| diff --git a/base/metrics/persistent_sample_map.cc b/base/metrics/persistent_sample_map.cc
|
| index cc20f45412bec2160f62dfb7aa9380e6b9a4caca..9857b97aa3a5b5bb3bb314beb535632fda6173f8 100644
|
| --- a/base/metrics/persistent_sample_map.cc
|
| +++ b/base/metrics/persistent_sample_map.cc
|
| @@ -204,8 +204,6 @@ bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
|
| }
|
|
|
| Count* PersistentSampleMap::GetSampleCountStorage(Sample value) {
|
| - DCHECK_LE(0, value);
|
| -
|
| // If |value| is already in the map, just return that.
|
| auto it = sample_counts_.find(value);
|
| if (it != sample_counts_.end())
|
| @@ -248,6 +246,7 @@ Count* PersistentSampleMap::GetOrCreateSampleCountStorage(Sample value) {
|
| }
|
|
|
| Count* PersistentSampleMap::ImportSamples(Sample until_value) {
|
| + Count* found_count = nullptr;
|
| PersistentMemoryAllocator::Reference ref;
|
| while ((ref = records_->GetNext()) != 0) {
|
| SampleRecord* record =
|
| @@ -259,9 +258,8 @@ Count* PersistentSampleMap::ImportSamples(Sample until_value) {
|
|
|
| // Check if the record's value is already known.
|
| if (!ContainsKey(sample_counts_, record->value)) {
|
| - // No: Add it to map of known values if the value is valid.
|
| - if (record->value >= 0)
|
| - sample_counts_[record->value] = &record->count;
|
| + // No: Add it to map of known values.
|
| + sample_counts_[record->value] = &record->count;
|
| } else {
|
| // Yes: Ignore it; it's a duplicate caused by a race condition -- see
|
| // code & comment in GetOrCreateSampleCountStorage() for details.
|
| @@ -269,12 +267,21 @@ Count* PersistentSampleMap::ImportSamples(Sample until_value) {
|
| DCHECK_EQ(0, record->count);
|
| }
|
|
|
| - // Stop if it's the value being searched for.
|
| - if (record->value == until_value)
|
| - return &record->count;
|
| + // Check if it's the value being searched for. There is a small chance
|
| + // that some histogram is actually using the "kAllSamples" value. In
|
| + // that case, keep the pointer for later but continue loading all the
|
| + // rest of the samples, too. And because race conditions can cause
|
| + // multiple records for a single value, be sure to only return the
|
| + // first one found.
|
| + if (record->value == until_value) {
|
| + if (!found_count)
|
| + found_count = &record->count;
|
| + if (until_value != kAllSamples)
|
| + break;
|
| + }
|
| }
|
|
|
| - return nullptr;
|
| + return found_count;
|
| }
|
|
|
| } // namespace base
|
|
|