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

Unified Diff: base/metrics/statistics_recorder.h

Issue 1181293005: Optimize memory use of registered histograms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve comments. Created 5 years, 6 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 | « base/metrics/histogram_base.h ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.h
diff --git a/base/metrics/statistics_recorder.h b/base/metrics/statistics_recorder.h
index b5230575963e079789fac0f36c22fd2be5ba5ae5..545c4663c529aa3567b0b402813f9f62b3d854d4 100644
--- a/base/metrics/statistics_recorder.h
+++ b/base/metrics/statistics_recorder.h
@@ -76,8 +76,24 @@ class BASE_EXPORT StatisticsRecorder {
static void GetSnapshot(const std::string& query, Histograms* snapshot);
private:
+ // HistogramNameRef holds a weak const ref to the name field of the associated
+ // Histogram object, allowing re-use of the underlying string storage for the
+ // map keys. The wrapper is required as using "const std::string&" as the key
+ // results in compile errors.
+ struct HistogramNameRef {
+ explicit HistogramNameRef(const std::string& name) : name_(name) {};
+
+ // Operator < is necessary to use this type as a std::map key.
+ bool operator<(const HistogramNameRef& other) const {
+ return name_ < other.name_;
+ }
+
+ // Weak, owned by the associated Histogram object.
+ const std::string& name_;
+ };
+
// We keep all registered histograms in a map, from name to histogram.
- typedef std::map<std::string, HistogramBase*> HistogramMap;
+ typedef std::map<HistogramNameRef, HistogramBase*> HistogramMap;
// We keep all |bucket_ranges_| in a map, from checksum to a list of
// |bucket_ranges_|. Checksum is calculated from the |ranges_| in
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698