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

Unified Diff: chrome/browser/metrics/metrics_memory_details.h

Issue 823533004: Move memory histograms generation to MetricsMemoryDetails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better class comment. Created 5 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
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..cee946f81174d0920f7454dddcca24200fe0ec17
--- /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
+ // 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 and logging histograms about
+// memory use of various processes.
+// Will run the provided callback when 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 MetricsMemoryDetails, for example, ChromeMetricsServiceClient.
+ // If it is null, nothing is tracked.
+ MemoryGrowthTracker* memory_growth_tracker_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
+};
+
+#endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.cc ('k') | chrome/browser/metrics/metrics_memory_details.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698