Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 21 // Accumulates total memory usage info inside MetricsMemoryDetails. | |
| 22 class TotalMemoryGrowthTracker : public MemoryGrowthTracker { | |
|
Simon Que
2016/10/05 22:12:43
Make this a private class within LeakDetectorContr
mwlodar
2016/10/06 00:07:53
Done.
| |
| 23 public: | |
| 24 TotalMemoryGrowthTracker(); | |
| 25 ~TotalMemoryGrowthTracker(); | |
| 26 | |
| 27 // Updates the inner counter by sample (in kb). Returns always false | |
| 28 // to suppress generating growth/shrink histograms in MetricsMemoryDetails. | |
| 29 bool UpdateSample(base::ProcessId pid, int sample, int* diff) override; | |
| 30 | |
| 31 size_t GetTotalUsageKb() const; | |
| 32 void Reset(); | |
| 33 | |
| 34 private: | |
| 35 size_t total_usage_kb_; | |
| 36 }; | |
| 37 | |
| 20 // This class initializes the LeakDetector on the browser process and registers | 38 // This class initializes the LeakDetector on the browser process and registers |
| 21 // itself to be notified of leak reports. | 39 // itself to be notified of leak reports. |
| 22 class LeakDetectorController | 40 class LeakDetectorController |
| 23 : public LeakDetector::Observer, | 41 : public LeakDetector::Observer, |
| 24 public LeakDetectorRemoteController::LocalController { | 42 public LeakDetectorRemoteController::LocalController { |
| 25 public: | 43 public: |
| 26 LeakDetectorController(); | 44 LeakDetectorController(); |
| 27 ~LeakDetectorController() override; | 45 ~LeakDetectorController() override; |
| 28 | 46 |
| 29 // Retrieves all reports in |stored_reports_|, moving them to |*reports|. | 47 // Retrieves all reports in |stored_reports_|, moving them to |*reports|. |
| 30 // |stored_reports_| is empty afterwards. | 48 // |stored_reports_| is empty afterwards. |
| 31 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports); | 49 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports); |
| 32 | 50 |
| 51 // Method called from MetricsMemoryDetails when memory usage gets measured. | |
| 52 // Updates |memory_usage_info| in stored_reports_[i] for i >= |index|. | |
| 53 void OnMemoryDetailCollectionDone(size_t index); | |
|
Simon Que
2016/10/05 22:12:43
I think this can be made private.
mwlodar
2016/10/06 00:07:53
Done.
| |
| 54 | |
| 33 protected: | 55 protected: |
| 34 // LeakDetector::Observer: | 56 // LeakDetector::Observer: |
| 35 void OnLeaksFound(const std::vector<MemoryLeakReportProto>& reports) override; | 57 void OnLeaksFound(const std::vector<MemoryLeakReportProto>& reports) override; |
| 36 | 58 |
| 37 // LeakDetectorRemoteController::LocalController: | 59 // LeakDetectorRemoteController::LocalController: |
| 38 MemoryLeakReportProto::Params GetParamsAndRecordRequest() override; | 60 MemoryLeakReportProto::Params GetParamsAndRecordRequest() override; |
| 39 void SendLeakReports( | 61 void SendLeakReports( |
| 40 const std::vector<MemoryLeakReportProto>& reports) override; | 62 const std::vector<MemoryLeakReportProto>& reports) override; |
| 41 void OnRemoteProcessShutdown() override; | 63 void OnRemoteProcessShutdown() override; |
| 42 | 64 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_ |
| OLD | NEW |