Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 DISALLOW_ASSIGN(CallStackProfile); | |
|
Alexei Svitkine (slow)
2016/10/24 15:26:21
Nit: Add an empty line above this.
bcwhite
2016/10/24 21:30:30
Done.
| |
| 127 }; | 137 }; |
| 128 | 138 |
| 129 using CallStackProfiles = std::vector<CallStackProfile>; | 139 using CallStackProfiles = std::vector<CallStackProfile>; |
| 130 | 140 |
| 131 // Represents parameters that configure the sampling. | 141 // Represents parameters that configure the sampling. |
| 132 struct BASE_EXPORT SamplingParams { | 142 struct BASE_EXPORT SamplingParams { |
| 133 SamplingParams(); | 143 SamplingParams(); |
| 134 | 144 |
| 135 // Time to delay before first samples are taken. Defaults to 0. | 145 // Time to delay before first samples are taken. Defaults to 0. |
| 136 TimeDelta initial_delay; | 146 TimeDelta initial_delay; |
| 137 | 147 |
| 138 // Number of sampling bursts to perform. Defaults to 1. | 148 // Number of sampling bursts to perform. Defaults to 1. |
| 139 int bursts; | 149 int bursts; |
| 140 | 150 |
| 141 // Interval between sampling bursts. This is the desired duration from the | 151 // 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. | 152 // start of one burst to the start of the next burst. Defaults to 10s. |
| 143 TimeDelta burst_interval; | 153 TimeDelta burst_interval; |
| 144 | 154 |
| 145 // Number of samples to record per burst. Defaults to 300. | 155 // Number of samples to record per burst. Defaults to 300. |
| 146 int samples_per_burst; | 156 int samples_per_burst; |
| 147 | 157 |
| 148 // Interval between samples during a sampling burst. This is the desired | 158 // 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 | 159 // duration from the start of one sample to the start of the next |
| 150 // sample. Defaults to 100ms. | 160 // sample. Defaults to 100ms. |
| 151 TimeDelta sampling_interval; | 161 TimeDelta sampling_interval; |
| 152 }; | 162 }; |
| 153 | 163 |
| 154 // The callback type used to collect completed profiles. | 164 // The callback type used to collect completed profiles. The passed |profiles| |
| 165 // are move-only. | |
| 155 // | 166 // |
| 156 // IMPORTANT NOTE: the callback is invoked on a thread the profiler | 167 // IMPORTANT NOTE: the callback is invoked on a thread the profiler |
| 157 // constructs, rather than on the thread used to construct the profiler and | 168 // 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 | 169 // set the callback, and thus the callback must be callable on any thread. For |
| 159 // threads with message loops that create StackSamplingProfilers, posting a | 170 // threads with message loops that create StackSamplingProfilers, posting a |
| 160 // task to the message loop with a copy of the profiles is the recommended | 171 // task to the message loop with a copy of the profiles is the recommended |
| 161 // thread-safe callback implementation. | 172 // thread-safe callback implementation. |
| 162 using CompletedCallback = Callback<void(const CallStackProfiles&)>; | 173 using CompletedCallback = Callback<void(CallStackProfiles)>; |
| 163 | 174 |
| 164 // Creates a profiler that sends completed profiles to |callback|. The second | 175 // Creates a profiler that sends completed profiles to |callback|. The second |
| 165 // constructor is for test purposes. | 176 // constructor is for test purposes. |
| 166 StackSamplingProfiler(PlatformThreadId thread_id, | 177 StackSamplingProfiler(PlatformThreadId thread_id, |
| 167 const SamplingParams& params, | 178 const SamplingParams& params, |
| 168 const CompletedCallback& callback); | 179 const CompletedCallback& callback); |
| 169 StackSamplingProfiler(PlatformThreadId thread_id, | 180 StackSamplingProfiler(PlatformThreadId thread_id, |
| 170 const SamplingParams& params, | 181 const SamplingParams& params, |
| 171 const CompletedCallback& callback, | 182 const CompletedCallback& callback, |
| 172 NativeStackSamplerTestDelegate* test_delegate); | 183 NativeStackSamplerTestDelegate* test_delegate); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, | 263 BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, |
| 253 const StackSamplingProfiler::Module& b); | 264 const StackSamplingProfiler::Module& b); |
| 254 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, | 265 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, |
| 255 const StackSamplingProfiler::Frame& b); | 266 const StackSamplingProfiler::Frame& b); |
| 256 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, | 267 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, |
| 257 const StackSamplingProfiler::Frame& b); | 268 const StackSamplingProfiler::Frame& b); |
| 258 | 269 |
| 259 } // namespace base | 270 } // namespace base |
| 260 | 271 |
| 261 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ | 272 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
| OLD | NEW |