stack_sampler_impl.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_PROFILER_STACK_SAMPLER_IMPL_H_
  5. #define BASE_PROFILER_STACK_SAMPLER_IMPL_H_
  6. #include <memory>
  7. #include "base/base_export.h"
  8. #include "base/containers/circular_deque.h"
  9. #include "base/profiler/frame.h"
  10. #include "base/profiler/register_context.h"
  11. #include "base/profiler/stack_copier.h"
  12. #include "base/profiler/stack_sampler.h"
  13. namespace base {
  14. class Unwinder;
  15. // Cross-platform stack sampler implementation. Delegates to StackCopier for the
  16. // platform-specific stack copying implementation.
  17. class BASE_EXPORT StackSamplerImpl : public StackSampler {
  18. public:
  19. StackSamplerImpl(std::unique_ptr<StackCopier> stack_copier,
  20. std::vector<std::unique_ptr<Unwinder>> core_unwinders,
  21. ModuleCache* module_cache,
  22. StackSamplerTestDelegate* test_delegate = nullptr);
  23. ~StackSamplerImpl() override;
  24. StackSamplerImpl(const StackSamplerImpl&) = delete;
  25. StackSamplerImpl& operator=(const StackSamplerImpl&) = delete;
  26. // StackSampler:
  27. void AddAuxUnwinder(std::unique_ptr<Unwinder> unwinder) override;
  28. void RecordStackFrames(StackBuffer* stack_buffer,
  29. ProfileBuilder* profile_builder) override;
  30. // Exposes the internal function for unit testing.
  31. static std::vector<Frame> WalkStackForTesting(
  32. ModuleCache* module_cache,
  33. RegisterContext* thread_context,
  34. uintptr_t stack_top,
  35. const base::circular_deque<std::unique_ptr<Unwinder>>& unwinders);
  36. private:
  37. static std::vector<Frame> WalkStack(
  38. ModuleCache* module_cache,
  39. RegisterContext* thread_context,
  40. uintptr_t stack_top,
  41. const base::circular_deque<std::unique_ptr<Unwinder>>& unwinders);
  42. const std::unique_ptr<StackCopier> stack_copier_;
  43. // Store all unwinder in decreasing priority order.
  44. base::circular_deque<std::unique_ptr<Unwinder>> unwinders_;
  45. ModuleCache* const module_cache_;
  46. StackSamplerTestDelegate* const test_delegate_;
  47. };
  48. } // namespace base
  49. #endif // BASE_PROFILER_STACK_SAMPLER_IMPL_H_