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

Side by Side 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: Properly implement gn build 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 unified diff | Download patch
OLDNEW
(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 detector_.AddObserver(this);
31 }
32
33 LeakDetectorController::~LeakDetectorController() {
34 detector_.RemoveObserver(this);
35 }
36
37 void LeakDetectorController::OnLeakFound(
38 const LeakDetector::LeakReport& report) {
Will Harris 2016/02/18 04:49:45 which threads are OnLeakFound and GetLeakReports b
Simon Que 2016/02/18 05:16:04 OnLeakFound could be called from any thread but Ge
39 stored_reports_.push_back(MemoryLeakReportProto());
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
OLDNEW
« no previous file with comments | « chrome/browser/metrics/leak_detector_controller.h ('k') | chrome/browser/metrics/leak_detector_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698