stack_sampler_impl.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/callback.h"
  9. #include "base/containers/circular_deque.h"
  10. #include "base/profiler/frame.h"
  11. #include "base/profiler/register_context.h"
  12. #include "base/profiler/stack_copier.h"
  13. #include "base/profiler/stack_sampler.h"
  14. namespace base {
  15. class Unwinder;
  16. // Cross-platform stack sampler implementation. Delegates to StackCopier for the
  17. // platform-specific stack copying implementation.
  18. class BASE_EXPORT StackSamplerImpl : public StackSampler {
  19. public:
  20. StackSamplerImpl(std::unique_ptr<StackCopier> stack_copier,
  21. UnwindersFactory core_unwinders_factory,
  22. ModuleCache* module_cache,
  23. RepeatingClosure record_sample_callback = RepeatingClosure(),
  24. StackSamplerTestDelegate* test_delegate = nullptr);
  25. ~StackSamplerImpl() override;
  26. StackSamplerImpl(const StackSamplerImpl&) = delete;
  27. StackSamplerImpl& operator=(const StackSamplerImpl&) = delete;
  28. // StackSampler:
  29. void Initialize() override;
  30. void AddAuxUnwinder(std::unique_ptr<Unwinder> unwinder) override;
  31. void RecordStackFrames(StackBuffer* stack_buffer,
  32. ProfileBuilder* profile_builder) override;
  33. // Exposes the internal function for unit testing.
  34. static std::vector<Frame> WalkStackForTesting(
  35. ModuleCache* module_cache,
  36. RegisterContext* thread_context,
  37. uintptr_t stack_top,
  38. const base::circular_deque<std::unique_ptr<Unwinder>>& unwinders);
  39. private:
  40. static std::vector<Frame> WalkStack(
  41. ModuleCache* module_cache,
  42. RegisterContext* thread_context,
  43. uintptr_t stack_top,
  44. const base::circular_deque<std::unique_ptr<Unwinder>>& unwinders);
  45. const std::unique_ptr<StackCopier> stack_copier_;
  46. UnwindersFactory unwinders_factory_;
  47. // Unwinders are stored in decreasing priority order.
  48. base::circular_deque<std::unique_ptr<Unwinder>> unwinders_;
  49. ModuleCache* const module_cache_;
  50. const RepeatingClosure record_sample_callback_;
  51. StackSamplerTestDelegate* const test_delegate_;
  52. };
  53. } // namespace base
  54. #endif // BASE_PROFILER_STACK_SAMPLER_IMPL_H_