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

Side by Side Diff: chrome/browser/metrics/leak_detector/leak_detector_controller.h

Issue 2396743002: Leak reports collect information about the memory usage (Closed)
Patch Set: Refactoring after Simon's comments 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_
6 #define CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_ 6 #define CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h " 14 #include "chrome/browser/metrics/leak_detector/leak_detector_remote_controller.h "
15 #include "chrome/browser/metrics/metrics_memory_details.h"
15 #include "components/metrics/leak_detector/leak_detector.h" 16 #include "components/metrics/leak_detector/leak_detector.h"
16 #include "components/metrics/proto/memory_leak_report.pb.h" 17 #include "components/metrics/proto/memory_leak_report.pb.h"
17 18
18 namespace metrics { 19 namespace metrics {
19 20
20 // This class initializes the LeakDetector on the browser process and registers 21 // This class initializes the LeakDetector on the browser process and registers
21 // itself to be notified of leak reports. 22 // itself to be notified of leak reports.
22 class LeakDetectorController 23 class LeakDetectorController
23 : public LeakDetector::Observer, 24 : public LeakDetector::Observer,
24 public LeakDetectorRemoteController::LocalController { 25 public LeakDetectorRemoteController::LocalController {
25 public: 26 public:
26 LeakDetectorController(); 27 LeakDetectorController();
27 ~LeakDetectorController() override; 28 ~LeakDetectorController() override;
28 29
29 // Retrieves all reports in |stored_reports_|, moving them to |*reports|. 30 // Retrieves all reports in |stored_reports_|, moving them to |*reports|.
30 // |stored_reports_| is empty afterwards. 31 // |stored_reports_| is empty afterwards.
31 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports); 32 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports);
32 33
33 protected: 34 protected:
34 // LeakDetector::Observer: 35 // LeakDetector::Observer:
35 void OnLeaksFound(const std::vector<MemoryLeakReportProto>& reports) override; 36 void OnLeaksFound(const std::vector<MemoryLeakReportProto>& reports) override;
36 37
37 // LeakDetectorRemoteController::LocalController: 38 // LeakDetectorRemoteController::LocalController:
38 MemoryLeakReportProto::Params GetParamsAndRecordRequest() override; 39 MemoryLeakReportProto::Params GetParamsAndRecordRequest() override;
39 void SendLeakReports( 40 void SendLeakReports(
40 const std::vector<MemoryLeakReportProto>& reports) override; 41 const std::vector<MemoryLeakReportProto>& reports) override;
41 void OnRemoteProcessShutdown() override; 42 void OnRemoteProcessShutdown() override;
42 43
43 private: 44 private:
45 // Accumulates total memory usage info inside MetricsMemoryDetails.
46 class TotalMemoryGrowthTracker : public MemoryGrowthTracker {
47 public:
48 TotalMemoryGrowthTracker();
49 ~TotalMemoryGrowthTracker();
50
51 // Updates the inner counter by sample (in kb). Returns always false
52 // to suppress generating growth/shrink histograms in MetricsMemoryDetails.
53 bool UpdateSample(base::ProcessId pid, int sample, int* diff) override;
54
55 size_t total_usage_kb() const { return total_usage_kb_; }
56 void reset() { total_usage_kb_ = 0; }
57
58 private:
59 size_t total_usage_kb_;
60 };
61
44 // Returns true to indicate that LeakDetector should be enabled on a renderer 62 // Returns true to indicate that LeakDetector should be enabled on a renderer
45 // process. This is determined as follows: 63 // process. This is determined as follows:
46 // 1. If the number of processes running LeakDetector is not at max, returns 64 // 1. If the number of processes running LeakDetector is not at max, returns
47 // true with a probability of |per_process_enable_probability_|. 65 // true with a probability of |per_process_enable_probability_|.
48 // 2. If the number of processes running LeakDetector has reached the max, 66 // 2. If the number of processes running LeakDetector has reached the max,
49 // returns false. 67 // returns false.
50 bool ShouldRandomlyEnableLeakDetectorOnRendererProcess() const; 68 bool ShouldRandomlyEnableLeakDetectorOnRendererProcess() const;
51 69
52 // Stores a given array of leak reports in |stored_reports_|. |process_type| 70 // Stores a given array of leak reports in |stored_reports_|. |process_type|
53 // is the type of process that generated these reports. The reports must all 71 // is the type of process that generated these reports. The reports must all
54 // come from the same process type. 72 // come from the same process type.
55 void StoreLeakReports(const std::vector<MemoryLeakReportProto>& reports, 73 void StoreLeakReports(const std::vector<MemoryLeakReportProto>& reports,
56 MemoryLeakReportProto::ProcessType process_type); 74 MemoryLeakReportProto::ProcessType process_type);
57 75
76 // Method called from MetricsMemoryDetails when memory usage gets measured.
77 // Updates |memory_usage_info| in stored_reports_[i] for i >= |index|.
78 void OnMemoryDetailCollectionDone(size_t index);
79
58 // All leak reports received through OnLeakFound() are stored in protobuf 80 // All leak reports received through OnLeakFound() are stored in protobuf
59 // format. 81 // format.
60 std::vector<MemoryLeakReportProto> stored_reports_; 82 std::vector<MemoryLeakReportProto> stored_reports_;
61 83
62 // Contains all the parameters passed to LeakDetector. Store them in a single 84 // Contains all the parameters passed to LeakDetector. Store them in a single
63 // protobuf message instead of in separate member variables. 85 // protobuf message instead of in separate member variables.
64 const MemoryLeakReportProto::Params params_; 86 const MemoryLeakReportProto::Params params_;
65 87
66 // The build ID of the current Chrome binary. 88 // The build ID of the current Chrome binary.
67 std::vector<uint8_t> build_id_; 89 std::vector<uint8_t> build_id_;
(...skipping 10 matching lines...) Expand all
78 // simultaneously. 100 // simultaneously.
79 int max_renderer_processes_with_leak_detector_enabled_; 101 int max_renderer_processes_with_leak_detector_enabled_;
80 102
81 // The number of renderer processes on which the leak detector has been 103 // The number of renderer processes on which the leak detector has been
82 // enabled and is running. 104 // enabled and is running.
83 int num_renderer_processes_with_leak_detector_enabled_; 105 int num_renderer_processes_with_leak_detector_enabled_;
84 106
85 // For thread safety. 107 // For thread safety.
86 base::ThreadChecker thread_checker_; 108 base::ThreadChecker thread_checker_;
87 109
110 // An object passed to MetricsMemoryDetails for collecting memory usage.
111 TotalMemoryGrowthTracker total_memory_growth_tracker_;
112
113 // Indicates that collecting memory usage is running.
114 bool waiting_for_collect_memory_usage_;
115
116 // For passing |this| into a callback.
117 base::WeakPtrFactory<LeakDetectorController> weak_ptr_factory_;
118
88 DISALLOW_COPY_AND_ASSIGN(LeakDetectorController); 119 DISALLOW_COPY_AND_ASSIGN(LeakDetectorController);
89 }; 120 };
90 121
91 } // namespace metrics 122 } // namespace metrics
92 123
93 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_ 124 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698