| Index: base/profiler/stack_sampling_profiler.h
|
| diff --git a/base/profiler/stack_sampling_profiler.h b/base/profiler/stack_sampling_profiler.h
|
| index cf1daf7e16d4b1846fa1b20a3c79f0f2578ce100..83e974767327b908dbfea7ec73bc893c00b99a36 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"
|
| @@ -107,8 +108,27 @@ 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. Just
|
| + // as a "lifetime" can only move forward, these bits mark the phases of
|
| + // the processes life as they occur. Bits can be set but never reset. The
|
| + // actual definition of the individual bits is left to the user of this
|
| + // module.
|
| + uint32_t process_phases = 0;
|
| + };
|
|
|
| // CallStackProfile represents a set of samples.
|
| struct BASE_EXPORT CallStackProfile {
|
| @@ -201,6 +221,15 @@ class BASE_EXPORT StackSamplingProfiler {
|
| // whichever occurs first.
|
| void Stop();
|
|
|
| + // Set the current system state that is recorded with each captured stack
|
| + // frame. This is thread-safe so can be called from anywhere. The parameter
|
| + // value should be from an enumeration of the appropriate type with values
|
| + // ranging from 0 to 31, inclusive. This sets bits within Sample field of
|
| + // |process_phases|. The actual meanings of these bits are defined (globally)
|
| + // by the caller(s).
|
| + static void SetProcessPhase(int phase);
|
| + static void ResetAnnotationsForTesting();
|
| +
|
| private:
|
| // SamplingThread is a separate thread used to suspend and sample stacks from
|
| // the target thread.
|
| @@ -243,6 +272,16 @@ class BASE_EXPORT StackSamplingProfiler {
|
| DISALLOW_COPY_AND_ASSIGN(SamplingThread);
|
| };
|
|
|
| + // Adds annotations to a Sample.
|
| + static void RecordAnnotations(Sample* sample);
|
| +
|
| + // This global variables holds the current system state and is recorded with
|
| + // every captured sample, done on a separate thread which is why updates to
|
| + // this 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_;
|
| +
|
| // The thread whose stack will be sampled.
|
| PlatformThreadId thread_id_;
|
|
|
| @@ -263,6 +302,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,
|
|
|