Index: base/metrics/histogram_snapshot_manager.h |
diff --git a/base/metrics/histogram_snapshot_manager.h b/base/metrics/histogram_snapshot_manager.h |
index 0d2f05bf6819e15f071e87d00eda93bb7c31906a..1f3e0330158bc46af54caa0f576594d877dfb5ac 100644 |
--- a/base/metrics/histogram_snapshot_manager.h |
+++ b/base/metrics/histogram_snapshot_manager.h |
@@ -24,6 +24,32 @@ class HistogramFlattener; |
// calling for the marginal change (a.k.a., delta) in a histogram to be |
// recorded. |
class BASE_EXPORT HistogramSnapshotManager { |
+ struct SampleInfo { |
+ // A histogram associated with this sample; it may be one of many if |
+ // several have been aggregated into the same "accumulated" sample set. |
+ // Ownership of the histogram remains elsewhere and this pointer is |
+ // cleared by FinishDeltas() called at the end of PrepareDeltas(). |
+ const HistogramBase* histogram; |
+ |
+ // The previous snapshot values that were logged to the server so can |
+ // record only the delta with the next log. |
+ scoped_ptr<HistogramSamples> logged; |
+ |
+ // The current snapshot values being accumulated. There is no need for |
+ // this to be a scoped_ptr<> because it is only used temporarily during |
+ // a loop after which it replaces the "logged" value. |
+ HistogramSamples* accumulated; |
+ |
+ // The set of inconsistencies already seen for the histogram. |
+ int inconsistencies; |
Alexei Svitkine (slow)
2015/12/04 18:30:11
Nit: inconsistencies_count or num_inconsistencies
bcwhite
2015/12/08 17:32:18
It's not a count but a set of flags. I'll add to
|
+ |
+ SampleInfo() : histogram(nullptr), |
+ accumulated(nullptr), |
+ inconsistencies(0) {} |
+ }; |
+ |
+ typedef std::map<uint64_t, SampleInfo> HashInfoMap; |
+ |
public: |
explicit HistogramSnapshotManager(HistogramFlattener* histogram_flattener); |
virtual ~HistogramSnapshotManager(); |
@@ -33,34 +59,43 @@ class BASE_EXPORT HistogramSnapshotManager { |
// |required_flags| is used to select histograms to be recorded. |
// Only histograms that have all the flags specified by the argument will be |
// chosen. If all histograms should be recorded, set it to |
- // |Histogram::kNoFlags|. |
+ // |Histogram::kNoFlags|. Though any "forward" iterator will work, the |
+ // histograms over which it iterates *must* remain valid until this method |
+ // returns; the iterator cannot deallocate histograms once it iterates past |
+ // them. |
template <class ForwardHistogramIterator> |
void PrepareDeltas(ForwardHistogramIterator begin, |
ForwardHistogramIterator end, |
HistogramBase::Flags flags_to_set, |
HistogramBase::Flags required_flags) { |
+ StartDeltas(); |
for (ForwardHistogramIterator it = begin; it != end; ++it) { |
(*it)->SetFlags(flags_to_set); |
if (((*it)->flags() & required_flags) == required_flags) |
- PrepareDelta(**it); |
+ PrepareDelta(*it); |
} |
+ FinishDeltas(); |
} |
private: |
- // Snapshot this histogram, and record the delta. |
- void PrepareDelta(const HistogramBase& histogram); |
+ FRIEND_TEST_ALL_PREFIXES(HistogramSnapshotManagerTest, CheckMerge); |
+ |
+ // Start delta accumulation. |
+ void StartDeltas(); |
+ |
+ // Snapshot this histogram and record the delta. |
+ void PrepareDelta(const HistogramBase* histogram); |
+ |
+ // Finish all deltas and flush them to the Flattener. |
+ void FinishDeltas(); |
// Try to detect and fix count inconsistency of logged samples. |
void InspectLoggedSamplesInconsistency( |
const HistogramSamples& new_snapshot, |
HistogramSamples* logged_samples); |
- // For histograms, track what we've already recorded (as a sample for |
- // each histogram) so that we can record only the delta with the next log. |
- std::map<uint64_t, HistogramSamples*> logged_samples_; |
- |
- // List of histograms found to be corrupt, and their problems. |
- std::map<uint64_t, int> inconsistencies_; |
+ // For histograms, track what has been previously seen. |
+ HashInfoMap known_histograms_; |
// |histogram_flattener_| handles the logistics of recording the histogram |
// deltas. |