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

Side by Side Diff: components/metrics/public/cpp/call_stack_profile_struct_traits.h

Issue 2253293002: Mojo C++ bindings: change the first template parameter of StructTraits and UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@91_extra
Patch Set: rebase Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Defines StructTraits specializations for translating between mojo types and 5 // Defines StructTraits specializations for translating between mojo types and
6 // base::StackSamplingProfiler types, with data validity checks. 6 // base::StackSamplingProfiler types, with data validity checks.
7 7
8 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_ 8 #ifndef COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_
9 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_ 9 #define COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/profiler/stack_sampling_profiler.h" 14 #include "base/profiler/stack_sampling_profiler.h"
15 #include "components/metrics/public/interfaces/call_stack_profile_collector.mojo m.h" 15 #include "components/metrics/public/interfaces/call_stack_profile_collector.mojo m.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 18
19 template <> 19 template <>
20 struct StructTraits<metrics::mojom::CallStackModule, 20 struct StructTraits<metrics::mojom::CallStackModuleDataView,
21 base::StackSamplingProfiler::Module> { 21 base::StackSamplingProfiler::Module> {
22 static uint64_t base_address( 22 static uint64_t base_address(
23 const base::StackSamplingProfiler::Module& module) { 23 const base::StackSamplingProfiler::Module& module) {
24 return module.base_address; 24 return module.base_address;
25 } 25 }
26 static const std::string& id( 26 static const std::string& id(
27 const base::StackSamplingProfiler::Module& module) { 27 const base::StackSamplingProfiler::Module& module) {
28 return module.id; 28 return module.id;
29 } 29 }
30 static const base::FilePath& filename( 30 static const base::FilePath& filename(
(...skipping 12 matching lines...) Expand all
43 !data.ReadFilename(&filename)) 43 !data.ReadFilename(&filename))
44 return false; 44 return false;
45 45
46 *out = 46 *out =
47 base::StackSamplingProfiler::Module(data.base_address(), id, filename); 47 base::StackSamplingProfiler::Module(data.base_address(), id, filename);
48 return true; 48 return true;
49 } 49 }
50 }; 50 };
51 51
52 template <> 52 template <>
53 struct StructTraits<metrics::mojom::CallStackFrame, 53 struct StructTraits<metrics::mojom::CallStackFrameDataView,
54 base::StackSamplingProfiler::Frame> { 54 base::StackSamplingProfiler::Frame> {
55 static uint64_t instruction_pointer( 55 static uint64_t instruction_pointer(
56 const base::StackSamplingProfiler::Frame& frame) { 56 const base::StackSamplingProfiler::Frame& frame) {
57 return frame.instruction_pointer; 57 return frame.instruction_pointer;
58 } 58 }
59 static uint64_t module_index( 59 static uint64_t module_index(
60 const base::StackSamplingProfiler::Frame& frame) { 60 const base::StackSamplingProfiler::Frame& frame) {
61 return frame.module_index == 61 return frame.module_index ==
62 base::StackSamplingProfiler::Frame::kUnknownModuleIndex ? 62 base::StackSamplingProfiler::Frame::kUnknownModuleIndex ?
63 static_cast<uint64_t>(-1) : 63 static_cast<uint64_t>(-1) :
64 frame.module_index; 64 frame.module_index;
65 } 65 }
66 66
67 static bool Read(metrics::mojom::CallStackFrameDataView data, 67 static bool Read(metrics::mojom::CallStackFrameDataView data,
68 base::StackSamplingProfiler::Frame* out) { 68 base::StackSamplingProfiler::Frame* out) {
69 size_t module_index = data.module_index() == static_cast<uint64_t>(-1) ? 69 size_t module_index = data.module_index() == static_cast<uint64_t>(-1) ?
70 base::StackSamplingProfiler::Frame::kUnknownModuleIndex : 70 base::StackSamplingProfiler::Frame::kUnknownModuleIndex :
71 data.module_index(); 71 data.module_index();
72 72
73 // We can't know whether the module_index field is valid at this point since 73 // We can't know whether the module_index field is valid at this point since
74 // we don't have access to the number of modules here. This will be checked 74 // we don't have access to the number of modules here. This will be checked
75 // in CallStackProfile's Read function below. 75 // in CallStackProfile's Read function below.
76 *out = base::StackSamplingProfiler::Frame(data.instruction_pointer(), 76 *out = base::StackSamplingProfiler::Frame(data.instruction_pointer(),
77 module_index); 77 module_index);
78 return true; 78 return true;
79 } 79 }
80 }; 80 };
81 81
82 template <> 82 template <>
83 struct StructTraits<metrics::mojom::CallStackProfile, 83 struct StructTraits<metrics::mojom::CallStackProfileDataView,
84 base::StackSamplingProfiler::CallStackProfile> { 84 base::StackSamplingProfiler::CallStackProfile> {
85 static const std::vector<base::StackSamplingProfiler::Module>& modules( 85 static const std::vector<base::StackSamplingProfiler::Module>& modules(
86 const base::StackSamplingProfiler::CallStackProfile& profile) { 86 const base::StackSamplingProfiler::CallStackProfile& profile) {
87 return profile.modules; 87 return profile.modules;
88 } 88 }
89 static const std::vector<base::StackSamplingProfiler::Sample>& samples( 89 static const std::vector<base::StackSamplingProfiler::Sample>& samples(
90 const base::StackSamplingProfiler::CallStackProfile& profile) { 90 const base::StackSamplingProfiler::CallStackProfile& profile) {
91 return profile.samples; 91 return profile.samples;
92 } 92 }
93 static const base::TimeDelta profile_duration( 93 static const base::TimeDelta profile_duration(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 out->samples = std::move(samples); 129 out->samples = std::move(samples);
130 out->profile_duration = profile_duration; 130 out->profile_duration = profile_duration;
131 out->sampling_period = sampling_period; 131 out->sampling_period = sampling_period;
132 return true; 132 return true;
133 } 133 }
134 }; 134 };
135 135
136 } // mojo 136 } // mojo
137 137
138 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_ 138 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698