OLD | NEW |
(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/leak_detector_remote_controller.h
" |
| 6 |
| 7 #include "content/public/browser/browser_thread.h" |
| 8 |
| 9 namespace metrics { |
| 10 |
| 11 namespace { |
| 12 |
| 13 // All instances of LeakDetectorRemoteController will need to reference a single |
| 14 // LocalController instance, referenced by this pointer. All remote LeakDetector |
| 15 // clients will get their params from and send leak reports to this instance. |
| 16 LeakDetectorRemoteController::LocalController* g_local_controller = nullptr; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 LeakDetectorRemoteController::~LeakDetectorRemoteController() {} |
| 21 |
| 22 // static |
| 23 void LeakDetectorRemoteController::Create(mojom::LeakDetectorRequest request) { |
| 24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 25 new LeakDetectorRemoteController(std::move(request)); |
| 26 } |
| 27 |
| 28 void LeakDetectorRemoteController::GetParams( |
| 29 const mojom::LeakDetector::GetParamsCallback& callback) { |
| 30 // If no controller exists, send an empty param protobuf. The remote caller |
| 31 // should not initialize anything if the params are empty. |
| 32 MemoryLeakReportProto_Params params; |
| 33 if (g_local_controller) { |
| 34 params = g_local_controller->GetParams(); |
| 35 } |
| 36 |
| 37 mojo::StructPtr<mojom::LeakDetectorParams> mojo_params = |
| 38 mojom::LeakDetectorParams::New(); |
| 39 mojo_params->sampling_rate = params.sampling_rate(); |
| 40 mojo_params->max_stack_depth = params.max_stack_depth(); |
| 41 mojo_params->analysis_interval_bytes = params.analysis_interval_bytes(); |
| 42 mojo_params->size_suspicion_threshold = params.size_suspicion_threshold(); |
| 43 mojo_params->call_stack_suspicion_threshold = |
| 44 params.call_stack_suspicion_threshold(); |
| 45 |
| 46 callback.Run(std::move(mojo_params)); |
| 47 } |
| 48 |
| 49 void LeakDetectorRemoteController::SendLeakReports( |
| 50 mojo::Array<mojom::MemoryLeakReportPtr> reports) { |
| 51 std::vector<MemoryLeakReportProto> report_protos; |
| 52 report_protos.reserve(reports.size()); |
| 53 |
| 54 for (const mojom::MemoryLeakReportPtr& report : reports) { |
| 55 report_protos.push_back(MemoryLeakReportProto()); |
| 56 auto proto = report_protos.back(); |
| 57 |
| 58 proto.set_size_bytes(report->size_bytes); |
| 59 for (auto call_stack_addr : report->call_stack) |
| 60 proto.add_call_stack(call_stack_addr); |
| 61 |
| 62 for (const auto& history_entry : report->alloc_breakdown_history) { |
| 63 auto proto_entry = proto.add_alloc_breakdown_history(); |
| 64 for (auto count : history_entry->counts_by_size) { |
| 65 proto_entry->add_counts_by_size(count); |
| 66 } |
| 67 proto_entry->set_count_for_call_stack( |
| 68 history_entry->count_for_call_stack); |
| 69 } |
| 70 } |
| 71 DCHECK(g_local_controller); |
| 72 g_local_controller->SendLeakReports(report_protos); |
| 73 } |
| 74 |
| 75 LeakDetectorRemoteController::LeakDetectorRemoteController( |
| 76 mojom::LeakDetectorRequest request) |
| 77 : binding_(this, std::move(request)) {} |
| 78 |
| 79 // static |
| 80 void LeakDetectorRemoteController::SetLocalControllerInstance( |
| 81 LocalController* controller) { |
| 82 g_local_controller = controller; |
| 83 } |
| 84 |
| 85 } // namespace metrics |
OLD | NEW |