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

Side by Side Diff: chrome/browser/metrics/metrics_memory_details.h

Issue 2396743002: Leak reports collect information about the memory usage (Closed)
Patch Set: Added setter for |generate_histograms_| Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/memory_details.h" 13 #include "chrome/browser/memory_details.h"
14 14
15 // MemoryGrowthTracker tracks latest metrics about record time and memory usage 15 // MemoryGrowthTracker tracks latest metrics about record time and memory usage
16 // at that time per process. 16 // at that time per process.
17 class MemoryGrowthTracker { 17 class MemoryGrowthTracker {
18 public: 18 public:
19 MemoryGrowthTracker(); 19 MemoryGrowthTracker();
20 ~MemoryGrowthTracker(); 20 virtual ~MemoryGrowthTracker();
21 21
22 // If 30 minutes have passed since last UMA record, UpdateSample() computes 22 // If 30 minutes have passed since last UMA record, UpdateSample() computes
23 // a difference between current memory usage |sample| of process |pid| and 23 // a difference between current memory usage |sample| of process |pid| and
24 // stored memory usage at the time of last UMA record. Then, it updates the 24 // stored memory usage at the time of last UMA record. Then, it updates the
25 // stored memory usage to |sample|, stores the difference in |diff| and 25 // stored memory usage to |sample|, stores the difference in |diff| and
26 // returns true. 26 // returns true.
27 // If no memory usage of |pid| has not been recorded so far or 30 minutes 27 // If no memory usage of |pid| has not been recorded so far or 30 minutes
28 // have not passed since last record, it just returns false. 28 // have not passed since last record, it just returns false.
29 // |sample| is memory usage in kB. 29 // |sample| is memory usage in kB.
30 bool UpdateSample(base::ProcessId pid, int sample, int* diff); 30 virtual bool UpdateSample(base::ProcessId pid, int sample, int* diff);
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 // Handles asynchronous fetching of memory details and logging histograms about 41 // Handles asynchronous fetching of memory details and logging histograms about
42 // memory use of various processes. 42 // memory use of various processes.
43 // Will run the provided callback when finished. 43 // Will run the provided callback when finished.
44 class MetricsMemoryDetails : public MemoryDetails { 44 class MetricsMemoryDetails : public MemoryDetails {
45 public: 45 public:
46 MetricsMemoryDetails(const base::Closure& callback, 46 MetricsMemoryDetails(const base::Closure& callback,
47 MemoryGrowthTracker* memory_growth_tracker); 47 MemoryGrowthTracker* memory_growth_tracker);
48 48
49 void set_generate_histograms(bool generate_histograms) {
50 generate_histograms_ = generate_histograms;
51 }
52
49 protected: 53 protected:
50 ~MetricsMemoryDetails() override; 54 ~MetricsMemoryDetails() override;
51 55
52 // MemoryDetails: 56 // MemoryDetails:
53 void OnDetailsAvailable() override; 57 void OnDetailsAvailable() override;
54 58
55 private: 59 private:
56 // Updates the global histograms for tracking memory usage. 60 // Updates the global histograms for tracking memory usage.
57 void UpdateHistograms(); 61 void UpdateHistograms();
58 62
59 #if defined(OS_CHROMEOS) 63 #if defined(OS_CHROMEOS)
60 void UpdateSwapHistograms(); 64 void UpdateSwapHistograms();
61 #endif 65 #endif
62 66
67 // Notifies |memory_growth_tracker_| about the memory usage.
68 // Update histograms on memory growth or shrink in renderer processes.
69 void AnalyzeMemoryGrowth();
70
63 base::Closure callback_; 71 base::Closure callback_;
64 72
65 // A pointer to MemoryGrowthTracker which is contained in a longer-lived 73 // A pointer to MemoryGrowthTracker which is contained in a longer-lived
66 // owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient. 74 // owner of MetricsMemoryDetails, for example, ChromeMetricsServiceClient.
67 // If it is null, nothing is tracked. 75 // If it is null, nothing is tracked.
68 MemoryGrowthTracker* memory_growth_tracker_; 76 MemoryGrowthTracker* memory_growth_tracker_;
69 77
78 // A flag indicating if histogram data should be generated. True on default.
79 // If false, then only MemoryGrowthTracker gets notified about memory usage.
80 bool generate_histograms_;
81
70 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails); 82 DISALLOW_COPY_AND_ASSIGN(MetricsMemoryDetails);
71 }; 83 };
72 84
73 #endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_ 85 #endif // CHROME_BROWSER_METRICS_METRICS_MEMORY_DETAILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698