Index: chrome/browser/metrics/metrics_memory_details.h |
diff --git a/chrome/browser/metrics/metrics_memory_details.h b/chrome/browser/metrics/metrics_memory_details.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a9c83c31d36a088bb8c51e00ed5aeea1b78f3f4b |
--- /dev/null |
+++ b/chrome/browser/metrics/metrics_memory_details.h |
@@ -0,0 +1,71 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
+#define CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
+ |
+#include <map> |
+ |
+#include "base/callback.h" |
+#include "chrome/browser/memory_details.h" |
+ |
+// MemoryGrowthTracker tracks latest metrics about record time and memory usage |
+// at that time per process. |
+class MemoryGrowthTracker { |
+ public: |
+ MemoryGrowthTracker(); |
+ ~MemoryGrowthTracker(); |
+ |
+ // If 30 minutes have passed since last UMA record, UpdateSample() computes |
Ilya Sherman
2015/01/16 04:57:36
Why 30 minutes? Is it too expensive to compute on
Alexei Svitkine (slow)
2015/01/16 16:07:50
I'm not changing this - this is just moving from t
|
+ // a difference between current memory usage |sample| of process |pid| and |
+ // stored memory usage at the time of last UMA record. Then, it updates the |
+ // stored memory usage to |sample|, stores the difference in |diff| and |
+ // returns true. |
+ // If no memory usage of |pid| has not been recorded so far or 30 minutes |
+ // have not passed since last record, it just returns false. |
+ // |sample| is memory usage in kB. |
+ bool UpdateSample(base::ProcessId pid, int sample, int* diff); |
+ |
+ private: |
+ // Latest metrics about record time and memory usage at that time per process. |
+ // The second values of |memory_sizes_| are in kB. |
+ std::map<base::ProcessId, base::TimeTicks> times_; |
+ std::map<base::ProcessId, int> memory_sizes_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker); |
+}; |
+ |
+// Handles asynchronous fetching of memory details. |
+// Will run the provided task after finished. |
+class MetricsMemoryDetails : public MemoryDetails { |
+ public: |
+ MetricsMemoryDetails(const base::Closure& callback, |
+ MemoryGrowthTracker* memory_growth_tracker); |
+ |
+ protected: |
+ ~MetricsMemoryDetails() override; |
+ |
+ // MemoryDetails: |
+ void OnDetailsAvailable() override; |
+ |
+ private: |
+ // Updates the global histograms for tracking memory usage. |
+ void UpdateHistograms(); |
+ |
+#if defined(OS_CHROMEOS) |
+ void UpdateSwapHistograms(); |
+#endif |
+ |
+ base::Closure callback_; |
+ |
+ // A pointer to MemoryGrowthTracker which is contained in a longer-lived |
+ // owner of MemoryDetails, for example, ChromeMetricsServiceClient. |
+ // The pointer is NULL by default and set by SetMemoryGrowthTracker(). |
+ // If it is NULL, nothing is tracked. |
Ilya Sherman
2015/01/16 04:57:36
Please update this comment -- there's no longer a
Alexei Svitkine (slow)
2015/01/16 16:07:50
Done.
|
+ MemoryGrowthTracker* memory_growth_tracker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
+}; |
+ |
+#endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |