| Index: base/metrics/persistent_sample_map.cc
|
| diff --git a/base/metrics/persistent_sample_map.cc b/base/metrics/persistent_sample_map.cc
|
| index 51cc0c709d8b0d9087c75d64c512b06e434f6ba7..f931fd579c3ef71edebc1f8a81fc133f35afd7d2 100644
|
| --- a/base/metrics/persistent_sample_map.cc
|
| +++ b/base/metrics/persistent_sample_map.cc
|
| @@ -20,6 +20,9 @@ namespace {
|
| enum NegativeSampleReason {
|
| PERSISTENT_SPARSE_HAVE_LOGGED_BUT_NOT_SAMPLE,
|
| PERSISTENT_SPARSE_SAMPLE_LESS_THAN_LOGGED,
|
| + PERSISTENT_SPARSE_ADDED_NEGATIVE_COUNT,
|
| + PERSISTENT_SPARSE_ADD_WENT_NEGATIVE,
|
| + PERSISTENT_SPARSE_ADD_OVERFLOW,
|
| MAX_NEGATIVE_SAMPLE_REASONS
|
| };
|
|
|
| @@ -197,28 +200,41 @@ bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
|
| *GetOrCreateSampleCountStorage(min) +=
|
| (op == HistogramSamples::ADD) ? count : -count;
|
| #else
|
| + NegativeSampleReason reason = MAX_NEGATIVE_SAMPLE_REASONS;
|
| if (op == HistogramSamples::ADD) {
|
| - *GetOrCreateSampleCountStorage(min) += count;
|
| + // Add should generally be adding only positive values.
|
| + Count* local_count_ptr = GetOrCreateSampleCountStorage(min);
|
| + if (count < 0) {
|
| + reason = PERSISTENT_SPARSE_ADDED_NEGATIVE_COUNT;
|
| + if (*local_count_ptr < -count) {
|
| + reason = PERSISTENT_SPARSE_ADD_WENT_NEGATIVE;
|
| + *local_count_ptr = 0;
|
| + }
|
| + } else {
|
| + *local_count_ptr += count;
|
| + if (*local_count_ptr < 0)
|
| + reason = PERSISTENT_SPARSE_ADD_OVERFLOW;
|
| + }
|
| } else {
|
| // Subtract is used only for determining deltas when reporting which
|
| // means that it's in the "logged" iterator. It should have an active
|
| // sample record and thus there is no need to try to create one.
|
| - NegativeSampleReason reason = MAX_NEGATIVE_SAMPLE_REASONS;
|
| - Count* bucket = GetSampleCountStorage(min);
|
| - if (bucket == nullptr) {
|
| + Count* local_count_ptr = GetSampleCountStorage(min);
|
| + if (local_count_ptr == nullptr) {
|
| reason = PERSISTENT_SPARSE_HAVE_LOGGED_BUT_NOT_SAMPLE;
|
| } else {
|
| - if (*bucket < count) {
|
| + if (*local_count_ptr < count) {
|
| reason = PERSISTENT_SPARSE_SAMPLE_LESS_THAN_LOGGED;
|
| - *bucket = 0;
|
| + *local_count_ptr = 0;
|
| } else {
|
| - *bucket -= count;
|
| + *local_count_ptr -= count;
|
| }
|
| }
|
| - if (reason != MAX_NEGATIVE_SAMPLE_REASONS) {
|
| - UMA_HISTOGRAM_ENUMERATION("UMA.NegativeSamples.Reason", reason,
|
| - MAX_NEGATIVE_SAMPLE_REASONS);
|
| - }
|
| + }
|
| + if (reason != MAX_NEGATIVE_SAMPLE_REASONS) {
|
| + NOTREACHED();
|
| + UMA_HISTOGRAM_ENUMERATION("UMA.NegativeSamples.Reason", reason,
|
| + MAX_NEGATIVE_SAMPLE_REASONS);
|
| }
|
| #endif
|
| }
|
|
|