OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
6 #define CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ | 6 #define CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 private: | 32 private: |
33 // Latest metrics about record time and memory usage at that time per process. | 33 // Latest metrics about record time and memory usage at that time per process. |
34 // The second values of |memory_sizes_| are in kB. | 34 // The second values of |memory_sizes_| are in kB. |
35 std::map<base::ProcessId, base::TimeTicks> times_; | 35 std::map<base::ProcessId, base::TimeTicks> times_; |
36 std::map<base::ProcessId, int> memory_sizes_; | 36 std::map<base::ProcessId, int> memory_sizes_; |
37 | 37 |
38 DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker); | 38 DISALLOW_COPY_AND_ASSIGN(MemoryGrowthTracker); |
39 }; | 39 }; |
40 | 40 |
41 // PeakMemoryUsageTracker tracks the peak memory usage. | |
42 class PeakMemoryUsageTracker { | |
43 public: | |
44 PeakMemoryUsageTracker(); | |
45 | |
46 // Call with current memory usage. Returns true if the peak has been updated. | |
47 bool Update(int memory_usage); | |
haraken
2016/12/12 11:41:00
unsigned long long?
| |
48 int peak() { return peak_; } | |
49 | |
50 private: | |
51 int peak_; | |
haraken
2016/12/12 11:41:00
unsigned long long?
| |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(PeakMemoryUsageTracker); | |
54 }; | |
55 | |
41 // Handles asynchronous fetching of memory details and logging histograms about | 56 // Handles asynchronous fetching of memory details and logging histograms about |
42 // memory use of various processes. | 57 // memory use of various processes. |
43 // Will run the provided callback when finished. | 58 // Will run the provided callback when finished. |
44 class MetricsMemoryDetails : public MemoryDetails { | 59 class MetricsMemoryDetails : public MemoryDetails { |
45 public: | 60 public: |
46 MetricsMemoryDetails(const base::Closure& callback, | 61 MetricsMemoryDetails(const base::Closure& callback, |
47 MemoryGrowthTracker* memory_growth_tracker); | 62 MemoryGrowthTracker* memory_growth_tracker, |
63 PeakMemoryUsageTracker* peak_memory_usage_tracker); | |
48 | 64 |
49 void set_generate_histograms(bool generate_histograms) { | 65 void set_generate_histograms(bool generate_histograms) { |
50 generate_histograms_ = generate_histograms; | 66 generate_histograms_ = generate_histograms; |
51 } | 67 } |
52 | 68 |
53 protected: | 69 protected: |
54 ~MetricsMemoryDetails() override; | 70 ~MetricsMemoryDetails() override; |
55 | 71 |
56 // MemoryDetails: | 72 // MemoryDetails: |
57 void OnDetailsAvailable() override; | 73 void OnDetailsAvailable() override; |
(...skipping 10 matching lines...) Expand all Loading... | |
68 // Update histograms on memory growth or shrink in renderer processes. | 84 // Update histograms on memory growth or shrink in renderer processes. |
69 void AnalyzeMemoryGrowth(); | 85 void AnalyzeMemoryGrowth(); |
70 | 86 |
71 base::Closure callback_; | 87 base::Closure callback_; |
72 | 88 |
73 // A pointer to MemoryGrowthTracker which is contained in a longer-lived | 89 // A pointer to MemoryGrowthTracker which is contained in a longer-lived |
74 // owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient. | 90 // owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient. |
75 // If it is null, nothing is tracked. | 91 // If it is null, nothing is tracked. |
76 MemoryGrowthTracker* memory_growth_tracker_; | 92 MemoryGrowthTracker* memory_growth_tracker_; |
77 | 93 |
94 // A pointer to PeakMemoryUsageTracker which is contained in a longer-lived | |
95 // owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient. | |
96 // If it is null, nothing is tracked. | |
97 PeakMemoryUsageTracker* peak_memory_usage_tracker_; | |
98 | |
78 // A flag indicating if histogram data should be generated. True on default. | 99 // A flag indicating if histogram data should be generated. True on default. |
79 // If false, then only MemoryGrowthTracker gets notified about memory usage. | 100 // If false, then only MemoryGrowthTracker gets notified about memory usage. |
80 bool generate_histograms_; | 101 bool generate_histograms_; |
81 | 102 |
82 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); | 103 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); |
83 }; | 104 }; |
84 | 105 |
85 #endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ | 106 #endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ |
OLD | NEW |