OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/metrics/leak_detector_controller.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/logging.h" | |
10 | |
11 namespace metrics { | |
12 | |
13 namespace { | |
14 | |
15 // Default parameters for LeakDetector. | |
16 const float kSamplingRate = 1.0f / 256; | |
17 const int kMaxStackDepth = 4; | |
18 const uint64_t kAnalysisIntervalBytes = 32 * 1024 * 1024; | |
19 const int kSizeSuspicionThreshold = 4; | |
20 const int kCallStackSuspicionThreshold = 4; | |
21 | |
22 } // namespace | |
23 | |
24 LeakDetectorController::LeakDetectorController() | |
25 : detector_(kSamplingRate, | |
26 kMaxStackDepth, | |
27 kAnalysisIntervalBytes, | |
28 kSizeSuspicionThreshold, | |
29 kCallStackSuspicionThreshold) { | |
30 CHECK(detector_.AddObserver(this)); | |
31 } | |
32 | |
33 LeakDetectorController::~LeakDetectorController() { | |
34 CHECK(detector_.RemoveObserver(this)); | |
35 } | |
36 | |
37 void LeakDetectorController::OnLeakFound( | |
38 const LeakDetector::LeakReport& report) { | |
39 stored_reports_.resize(stored_reports_.size() + 1); | |
Alexei Svitkine (slow)
2016/02/10 20:16:58
I think this pattern results in bad growth (i.e. p
Simon Que
2016/02/11 01:45:37
Done.
| |
40 MemoryLeakReportProto* proto = &stored_reports_.back(); | |
41 | |
42 // Copy the contents of the report to the protobuf. | |
43 proto->set_size_bytes(report.alloc_size_bytes); | |
44 proto->mutable_call_stack()->Reserve(report.call_stack.size()); | |
45 for (uintptr_t call_stack_entry : report.call_stack) | |
46 proto->mutable_call_stack()->Add(call_stack_entry); | |
47 | |
48 // Store the LeakDetector parameters in the protobuf. | |
49 proto->set_sampling_rate(kSamplingRate); | |
50 proto->set_max_stack_depth(kMaxStackDepth); | |
51 proto->set_analysis_interval_bytes(kAnalysisIntervalBytes); | |
52 proto->set_size_suspicion_threshold(kSizeSuspicionThreshold); | |
53 proto->set_call_stack_suspicion_threshold(kCallStackSuspicionThreshold); | |
54 } | |
55 | |
56 void LeakDetectorController::GetLeakReports( | |
57 std::vector<MemoryLeakReportProto>* reports) { | |
58 *reports = std::move(stored_reports_); | |
59 } | |
60 | |
61 } // namespace metrics | |
OLD | NEW |