| 6 | #define BASE_PROFILER_STACK_SAMPLER_IMPL_H_ |
| 7 |
| 8 | #include <memory> |
| 9 |
| 10 | #include "base/base_export.h" |
| 11 | #include "base/profiler/frame.h" |
| 12 | #include "base/profiler/register_context.h" |
| 13 | #include "base/profiler/stack_copier.h" |
| 14 | #include "base/profiler/stack_sampler.h" |
| 15 |
| 16 | namespace base { |
| 17 |
| 18 | class Unwinder; |
| 19 |
| 20 | // Cross-platform stack sampler implementation. Delegates to StackCopier for the |
| 21 | // platform-specific stack copying implementation. |
| 22 | class BASE_EXPORT StackSamplerImpl : public StackSampler { |
| 23 | public: |
| 24 | StackSamplerImpl(std::unique_ptr<StackCopier> stack_copier, |
| 25 | std::unique_ptr<Unwinder> native_unwinder, |
| 26 | ModuleCache* module_cache, |
| 27 | StackSamplerTestDelegate* test_delegate = nullptr); |
| 28 | ~StackSamplerImpl() override; |
| 29 |
| 30 | StackSamplerImpl(const StackSamplerImpl&) = delete; |
| 31 | StackSamplerImpl& operator=(const StackSamplerImpl&) = delete; |
| 32 |
| 33 | // StackSampler: |
| 34 | void AddAuxUnwinder(std::unique_ptr<Unwinder> unwinder) override; |
| 35 | void RecordStackFrames(StackBuffer* stack_buffer, |
| 36 | ProfileBuilder* profile_builder) override; |
| 37 |
| 38 | // Exposes the internal function for unit testing. |
| 39 | static std::vector<Frame> WalkStackForTesting(ModuleCache* module_cache, |
| 40 | RegisterContext* thread_context, |
| 41 | uintptr_t stack_top, |
| 42 | Unwinder* native_unwinder, |
| 43 | Unwinder* aux_unwinder); |
| 44 |
| 45 | private: |
| 46 | static std::vector<Frame> WalkStack(ModuleCache* module_cache, |
| 47 | RegisterContext* thread_context, |
| 48 | uintptr_t stack_top, |
| 49 | Unwinder* native_unwinder, |
| 50 | Unwinder* aux_unwinder); |
| 51 |
| 52 | const std::unique_ptr<StackCopier> stack_copier_; |
| 53 | const std::unique_ptr<Unwinder> native_unwinder_; |
| 54 | std::unique_ptr<Unwinder> aux_unwinder_; |
| 55 | ModuleCache* const module_cache_; |
| 56 | StackSamplerTestDelegate* const test_delegate_; |
| 57 | }; |
| 58 |
| 59 | } // namespace base |
| 60 |
| 61 | #endif // BASE_PROFILER_STACK_SAMPLER_IMPL_H_ |
| 62 |