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

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

Issue 2444143002: Add process lifetime annotations to stack samples. (Closed)
Patch Set: Created 4 years, 1 month 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
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 static int32_t current_activities(
94 const base::StackSamplingProfiler::Sample& sample) {
95 return sample.current_activities;
96 }
97
98 static bool Read(metrics::mojom::CallStackSampleDataView data,
99 base::StackSamplingProfiler::Sample* out) {
100 std::vector<base::StackSamplingProfiler::Frame> frames;
101 if (!data.ReadFrames(&frames))
102 return false;
103
104 *out = base::StackSamplingProfiler::Sample();
105 out->frames = std::move(frames);
106 out->process_phases = data.process_phases();
107 out->current_activities = data.current_activities();
108 return true;
109 }
110 };
111
112 template <>
83 struct StructTraits<metrics::mojom::CallStackProfileDataView, 113 struct StructTraits<metrics::mojom::CallStackProfileDataView,
84 base::StackSamplingProfiler::CallStackProfile> { 114 base::StackSamplingProfiler::CallStackProfile> {
85 static const std::vector<base::StackSamplingProfiler::Module>& modules( 115 static const std::vector<base::StackSamplingProfiler::Module>& modules(
86 const base::StackSamplingProfiler::CallStackProfile& profile) { 116 const base::StackSamplingProfiler::CallStackProfile& profile) {
87 return profile.modules; 117 return profile.modules;
88 } 118 }
89 static const std::vector<base::StackSamplingProfiler::Sample>& samples( 119 static const std::vector<base::StackSamplingProfiler::Sample>& samples(
90 const base::StackSamplingProfiler::CallStackProfile& profile) { 120 const base::StackSamplingProfiler::CallStackProfile& profile) {
91 return profile.samples; 121 return profile.samples;
92 } 122 }
93 static const base::TimeDelta profile_duration( 123 static const base::TimeDelta profile_duration(
94 const base::StackSamplingProfiler::CallStackProfile& profile) { 124 const base::StackSamplingProfiler::CallStackProfile& profile) {
95 return profile.profile_duration; 125 return profile.profile_duration;
96 } 126 }
97 static const base::TimeDelta sampling_period( 127 static const base::TimeDelta sampling_period(
98 const base::StackSamplingProfiler::CallStackProfile& profile) { 128 const base::StackSamplingProfiler::CallStackProfile& profile) {
99 return profile.sampling_period; 129 return profile.sampling_period;
100 } 130 }
101 131
102 static bool ValidateSamples( 132 static bool ValidateSamples(
103 std::vector<base::StackSamplingProfiler::Sample> samples, 133 std::vector<base::StackSamplingProfiler::Sample> samples,
104 size_t module_count) { 134 size_t module_count) {
105 for (const base::StackSamplingProfiler::Sample& sample : samples) { 135 for (const base::StackSamplingProfiler::Sample& sample : samples) {
106 for (const base::StackSamplingProfiler::Frame& frame : sample) { 136 for (const base::StackSamplingProfiler::Frame& frame : sample.frames) {
107 if (frame.module_index >= module_count && 137 if (frame.module_index >= module_count &&
108 frame.module_index != 138 frame.module_index !=
109 base::StackSamplingProfiler::Frame::kUnknownModuleIndex) 139 base::StackSamplingProfiler::Frame::kUnknownModuleIndex)
110 return false; 140 return false;
111 } 141 }
112 } 142 }
113 return true; 143 return true;
114 } 144 }
115 145
116 static bool Read(metrics::mojom::CallStackProfileDataView data, 146 static bool Read(metrics::mojom::CallStackProfileDataView data,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 metrics::CallStackProfileParams::SampleOrderingSpec::PRESERVE_ORDER; 405 metrics::CallStackProfileParams::SampleOrderingSpec::PRESERVE_ORDER;
376 return true; 406 return true;
377 } 407 }
378 return false; 408 return false;
379 } 409 }
380 }; 410 };
381 411
382 } // mojo 412 } // mojo
383 413
384 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_ 414 #endif // COMPONENTS_METRICS_CALL_STACK_PROFILE_STRUCT_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698