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

Unified Diff: base/metrics/persistent_sample_map.cc

Issue 2668383005: Report reasons for a negative histogram sample count. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« 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