Chromium Code Reviews| Index: base/profiler/stack_sampling_profiler.h |
| diff --git a/base/profiler/stack_sampling_profiler.h b/base/profiler/stack_sampling_profiler.h |
| index bf5a4f337219f76b782189fde2c5aa2f9646c640..fbdb893efa6f160e209c1aa332b586d769e50478 100644 |
| --- a/base/profiler/stack_sampling_profiler.h |
| +++ b/base/profiler/stack_sampling_profiler.h |
| @@ -11,6 +11,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/atomicops.h" |
| #include "base/base_export.h" |
| #include "base/callback.h" |
| #include "base/files/file_path.h" |
| @@ -64,6 +65,15 @@ class NativeStackSamplerTestDelegate; |
| // record those modules associated with the recorded stack frames. |
| class BASE_EXPORT StackSamplingProfiler { |
| public: |
| + enum ProcessPhase { |
| + // TODO: Expand this. |
| + FirstNonEmptyPaint, |
| + }; |
| + |
| + enum ProcessActivity { |
| + // TODO: Expand this, too. |
| + }; |
| + |
| // Module represents the module (DLL or exe) corresponding to a stack frame. |
| struct BASE_EXPORT Module { |
| Module(); |
| @@ -107,8 +117,28 @@ class BASE_EXPORT StackSamplingProfiler { |
| size_t module_index; |
| }; |
| - // Sample represents a set of stack frames. |
| - using Sample = std::vector<Frame>; |
| + // Sample represents a set of stack frames with some extra information. |
| + struct BASE_EXPORT Sample { |
| + Sample(); |
| + Sample(const Sample& sample); |
| + ~Sample(); |
| + |
| + // These constructors are used only during testing. |
| + Sample(const Frame& frame); |
| + Sample(const std::vector<Frame>& frames); |
| + |
| + // The entire stack frame when the sample is taken. |
| + std::vector<Frame> frames; |
| + |
| + // A bit-field indicating which process phases have passed. This can be |
| + // used to tell where in the process lifetime the samples are taken. See |
| + // ProcessPhase, above. |
| + uint32_t process_phases = 0; |
| + |
| + // A bit-field indicating activities which were active when the frame was |
| + // captured. See ProcessActivity, above. |
| + uint32_t current_activities = 0; |
| + }; |
| // CallStackProfile represents a set of samples. |
| struct BASE_EXPORT CallStackProfile { |
| @@ -161,6 +191,11 @@ class BASE_EXPORT StackSamplingProfiler { |
| // thread-safe callback implementation. |
| using CompletedCallback = Callback<void(const CallStackProfiles&)>; |
| + // The callback type used to add annotations to a sample during collection. |
| + // This is passed to the native sampler to be applied at the most appropriate |
| + // time. |
| + using AnnotateCallback = Callback<void(Sample*)>; |
|
Mike Wittman
2016/10/26 16:28:17
I think this type would be better on NativeStackSa
|
| + |
| // Creates a profiler that sends completed profiles to |callback|. The second |
| // constructor is for test purposes. |
| StackSamplingProfiler(PlatformThreadId thread_id, |
| @@ -189,6 +224,12 @@ class BASE_EXPORT StackSamplingProfiler { |
| // whichever occurs first. |
| void Stop(); |
| + // Set the current system state that is recorded with each captured stack |
| + // frame. These are all thread-safe so can be called from anywhere. |
| + static void SetProcessPhase(ProcessPhase phase); |
| + static void RecordActivityBegin(ProcessActivity activity); |
| + static void RecordActivityEnd(ProcessActivity activity); |
| + |
| private: |
| // SamplingThread is a separate thread used to suspend and sample stacks from |
| // the target thread. |
| @@ -231,6 +272,17 @@ class BASE_EXPORT StackSamplingProfiler { |
| DISALLOW_COPY_AND_ASSIGN(SamplingThread); |
| }; |
| + // Adds "phases" and "activities" annotations to a Sample. |
| + static void RecordAnnotations(Sample* sample); |
| + |
| + // These global variables hold current system state. These values are |
| + // recorded with every captured sample, done on a separate thread which is |
| + // why updates to these must be atomic. A PostTask to move the the updates |
| + // to that thread would skew the timing and a lock could result in deadlock |
| + // if the thread making a change was also being profiled and got stopped. |
| + static subtle::Atomic32 process_phases_; |
| + static subtle::Atomic32 current_activities_; |
| + |
| // The thread whose stack will be sampled. |
| PlatformThreadId thread_id_; |
| @@ -251,6 +303,12 @@ class BASE_EXPORT StackSamplingProfiler { |
| // done in tests and by the metrics provider code. |
| BASE_EXPORT bool operator==(const StackSamplingProfiler::Module& a, |
| const StackSamplingProfiler::Module& b); |
| +BASE_EXPORT bool operator==(const StackSamplingProfiler::Sample& a, |
| + const StackSamplingProfiler::Sample& b); |
| +BASE_EXPORT bool operator!=(const StackSamplingProfiler::Sample& a, |
| + const StackSamplingProfiler::Sample& b); |
| +BASE_EXPORT bool operator<(const StackSamplingProfiler::Sample& a, |
| + const StackSamplingProfiler::Sample& b); |
| BASE_EXPORT bool operator==(const StackSamplingProfiler::Frame& a, |
| const StackSamplingProfiler::Frame& b); |
| BASE_EXPORT bool operator<(const StackSamplingProfiler::Frame& a, |