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

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: Make LeakDetector thread-safe 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) {
39 DCHECK(thread_checker_.CalledOnValidThread());
Will Harris 2016/02/20 08:54:05 rest of these methods need thread_checker_ to be c
Simon Que 2016/02/22 23:26:18 Done. But not ctor?
40
41 stored_reports_.push_back(MemoryLeakReportProto());
42 MemoryLeakReportProto* proto = &stored_reports_.back();
43
44 // Copy the contents of the report to the protobuf.
45 proto->set_size_bytes(report.alloc_size_bytes);
46 proto->mutable_call_stack()->Reserve(report.call_stack.size());
47 for (uintptr_t call_stack_entry : report.call_stack)
48 proto->mutable_call_stack()->Add(call_stack_entry);
49
50 // Store the LeakDetector parameters in the protobuf.
51 proto->set_sampling_rate(kSamplingRate);
52 proto->set_max_stack_depth(kMaxStackDepth);
53 proto->set_analysis_interval_bytes(kAnalysisIntervalBytes);
54 proto->set_size_suspicion_threshold(kSizeSuspicionThreshold);
55 proto->set_call_stack_suspicion_threshold(kCallStackSuspicionThreshold);
56 }
57
58 void LeakDetectorController::GetLeakReports(
59 std::vector<MemoryLeakReportProto>* reports) {
60 *reports = std::move(stored_reports_);
61 }
62
63 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698