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

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: Add content/public/browser to GN deps Created 4 years, 9 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 DCHECK(thread_checker_.CalledOnValidThread());
35 detector_.RemoveObserver(this);
36 }
37
38 void LeakDetectorController::OnLeakFound(
39 const LeakDetector::LeakReport& report) {
40 DCHECK(thread_checker_.CalledOnValidThread());
41
42 stored_reports_.push_back(MemoryLeakReportProto());
43 MemoryLeakReportProto* proto = &stored_reports_.back();
44
45 // Copy the contents of the report to the protobuf.
46 proto->set_size_bytes(report.alloc_size_bytes);
47 proto->mutable_call_stack()->Reserve(report.call_stack.size());
48 for (uintptr_t call_stack_entry : report.call_stack)
49 proto->mutable_call_stack()->Add(call_stack_entry);
50
51 // Store the LeakDetector parameters in the protobuf.
52 proto->set_sampling_rate(kSamplingRate);
53 proto->set_max_stack_depth(kMaxStackDepth);
54 proto->set_analysis_interval_bytes(kAnalysisIntervalBytes);
55 proto->set_size_suspicion_threshold(kSizeSuspicionThreshold);
56 proto->set_call_stack_suspicion_threshold(kCallStackSuspicionThreshold);
57 }
58
59 void LeakDetectorController::GetLeakReports(
60 std::vector<MemoryLeakReportProto>* reports) {
61 DCHECK(thread_checker_.CalledOnValidThread());
62 *reports = std::move(stored_reports_);
63 }
64
65 } // 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