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

Unified Diff: chrome/browser/metrics/leak_detector_controller.cc

Issue 1681263003: metrics: Add leak detector controller in Chrome OS metrics system (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new files Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698