Chromium Code Reviews| Index: chrome/browser/metrics/leak_detector_controller.cc |
| diff --git a/chrome/browser/metrics/leak_detector_controller.cc b/chrome/browser/metrics/leak_detector_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e9c639aa320c40c948f7cca590d72698c2960d4 |
| --- /dev/null |
| +++ b/chrome/browser/metrics/leak_detector_controller.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/metrics/leak_detector_controller.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/logging.h" |
| + |
| +namespace metrics { |
| + |
| +namespace { |
| + |
| +// Default parameters for LeakDetector. |
| +const float kSamplingRate = 1.0f / 256; |
| +const int kMaxStackDepth = 4; |
| +const uint64_t kAnalysisIntervalBytes = 32 * 1024 * 1024; |
| +const int kSizeSuspicionThreshold = 4; |
| +const int kCallStackSuspicionThreshold = 4; |
| + |
| +} // namespace |
| + |
| +LeakDetectorController::LeakDetectorController() |
| + : detector_(kSamplingRate, |
| + kMaxStackDepth, |
| + kAnalysisIntervalBytes, |
| + kSizeSuspicionThreshold, |
| + kCallStackSuspicionThreshold) { |
| + CHECK(detector_.AddObserver(this)); |
| +} |
| + |
| +LeakDetectorController::~LeakDetectorController() { |
| + CHECK(detector_.RemoveObserver(this)); |
| +} |
| + |
| +void LeakDetectorController::OnLeakFound( |
| + const LeakDetector::LeakReport& report) { |
| + 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.
|
| + MemoryLeakReportProto* proto = &stored_reports_.back(); |
| + |
| + // Copy the contents of the report to the protobuf. |
| + proto->set_size_bytes(report.alloc_size_bytes); |
| + proto->mutable_call_stack()->Reserve(report.call_stack.size()); |
| + for (uintptr_t call_stack_entry : report.call_stack) |
| + proto->mutable_call_stack()->Add(call_stack_entry); |
| + |
| + // Store the LeakDetector parameters in the protobuf. |
| + proto->set_sampling_rate(kSamplingRate); |
| + proto->set_max_stack_depth(kMaxStackDepth); |
| + proto->set_analysis_interval_bytes(kAnalysisIntervalBytes); |
| + proto->set_size_suspicion_threshold(kSizeSuspicionThreshold); |
| + proto->set_call_stack_suspicion_threshold(kCallStackSuspicionThreshold); |
| +} |
| + |
| +void LeakDetectorController::GetLeakReports( |
| + std::vector<MemoryLeakReportProto>* reports) { |
| + *reports = std::move(stored_reports_); |
| +} |
| + |
| +} // namespace metrics |