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

Side by Side Diff: components/metrics/leak_detector/protobuf_to_mojo_converter.cc

Issue 2064463002: Mojo interface/service for Leak Detector on remote process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update ProtobufToMojoConverterTest Created 4 years, 5 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 "components/metrics/leak_detector/protobuf_to_mojo_converter.h"
6
7 namespace metrics {
8 namespace leak_detector {
9 namespace protobuf_to_mojo_converter {
10
11 void ParamsToMojo(const MemoryLeakReportProto::Params& params,
12 mojom::LeakDetectorParams* mojo_params) {
13 mojo_params->sampling_rate = params.sampling_rate();
14 mojo_params->max_stack_depth = params.max_stack_depth();
15 mojo_params->analysis_interval_bytes = params.analysis_interval_bytes();
16 mojo_params->size_suspicion_threshold = params.size_suspicion_threshold();
17 mojo_params->call_stack_suspicion_threshold =
18 params.call_stack_suspicion_threshold();
19 }
20
21 void MojoToParams(const mojom::LeakDetectorParams& mojo_params,
22 MemoryLeakReportProto::Params* params) {
23 params->set_sampling_rate(mojo_params.sampling_rate);
24 params->set_max_stack_depth(mojo_params.max_stack_depth);
25 params->set_analysis_interval_bytes(mojo_params.analysis_interval_bytes);
26 params->set_size_suspicion_threshold(mojo_params.size_suspicion_threshold);
27 params->set_call_stack_suspicion_threshold(
28 mojo_params.call_stack_suspicion_threshold);
29 }
30
31 void ReportToMojo(const MemoryLeakReportProto& report,
32 mojom::MemoryLeakReport* mojo_report) {
33 mojo_report->size_bytes = report.size_bytes();
34 for (auto call_stack_value : report.call_stack()) {
35 mojo_report->call_stack.push_back(call_stack_value);
36 }
37
38 for (const auto& history_entry : report.alloc_breakdown_history()) {
39 metrics::mojom::AllocationBreakdownPtr mojo_entry =
40 metrics::mojom::AllocationBreakdown::New();
41 for (auto count : history_entry.counts_by_size()) {
42 mojo_entry->counts_by_size.push_back(count);
43 }
44 mojo_entry->count_for_call_stack = history_entry.count_for_call_stack();
45
46 mojo_report->alloc_breakdown_history.push_back(std::move(mojo_entry));
47 }
48 }
49
50 void MojoToReport(const mojom::MemoryLeakReport& mojo_report,
51 MemoryLeakReportProto* report) {
52 report->set_size_bytes(mojo_report.size_bytes);
53 for (auto call_stack_addr : mojo_report.call_stack)
54 report->add_call_stack(call_stack_addr);
55
56 for (const auto& history_entry : mojo_report.alloc_breakdown_history) {
57 auto proto_entry = report->add_alloc_breakdown_history();
58 for (auto count : history_entry->counts_by_size) {
59 proto_entry->add_counts_by_size(count);
60 }
61 proto_entry->set_count_for_call_stack(history_entry->count_for_call_stack);
62 }
63 }
64
65 } // namespace protobuf_to_mojo_converter
66 } // namespace leak_detector
67 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698