| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 Sample(const Sample& sample); | 114 Sample(const Sample& sample); |
| 115 ~Sample(); | 115 ~Sample(); |
| 116 | 116 |
| 117 // These constructors are used only during testing. | 117 // These constructors are used only during testing. |
| 118 Sample(const Frame& frame); | 118 Sample(const Frame& frame); |
| 119 Sample(const std::vector<Frame>& frames); | 119 Sample(const std::vector<Frame>& frames); |
| 120 | 120 |
| 121 // The entire stack frame when the sample is taken. | 121 // The entire stack frame when the sample is taken. |
| 122 std::vector<Frame> frames; | 122 std::vector<Frame> frames; |
| 123 | 123 |
| 124 // A bit-field indicating which process phases have passed. This can be | 124 // A bit-field indicating which process milestones have passed. This can be |
| 125 // used to tell where in the process lifetime the samples are taken. Just | 125 // used to tell where in the process lifetime the samples are taken. Just |
| 126 // as a "lifetime" can only move forward, these bits mark the phases of | 126 // as a "lifetime" can only move forward, these bits mark the milestones of |
| 127 // the processes life as they occur. Bits can be set but never reset. The | 127 // the processes life as they occur. Bits can be set but never reset. The |
| 128 // actual definition of the individual bits is left to the user of this | 128 // actual definition of the individual bits is left to the user of this |
| 129 // module. | 129 // module. |
| 130 uint32_t process_phases = 0; | 130 uint32_t process_milestones = 0; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 // CallStackProfile represents a set of samples. | 133 // CallStackProfile represents a set of samples. |
| 134 struct BASE_EXPORT CallStackProfile { | 134 struct BASE_EXPORT CallStackProfile { |
| 135 CallStackProfile(); | 135 CallStackProfile(); |
| 136 CallStackProfile(CallStackProfile&& other); | 136 CallStackProfile(CallStackProfile&& other); |
| 137 ~CallStackProfile(); | 137 ~CallStackProfile(); |
| 138 | 138 |
| 139 CallStackProfile& operator=(CallStackProfile&& other); | 139 CallStackProfile& operator=(CallStackProfile&& other); |
| 140 | 140 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // Stops the profiler and any ongoing sampling. Calling this function is | 218 // Stops the profiler and any ongoing sampling. Calling this function is |
| 219 // optional; if not invoked profiling terminates when all the profiling bursts | 219 // optional; if not invoked profiling terminates when all the profiling bursts |
| 220 // specified in the SamplingParams are completed or the profiler is destroyed, | 220 // specified in the SamplingParams are completed or the profiler is destroyed, |
| 221 // whichever occurs first. | 221 // whichever occurs first. |
| 222 void Stop(); | 222 void Stop(); |
| 223 | 223 |
| 224 // Set the current system state that is recorded with each captured stack | 224 // Set the current system state that is recorded with each captured stack |
| 225 // frame. This is thread-safe so can be called from anywhere. The parameter | 225 // frame. This is thread-safe so can be called from anywhere. The parameter |
| 226 // value should be from an enumeration of the appropriate type with values | 226 // value should be from an enumeration of the appropriate type with values |
| 227 // ranging from 0 to 31, inclusive. This sets bits within Sample field of | 227 // ranging from 0 to 31, inclusive. This sets bits within Sample field of |
| 228 // |process_phases|. The actual meanings of these bits are defined (globally) | 228 // |process_milestones|. The actual meanings of these bits are defined |
| 229 // by the caller(s). | 229 // (globally) by the caller(s). |
| 230 static void SetProcessPhase(int phase); | 230 static void SetProcessMilestone(int milestone); |
| 231 static void ResetAnnotationsForTesting(); | 231 static void ResetAnnotationsForTesting(); |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 // SamplingThread is a separate thread used to suspend and sample stacks from | 234 // SamplingThread is a separate thread used to suspend and sample stacks from |
| 235 // the target thread. | 235 // the target thread. |
| 236 class SamplingThread : public PlatformThread::Delegate { | 236 class SamplingThread : public PlatformThread::Delegate { |
| 237 public: | 237 public: |
| 238 // Samples stacks using |native_sampler|. When complete, invokes | 238 // Samples stacks using |native_sampler|. When complete, invokes |
| 239 // |completed_callback| with the collected call stack profiles. | 239 // |completed_callback| with the collected call stack profiles. |
| 240 // |completed_callback| must be callable on any thread. | 240 // |completed_callback| must be callable on any thread. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 // Adds annotations to a Sample. | 275 // Adds annotations to a Sample. |
| 276 static void RecordAnnotations(Sample* sample); | 276 static void RecordAnnotations(Sample* sample); |
| 277 | 277 |
| 278 // This global variables holds the current system state and is recorded with | 278 // This global variables holds the current system state and is recorded with |
| 279 // every captured sample, done on a separate thread which is why updates to | 279 // every captured sample, done on a separate thread which is why updates to |
| 280 // this must be atomic. A PostTask to move the the updates to that thread | 280 // this must be atomic. A PostTask to move the the updates to that thread |
| 281 // would skew the timing and a lock could result in deadlock if the thread | 281 // would skew the timing and a lock could result in deadlock if the thread |
| 282 // making a change was also being profiled and got stopped. | 282 // making a change was also being profiled and got stopped. |
| 283 static subtle::Atomic32 process_phases_; | 283 static subtle::Atomic32 process_milestones_; |
| 284 | 284 |
| 285 // The thread whose stack will be sampled. | 285 // The thread whose stack will be sampled. |
| 286 PlatformThreadId thread_id_; | 286 PlatformThreadId thread_id_; |
| 287 | 287 |
| 288 const SamplingParams params_; | 288 const SamplingParams params_; |
| 289 | 289 |
| 290 std::unique_ptr<SamplingThread> sampling_thread_; | 290 std::unique_ptr<SamplingThread> sampling_thread_; |
| 291 PlatformThreadHandle sampling_thread_handle_; | 291 PlatformThreadHandle sampling_thread_handle_; |
| 292 | 292 |
| 293 const CompletedCallback completed_callback_; | 293 const CompletedCallback completed_callback_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 309 BASE_EXPORT bool operator<(const StackSamplingProfiler::Sample& a, | 309 BASE_EXPORT bool operator<(const StackSamplingProfiler::Sample& a, |
| 310 const StackSamplingProfiler::Sample& b); | 310 const StackSamplingProfiler::Sample& b); |
| 311 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, | 311 BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, |
| 312 const StackSamplingProfiler::Frame& b); | 312 const StackSamplingProfiler::Frame& b); |
| 313 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, | 313 BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, |
| 314 const StackSamplingProfiler::Frame& b); | 314 const StackSamplingProfiler::Frame& b); |
| 315 | 315 |
| 316 } // namespace base | 316 } // namespace base |
| 317 | 317 |
| 318 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ | 318 #endif // BASE_PROFILER_STACK_SAMPLING_PROFILER_H_ |
| OLD | NEW |