stack_sampler_win.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2015 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 "base/bind.h"
  6. #include "base/check.h"
  7. #include "base/profiler/native_unwinder_win.h"
  8. #include "base/profiler/stack_copier_suspend.h"
  9. #include "base/profiler/stack_sampler_impl.h"
  10. #include "base/profiler/suspendable_thread_delegate_win.h"
  11. #include "build/build_config.h"
  12. namespace base {
  13. // static
  14. std::unique_ptr<StackSampler> StackSampler::Create(
  15. SamplingProfilerThreadToken thread_token,
  16. ModuleCache* module_cache,
  17. UnwindersFactory core_unwinders_factory,
  18. RepeatingClosure record_sample_callback,
  19. StackSamplerTestDelegate* test_delegate) {
  20. DCHECK(!core_unwinders_factory);
  21. #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM64)
  22. const auto create_unwinders = []() {
  23. std::vector<std::unique_ptr<Unwinder>> unwinders;
  24. unwinders.push_back(std::make_unique<NativeUnwinderWin>());
  25. return unwinders;
  26. };
  27. return std::make_unique<StackSamplerImpl>(
  28. std::make_unique<StackCopierSuspend>(
  29. std::make_unique<SuspendableThreadDelegateWin>(thread_token)),
  30. BindOnce(create_unwinders), module_cache,
  31. std::move(record_sample_callback), test_delegate);
  32. #else
  33. return nullptr;
  34. #endif
  35. }
  36. // static
  37. size_t StackSampler::GetStackBufferSize() {
  38. // The default Win32 reserved stack size is 1 MB and Chrome Windows threads
  39. // currently always use the default, but this allows for expansion if it
  40. // occurs. The size beyond the actual stack size consists of unallocated
  41. // virtual memory pages so carries little cost (just a bit of wasted address
  42. // space).
  43. return 2 << 20; // 2 MiB
  44. }
  45. } // namespace base