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

Unified Diff: components/metrics/metrics_service.h

Issue 1485763002: Merge multiple histogram snapshots into single one for reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: added merge test Created 5 years, 1 month 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
Index: components/metrics/metrics_service.h
diff --git a/components/metrics/metrics_service.h b/components/metrics/metrics_service.h
index 8d81484da9896ad8c643930db52730da2b8b3a1b..3b71571f183b77103fb63f69588ff17cf8f89c2b 100644
--- a/components/metrics/metrics_service.h
+++ b/components/metrics/metrics_service.h
@@ -9,6 +9,7 @@
#define COMPONENTS_METRICS_METRICS_SERVICE_H_
#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -104,6 +105,8 @@ class MetricsService : public base::HistogramFlattener {
SHUTDOWN_COMPLETE = 700,
};
+ typedef std::set<base::HistogramBase*> HistogramSet;
+
// Creates the MetricsService with the given |state_manager|, |client|, and
// |local_state|. Does not take ownership of the paramaters; instead stores
// a weak pointer to each. Caller should ensure that the parameters are valid
@@ -296,21 +299,14 @@ class MetricsService : public base::HistogramFlattener {
// A class for iterating over the histograms in persistent memory segments.
class PersistentHistogramIterator {
- // This class provides a reference-counted pointer to a histogram which
- // is necessary for histogram objects that are dynamically generated
- // (generally pointing to persistent memory) and to be owned by an STL
- // iterator which, by necessity, must be copyable.
- class HistogramPointer : public base::RefCounted<HistogramPointer> {
- public:
- HistogramPointer(base::HistogramBase* h) : histogram_(h) {}
- base::HistogramBase* get() { return histogram_.get(); }
-
- private:
- scoped_ptr<base::HistogramBase> histogram_;
- };
-
public:
- PersistentHistogramIterator(AllocatorSet& allocators,
+ // The |found_histograms| set will be loaded with pointers to all the
+ // histograms found during iteration. This is important because users
+ // of the iterator may expect the returned histograms to live longer
+ // than a particular iteration step. The caller must delete these
+ // if necessary.
+ PersistentHistogramIterator(HistogramSet* found_histograms,
+ AllocatorSet& allocators,
AllocatorSet::iterator pos);
PersistentHistogramIterator& operator++();
@@ -329,7 +325,7 @@ class MetricsService : public base::HistogramFlattener {
histogram_iter_ != rhs.histogram_iter_;
}
base::HistogramBase* operator*() {
- return current_histogram_->get();
+ return current_histogram_;
}
private:
@@ -337,9 +333,8 @@ class MetricsService : public base::HistogramFlattener {
AllocatorSet::iterator allocator_iter_;
base::PersistentMemoryAllocator::Iterator histogram_iter_;
- // STL iterators must be copyable so a regular scoped_ptr is not
- // sufficient as it doesn't allow such. A ref-counted one is needed.
- scoped_refptr<HistogramPointer> current_histogram_;
+ HistogramSet* found_histograms_;
+ base::HistogramBase* current_histogram_;
};
typedef std::vector<SyntheticTrialGroup> SyntheticTrialGroups;
@@ -483,7 +478,7 @@ class MetricsService : public base::HistogramFlattener {
void SkipAndDiscardUpload();
// Begin and End iterators for going through all the metrics under management.
- PersistentHistogramIterator persistent_begin();
+ PersistentHistogramIterator persistent_begin(HistogramSet* found);
PersistentHistogramIterator persistent_end();
// Manager for the various in-flight logs.

Powered by Google App Engine
This is Rietveld 408576698