| OLD | NEW |
| 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 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::CallStackSampleDataView, |
| 84 base::StackSamplingProfiler::Sample> { |
| 85 static const std::vector<base::StackSamplingProfiler::Frame>& frames( |
| 86 const base::StackSamplingProfiler::Sample& sample) { |
| 87 return sample.frames; |
| 88 } |
| 89 static int32_t process_phases( |
| 90 const base::StackSamplingProfiler::Sample& sample) { |
| 91 return sample.process_phases; |
| 92 } |
| 93 |
| 94 static bool Read(metrics::mojom::CallStackSampleDataView data, |
| 95 base::StackSamplingProfiler::Sample* out) { |
| 96 std::vector<base::StackSamplingProfiler::Frame> frames; |
| 97 if (!data.ReadFrames(&frames)) |
| 98 return false; |
| 99 |
| 100 *out = base::StackSamplingProfiler::Sample(); |
| 101 out->frames = std::move(frames); |
| 102 out->process_phases = data.process_phases(); |
| 103 return true; |
| 104 } |
| 105 }; |
| 106 |
| 107 template <> |
| 83 struct StructTraits<metrics::mojom::CallStackProfileDataView, | 108 struct StructTraits<metrics::mojom::CallStackProfileDataView, |
| 84 base::StackSamplingProfiler::CallStackProfile> { | 109 base::StackSamplingProfiler::CallStackProfile> { |
| 85 static const std::vector<base::StackSamplingProfiler::Module>& modules( | 110 static const std::vector<base::StackSamplingProfiler::Module>& modules( |
| 86 const base::StackSamplingProfiler::CallStackProfile& profile) { | 111 const base::StackSamplingProfiler::CallStackProfile& profile) { |
| 87 return profile.modules; | 112 return profile.modules; |
| 88 } | 113 } |
| 89 static const std::vector<base::StackSamplingProfiler::Sample>& samples( | 114 static const std::vector<base::StackSamplingProfiler::Sample>& samples( |
| 90 const base::StackSamplingProfiler::CallStackProfile& profile) { | 115 const base::StackSamplingProfiler::CallStackProfile& profile) { |
| 91 return profile.samples; | 116 return profile.samples; |
| 92 } | 117 } |
| 93 static const base::TimeDelta profile_duration( | 118 static const base::TimeDelta profile_duration( |
| 94 const base::StackSamplingProfiler::CallStackProfile& profile) { | 119 const base::StackSamplingProfiler::CallStackProfile& profile) { |
| 95 return profile.profile_duration; | 120 return profile.profile_duration; |
| 96 } | 121 } |
| 97 static const base::TimeDelta sampling_period( | 122 static const base::TimeDelta sampling_period( |
| 98 const base::StackSamplingProfiler::CallStackProfile& profile) { | 123 const base::StackSamplingProfiler::CallStackProfile& profile) { |
| 99 return profile.sampling_period; | 124 return profile.sampling_period; |
| 100 } | 125 } |
| 101 | 126 |
| 102 static bool ValidateSamples( | 127 static bool ValidateSamples( |
| 103 std::vector<base::StackSamplingProfiler::Sample> samples, | 128 std::vector<base::StackSamplingProfiler::Sample> samples, |
| 104 size_t module_count) { | 129 size_t module_count) { |
| 105 for (const base::StackSamplingProfiler::Sample& sample : samples) { | 130 for (const base::StackSamplingProfiler::Sample& sample : samples) { |
| 106 for (const base::StackSamplingProfiler::Frame& frame : sample) { | 131 for (const base::StackSamplingProfiler::Frame& frame : sample.frames) { |
| 107 if (frame.module_index >= module_count && | 132 if (frame.module_index >= module_count && |
| 108 frame.module_index != | 133 frame.module_index != |
| 109 base::StackSamplingProfiler::Frame::kUnknownModuleIndex) | 134 base::StackSamplingProfiler::Frame::kUnknownModuleIndex) |
| 110 return false; | 135 return false; |
| 111 } | 136 } |
| 112 } | 137 } |
| 113 return true; | 138 return true; |
| 114 } | 139 } |
| 115 | 140 |
| 116 static bool Read(metrics::mojom::CallStackProfileDataView data, | 141 static bool Read(metrics::mojom::CallStackProfileDataView data, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 metrics::CallStackProfileParams::SampleOrderingSpec::PRESERVE_ORDER; | 389 metrics::CallStackProfileParams::SampleOrderingSpec::PRESERVE_ORDER; |
| 365 return true; | 390 return true; |
| 366 } | 391 } |
| 367 return false; | 392 return false; |
| 368 } | 393 } |
| 369 }; | 394 }; |
| 370 | 395 |
| 371 } // mojo | 396 } // mojo |
| 372 | 397 |
| 373 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_ | 398 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_ |
| OLD | NEW |