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

Side by Side Diff: base/profiler/stack_sampling_profiler.h

Issue 2438073002: Use movable types for CallStackProfile(s) to remove copying of data. (Closed)
Patch Set: added some comments about std::move 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
« no previous file with comments | « no previous file | base/profiler/stack_sampling_profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ 5 #ifndef BASE_PROFILER_STACK_SAMPLING_PROFILER_H_
6 #define BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ 6 #define BASE_PROFILER_STACK_SAMPLING_PROFILER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // module state directly here to save space. 106 // module state directly here to save space.
107 size_t module_index; 107 size_t module_index;
108 }; 108 };
109 109
110 // Sample represents a set of stack frames. 110 // Sample represents a set of stack frames.
111 using Sample = std::vector<Frame>; 111 using Sample = std::vector<Frame>;
112 112
113 // CallStackProfile represents a set of samples. 113 // CallStackProfile represents a set of samples.
114 struct BASE_EXPORT CallStackProfile { 114 struct BASE_EXPORT CallStackProfile {
115 CallStackProfile(); 115 CallStackProfile();
116 CallStackProfile(const CallStackProfile& other); 116 CallStackProfile(CallStackProfile&& other);
117 ~CallStackProfile(); 117 ~CallStackProfile();
118 118
119 CallStackProfile& operator=(CallStackProfile&& other);
120
121 CallStackProfile CopyForTesting() const;
122
119 std::vector<Module> modules; 123 std::vector<Module> modules;
120 std::vector<Sample> samples; 124 std::vector<Sample> samples;
121 125
122 // Duration of this profile. 126 // Duration of this profile.
123 TimeDelta profile_duration; 127 TimeDelta profile_duration;
124 128
125 // Time between samples. 129 // Time between samples.
126 TimeDelta sampling_period; 130 TimeDelta sampling_period;
131
132 private:
133 // Copying is possible but expensive so disallow it except for internal use
134 // (i.e. CopyForTesting); use std::move instead.
135 CallStackProfile(const CallStackProfile& other);
136
137 DISALLOW_ASSIGN(CallStackProfile);
127 }; 138 };
128 139
129 using CallStackProfiles = std::vector<CallStackProfile>; 140 using CallStackProfiles = std::vector<CallStackProfile>;
130 141
131 // Represents parameters that configure the sampling. 142 // Represents parameters that configure the sampling.
132 struct BASE_EXPORT SamplingParams { 143 struct BASE_EXPORT SamplingParams {
133 SamplingParams(); 144 SamplingParams();
134 145
135 // Time to delay before first samples are taken. Defaults to 0. 146 // Time to delay before first samples are taken. Defaults to 0.
136 TimeDelta initial_delay; 147 TimeDelta initial_delay;
137 148
138 // Number of sampling bursts to perform. Defaults to 1. 149 // Number of sampling bursts to perform. Defaults to 1.
139 int bursts; 150 int bursts;
140 151
141 // Interval between sampling bursts. This is the desired duration from the 152 // Interval between sampling bursts. This is the desired duration from the
142 // start of one burst to the start of the next burst. Defaults to 10s. 153 // start of one burst to the start of the next burst. Defaults to 10s.
143 TimeDelta burst_interval; 154 TimeDelta burst_interval;
144 155
145 // Number of samples to record per burst. Defaults to 300. 156 // Number of samples to record per burst. Defaults to 300.
146 int samples_per_burst; 157 int samples_per_burst;
147 158
148 // Interval between samples during a sampling burst. This is the desired 159 // Interval between samples during a sampling burst. This is the desired
149 // duration from the start of one sample to the start of the next 160 // duration from the start of one sample to the start of the next
150 // sample. Defaults to 100ms. 161 // sample. Defaults to 100ms.
151 TimeDelta sampling_interval; 162 TimeDelta sampling_interval;
152 }; 163 };
153 164
154 // The callback type used to collect completed profiles. 165 // The callback type used to collect completed profiles. The passed |profiles|
166 // are move-only.
155 // 167 //
156 // IMPORTANT NOTE: the callback is invoked on a thread the profiler 168 // IMPORTANT NOTE: the callback is invoked on a thread the profiler
157 // constructs, rather than on the thread used to construct the profiler and 169 // constructs, rather than on the thread used to construct the profiler and
158 // set the callback, and thus the callback must be callable on any thread. For 170 // set the callback, and thus the callback must be callable on any thread. For
159 // threads with message loops that create StackSamplingProfilers, posting a 171 // threads with message loops that create StackSamplingProfilers, posting a
160 // task to the message loop with a copy of the profiles is the recommended 172 // task to the message loop with a copy of the profiles is the recommended
161 // thread-safe callback implementation. 173 // thread-safe callback implementation.
162 using CompletedCallback = Callback<void(const CallStackProfiles&)>; 174 using CompletedCallback = Callback<void(CallStackProfiles)>;
163 175
164 // Creates a profiler that sends completed profiles to |callback|. The second 176 // Creates a profiler that sends completed profiles to |callback|. The second
165 // constructor is for test purposes. 177 // constructor is for test purposes.
166 StackSamplingProfiler(PlatformThreadId thread_id, 178 StackSamplingProfiler(PlatformThreadId thread_id,
167 const SamplingParams& params, 179 const SamplingParams& params,
168 const CompletedCallback& callback); 180 const CompletedCallback& callback);
169 StackSamplingProfiler(PlatformThreadId thread_id, 181 StackSamplingProfiler(PlatformThreadId thread_id,
170 const SamplingParams& params, 182 const SamplingParams& params,
171 const CompletedCallback& callback, 183 const CompletedCallback& callback,
172 NativeStackSamplerTestDelegate* test_delegate); 184 NativeStackSamplerTestDelegate* test_delegate);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, 264 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a,
253 const StackSamplingProfiler::Module& b); 265 const StackSamplingProfiler::Module& b);
254 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, 266 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a,
255 const StackSamplingProfiler::Frame& b); 267 const StackSamplingProfiler::Frame& b);
256 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, 268 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a,
257 const StackSamplingProfiler::Frame& b); 269 const StackSamplingProfiler::Frame& b);
258 270
259 } // namespace base 271 } // namespace base
260 272
261 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ 273 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_
OLDNEW
« no previous file with comments | « no previous file | base/profiler/stack_sampling_profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698