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

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

Issue 2062743002: Randomly enable leak detector based on probability parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RenderThreadObserver interface to shutdown remote client on same thread Created 4 years, 4 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>
(...skipping 17 matching lines...) Expand all
28 28
29 // Retrieves all reports in |stored_reports_|, moving them to |*reports|. 29 // Retrieves all reports in |stored_reports_|, moving them to |*reports|.
30 // |stored_reports_| is empty afterwards. 30 // |stored_reports_| is empty afterwards.
31 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports); 31 void GetLeakReports(std::vector<MemoryLeakReportProto>* reports);
32 32
33 protected: 33 protected:
34 // LeakDetector::Observer: 34 // LeakDetector::Observer:
35 void OnLeaksFound(const std::vector<MemoryLeakReportProto>& reports) override; 35 void OnLeaksFound(const std::vector<MemoryLeakReportProto>& reports) override;
36 36
37 // LeakDetectorRemoteController::LocalController: 37 // LeakDetectorRemoteController::LocalController:
38 MemoryLeakReportProto::Params GetParams() const override; 38 MemoryLeakReportProto::Params GetParamsAndRecordRequest() override;
39 void SendLeakReports( 39 void SendLeakReports(
40 const std::vector<MemoryLeakReportProto>& reports) override; 40 const std::vector<MemoryLeakReportProto>& reports) override;
41 void OnRemoteProcessShutdown() override; 41 void OnRemoteProcessShutdown() override;
42 42
43 private: 43 private:
44 // Returns true to indicate that LeakDetector should be enabled on a renderer
45 // process. This is determined as follows:
46 // 1. If the number of processes running LeakDetector is not at max, returns
47 // true with a probability of |per_process_enable_probability_|.
48 // 2. If the number of processes running LeakDetector has reached the max,
49 // returns false.
50 bool ShouldRandomlyEnableLeakDetectorOnRendererProcess() const;
51
44 // Stores a given array of leak reports in |stored_reports_|. |process_type| 52 // Stores a given array of leak reports in |stored_reports_|. |process_type|
45 // is the type of process that generated these reports. The reports must all 53 // is the type of process that generated these reports. The reports must all
46 // come from the same process type. 54 // come from the same process type.
47 void StoreLeakReports(const std::vector<MemoryLeakReportProto>& reports, 55 void StoreLeakReports(const std::vector<MemoryLeakReportProto>& reports,
48 MemoryLeakReportProto::ProcessType process_type); 56 MemoryLeakReportProto::ProcessType process_type);
49 57
50 // All leak reports received through OnLeakFound() are stored in protobuf 58 // All leak reports received through OnLeakFound() are stored in protobuf
51 // format. 59 // format.
52 std::vector<MemoryLeakReportProto> stored_reports_; 60 std::vector<MemoryLeakReportProto> stored_reports_;
53 61
54 // Contains all the parameters passed to LeakDetector. Store them in a single 62 // Contains all the parameters passed to LeakDetector. Store them in a single
55 // protobuf message instead of in separate member variables. 63 // protobuf message instead of in separate member variables.
56 const MemoryLeakReportProto::Params params_; 64 const MemoryLeakReportProto::Params params_;
57 65
58 // The build ID of the current Chrome binary. 66 // The build ID of the current Chrome binary.
59 std::vector<uint8_t> build_id_; 67 std::vector<uint8_t> build_id_;
60 68
69 // The probability that each process will have the leak detector enabled on
70 // it. For remote processes, this is determined by sending |params_| for
71 // initialization. If the remote process is not to have leak detector enabled,
72 // |params_.sampling_rate()| will be set to 0. Whether or not to enable for a
73 // particular process is independent of the decision for all other processes.
74 double browser_process_enable_probability_;
75 double renderer_process_enable_probability_;
76
77 // The maximum allowed number of renderer processes with leak detector running
78 // simultaneously.
79 int max_renderer_processes_with_leak_detector_enabled_;
80
81 // The number of renderer processes on which the leak detector has been
82 // enabled and is running.
83 int num_renderer_processes_with_leak_detector_enabled_;
84
61 // For thread safety. 85 // For thread safety.
62 base::ThreadChecker thread_checker_; 86 base::ThreadChecker thread_checker_;
63 87
64 DISALLOW_COPY_AND_ASSIGN(LeakDetectorController); 88 DISALLOW_COPY_AND_ASSIGN(LeakDetectorController);
65 }; 89 };
66 90
67 } // namespace metrics 91 } // namespace metrics
68 92
69 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_ 93 #endif // CHROME_BROWSER_METRICS_LEAK_DETECTOR_LEAK_DETECTOR_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698