| 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 | |
| 5 | #include "base/profiler/stack_sampler.h" |
| 6 | |
| 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 | |
| 13 | namespace base { |
| 14 | |
| 15 | // static |
| 16 | std::unique_ptr<StackSampler> StackSampler::Create( |
| 17 | SamplingProfilerThreadToken thread_token, |
| 18 | ModuleCache* module_cache, |
| 19 | StackSamplerTestDelegate* test_delegate, |
| 20 | std::unique_ptr<Unwinder> native_unwinder) { |
| 21 | DCHECK(!native_unwinder); |
| 22 | #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM64) |
| 23 | return std::make_unique<StackSamplerImpl>( |
| 24 | std::make_unique<StackCopierSuspend>( |
| 25 | std::make_unique<SuspendableThreadDelegateWin>(thread_token)), |
| 26 | std::make_unique<NativeUnwinderWin>(), module_cache, test_delegate); |
| 27 | #else |
| 28 | return nullptr; |
| 29 | #endif |
| 30 | } |
| 31 | |
| 32 | // static |
| 33 | size_t StackSampler::GetStackBufferSize() { |
| 34 | // The default Win32 reserved stack size is 1 MB and Chrome Windows threads |
| 35 | // currently always use the default, but this allows for expansion if it |
| 36 | // occurs. The size beyond the actual stack size consists of unallocated |
| 37 | // virtual memory pages so carries little cost (just a bit of wasted address |
| 38 | // space). |
| 39 | return 2 << 20; // 2 MiB |
| 40 | } |
| 41 | |
| 42 | } // namespace base |
| 43 | |