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

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: fix tests and build problems 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 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; use std::move instead.
Mike Wittman 2016/10/21 18:05:29 nit: ... disallow it _from outside the class_ ...
bcwhite 2016/10/24 13:17:45 Done.
134 CallStackProfile(const CallStackProfile& other);
Mike Wittman 2016/10/21 18:05:29 should we have DISALLOW_ASSIGN here?
bcwhite 2016/10/24 13:17:45 Done, though I don't think it's necessary because
127 }; 135 };
128 136
129 using CallStackProfiles = std::vector<CallStackProfile>; 137 using CallStackProfiles = std::vector<CallStackProfile>;
130 138
131 // Represents parameters that configure the sampling. 139 // Represents parameters that configure the sampling.
132 struct BASE_EXPORT SamplingParams { 140 struct BASE_EXPORT SamplingParams {
133 SamplingParams(); 141 SamplingParams();
134 142
135 // Time to delay before first samples are taken. Defaults to 0. 143 // Time to delay before first samples are taken. Defaults to 0.
136 TimeDelta initial_delay; 144 TimeDelta initial_delay;
137 145
138 // Number of sampling bursts to perform. Defaults to 1. 146 // Number of sampling bursts to perform. Defaults to 1.
139 int bursts; 147 int bursts;
140 148
141 // Interval between sampling bursts. This is the desired duration from the 149 // 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. 150 // start of one burst to the start of the next burst. Defaults to 10s.
143 TimeDelta burst_interval; 151 TimeDelta burst_interval;
144 152
145 // Number of samples to record per burst. Defaults to 300. 153 // Number of samples to record per burst. Defaults to 300.
146 int samples_per_burst; 154 int samples_per_burst;
147 155
148 // Interval between samples during a sampling burst. This is the desired 156 // 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 157 // duration from the start of one sample to the start of the next
150 // sample. Defaults to 100ms. 158 // sample. Defaults to 100ms.
151 TimeDelta sampling_interval; 159 TimeDelta sampling_interval;
152 }; 160 };
153 161
154 // The callback type used to collect completed profiles. 162 // The callback type used to collect completed profiles. The passed |profiles|
163 // are move-only.
155 // 164 //
156 // IMPORTANT NOTE: the callback is invoked on a thread the profiler 165 // IMPORTANT NOTE: the callback is invoked on a thread the profiler
157 // constructs, rather than on the thread used to construct the profiler and 166 // 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 167 // set the callback, and thus the callback must be callable on any thread. For
159 // threads with message loops that create StackSamplingProfilers, posting a 168 // threads with message loops that create StackSamplingProfilers, posting a
160 // task to the message loop with a copy of the profiles is the recommended 169 // task to the message loop with a copy of the profiles is the recommended
161 // thread-safe callback implementation. 170 // thread-safe callback implementation.
162 using CompletedCallback = Callback<void(const CallStackProfiles&)>; 171 using CompletedCallback = Callback<void(CallStackProfiles)>;
163 172
164 // Creates a profiler that sends completed profiles to |callback|. The second 173 // Creates a profiler that sends completed profiles to |callback|. The second
165 // constructor is for test purposes. 174 // constructor is for test purposes.
166 StackSamplingProfiler(PlatformThreadId thread_id, 175 StackSamplingProfiler(PlatformThreadId thread_id,
167 const SamplingParams& params, 176 const SamplingParams& params,
168 const CompletedCallback& callback); 177 const CompletedCallback& callback);
169 StackSamplingProfiler(PlatformThreadId thread_id, 178 StackSamplingProfiler(PlatformThreadId thread_id,
170 const SamplingParams& params, 179 const SamplingParams& params,
171 const CompletedCallback& callback, 180 const CompletedCallback& callback,
172 NativeStackSamplerTestDelegate* test_delegate); 181 NativeStackSamplerTestDelegate* test_delegate);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, 261 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a,
253 const StackSamplingProfiler::Module& b); 262 const StackSamplingProfiler::Module& b);
254 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, 263 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a,
255 const StackSamplingProfiler::Frame& b); 264 const StackSamplingProfiler::Frame& b);
256 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, 265 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a,
257 const StackSamplingProfiler::Frame& b); 266 const StackSamplingProfiler::Frame& b);
258 267
259 } // namespace base 268 } // namespace base
260 269
261 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ 270 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_
OLDNEW
« no previous file with comments | « no previous file | base/profiler/stack_sampling_profiler.cc » ('j') | base/profiler/stack_sampling_profiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698