| Index: base/metrics/persistent_sample_map.cc
|
| diff --git a/base/metrics/persistent_sample_map.cc b/base/metrics/persistent_sample_map.cc
|
| index 1cc425423c787dc4575ceaeed0640c8337ac59d0..131e47b68a0d33eee92a44c99bc12c2c67594514 100644
|
| --- a/base/metrics/persistent_sample_map.cc
|
| +++ b/base/metrics/persistent_sample_map.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/logging.h"
|
| #include "base/memory/ptr_util.h"
|
| +#include "base/metrics/histogram_macros.h"
|
| #include "base/metrics/persistent_histogram_allocator.h"
|
| #include "base/stl_util.h"
|
|
|
| @@ -16,6 +17,12 @@ typedef HistogramBase::Sample Sample;
|
|
|
| namespace {
|
|
|
| +enum NegativeSampleReason {
|
| + PERSISTENT_SPARSE_HAVE_LOGGED_BUT_NOT_SAMPLE,
|
| + PERSISTENT_SPARSE_SAMPLE_LESS_THAN_LOGGED,
|
| + MAX_NEGATIVE_SAMPLE_REASONS
|
| +};
|
| +
|
| // An iterator for going through a PersistentSampleMap. The logic here is
|
| // identical to that of SampleMapIterator but with different data structures.
|
| // Changes here likely need to be duplicated there.
|
| @@ -181,11 +188,39 @@ bool PersistentSampleMap::AddSubtractImpl(SampleCountIterator* iter,
|
| Count count;
|
| for (; !iter->Done(); iter->Next()) {
|
| iter->Get(&min, &max, &count);
|
| + if (count == 0)
|
| + continue;
|
| if (min + 1 != max)
|
| return false; // SparseHistogram only supports bucket with size 1.
|
|
|
| +#if 0 // TODO(bcwhite) Re-enable efficient version after crbug.com/682680.
|
| *GetOrCreateSampleCountStorage(min) +=
|
| (op == HistogramSamples::ADD) ? count : -count;
|
| +#else
|
| + if (op == HistogramSamples::ADD) {
|
| + *GetOrCreateSampleCountStorage(min) += count;
|
| + } 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) {
|
| + reason = PERSISTENT_SPARSE_HAVE_LOGGED_BUT_NOT_SAMPLE;
|
| + } else {
|
| + if (*bucket < count) {
|
| + reason = PERSISTENT_SPARSE_SAMPLE_LESS_THAN_LOGGED;
|
| + *bucket = 0;
|
| + } else {
|
| + *bucket -= count;
|
| + }
|
| + }
|
| + if (reason != MAX_NEGATIVE_SAMPLE_REASONS) {
|
| + UMA_HISTOGRAM_ENUMERATION("UMA.NegativeSamples.Reason", reason,
|
| + MAX_NEGATIVE_SAMPLE_REASONS);
|
| + }
|
| + }
|
| +#endif
|
| }
|
| return true;
|
| }
|
|
|