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 #include "chrome/browser/metrics/leak_detector_controller.h" | 5 #include "chrome/browser/metrics/leak_detector_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 namespace metrics { | 11 namespace metrics { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Default parameters for LeakDetector. | 15 // Default parameters for LeakDetector. |
16 const float kSamplingRate = 1.0f / 256; | 16 const float kSamplingRate = 1.0f / 256; |
17 const int kMaxStackDepth = 4; | 17 const int kMaxStackDepth = 4; |
18 const uint64_t kAnalysisIntervalBytes = 32 * 1024 * 1024; | 18 const uint64_t kAnalysisIntervalBytes = 32 * 1024 * 1024; |
19 const int kSizeSuspicionThreshold = 4; | 19 const int kSizeSuspicionThreshold = 4; |
20 const int kCallStackSuspicionThreshold = 4; | 20 const int kCallStackSuspicionThreshold = 4; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 LeakDetectorController::LeakDetectorController() | 24 LeakDetectorController::LeakDetectorController() { |
25 : detector_(kSamplingRate, | 25 LeakDetector* detector = LeakDetector::GetInstance(); |
26 kMaxStackDepth, | 26 detector->AddObserver(this); |
27 kAnalysisIntervalBytes, | 27 detector->Init(kSamplingRate, kMaxStackDepth, kAnalysisIntervalBytes, |
28 kSizeSuspicionThreshold, | 28 kSizeSuspicionThreshold, kCallStackSuspicionThreshold); |
29 kCallStackSuspicionThreshold) { | |
30 detector_.AddObserver(this); | |
31 } | 29 } |
32 | 30 |
33 LeakDetectorController::~LeakDetectorController() { | 31 LeakDetectorController::~LeakDetectorController() { |
34 DCHECK(thread_checker_.CalledOnValidThread()); | 32 DCHECK(thread_checker_.CalledOnValidThread()); |
35 detector_.RemoveObserver(this); | 33 LeakDetector::GetInstance()->RemoveObserver(this); |
36 } | 34 } |
37 | 35 |
38 void LeakDetectorController::OnLeakFound( | 36 void LeakDetectorController::OnLeakFound( |
39 const LeakDetector::LeakReport& report) { | 37 const LeakDetector::LeakReport& report) { |
40 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
41 | 39 |
42 stored_reports_.push_back(MemoryLeakReportProto()); | 40 stored_reports_.push_back(MemoryLeakReportProto()); |
43 MemoryLeakReportProto* proto = &stored_reports_.back(); | 41 MemoryLeakReportProto* proto = &stored_reports_.back(); |
44 | 42 |
45 // Copy the contents of the report to the protobuf. | 43 // Copy the contents of the report to the protobuf. |
(...skipping 10 matching lines...) Expand all Loading... |
56 proto->set_call_stack_suspicion_threshold(kCallStackSuspicionThreshold); | 54 proto->set_call_stack_suspicion_threshold(kCallStackSuspicionThreshold); |
57 } | 55 } |
58 | 56 |
59 void LeakDetectorController::GetLeakReports( | 57 void LeakDetectorController::GetLeakReports( |
60 std::vector<MemoryLeakReportProto>* reports) { | 58 std::vector<MemoryLeakReportProto>* reports) { |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
62 *reports = std::move(stored_reports_); | 60 *reports = std::move(stored_reports_); |
63 } | 61 } |
64 | 62 |
65 } // namespace metrics | 63 } // namespace metrics |
OLD | NEW |