stack_sampler_mac.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2017 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. #include "base/profiler/stack_sampler.h"
  5. #include <memory>
  6. #include "base/bind.h"
  7. #include "base/check.h"
  8. #include "base/profiler/frame_pointer_unwinder.h"
  9. #include "base/profiler/stack_copier_suspend.h"
  10. #include "base/profiler/stack_sampler_impl.h"
  11. #include "base/profiler/suspendable_thread_delegate_mac.h"
  12. #include "base/profiler/unwinder.h"
  13. namespace base {
  14. namespace {
  15. std::vector<std::unique_ptr<Unwinder>> CreateUnwinders() {
  16. std::vector<std::unique_ptr<Unwinder>> unwinders;
  17. unwinders.push_back(std::make_unique<FramePointerUnwinder>());
  18. return unwinders;
  19. }
  20. } // namespace
  21. // static
  22. std::unique_ptr<StackSampler> StackSampler::Create(
  23. SamplingProfilerThreadToken thread_token,
  24. ModuleCache* module_cache,
  25. UnwindersFactory core_unwinders_factory,
  26. RepeatingClosure record_sample_callback,
  27. StackSamplerTestDelegate* test_delegate) {
  28. DCHECK(!core_unwinders_factory);
  29. return std::make_unique<StackSamplerImpl>(
  30. std::make_unique<StackCopierSuspend>(
  31. std::make_unique<SuspendableThreadDelegateMac>(thread_token)),
  32. BindOnce(&CreateUnwinders), module_cache,
  33. std::move(record_sample_callback), test_delegate);
  34. }
  35. // static
  36. size_t StackSampler::GetStackBufferSize() {
  37. size_t stack_size = PlatformThread::GetDefaultThreadStackSize();
  38. // If getrlimit somehow fails, return the default macOS main thread stack size
  39. // of 8 MB (DFLSSIZ in <i386/vmparam.h>) with extra wiggle room.
  40. return stack_size > 0 ? stack_size : 12 * 1024 * 1024;
  41. }
  42. } // namespace base