OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/profiler/native_stack_sampler.h" | 5 #include "base/profiler/native_stack_sampler.h" |
6 | 6 |
7 #include <objbase.h> | 7 #include <objbase.h> |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <winternl.h> | 10 #include <winternl.h> |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 NativeStackSamplerTestDelegate* test_delegate); | 391 NativeStackSamplerTestDelegate* test_delegate); |
392 ~NativeStackSamplerWin() override; | 392 ~NativeStackSamplerWin() override; |
393 | 393 |
394 // StackSamplingProfiler::NativeStackSampler: | 394 // StackSamplingProfiler::NativeStackSampler: |
395 void ProfileRecordingStarting( | 395 void ProfileRecordingStarting( |
396 std::vector<StackSamplingProfiler::Module>* modules) override; | 396 std::vector<StackSamplingProfiler::Module>* modules) override; |
397 void RecordStackSample(StackSamplingProfiler::Sample* sample) override; | 397 void RecordStackSample(StackSamplingProfiler::Sample* sample) override; |
398 void ProfileRecordingStopped() override; | 398 void ProfileRecordingStopped() override; |
399 | 399 |
400 private: | 400 private: |
401 // Intended to hold the largest stack used by Chrome. The default Win32 | 401 enum { |
402 // reserved stack size is 1 MB and Chrome Windows threads currently always | 402 // Intended to hold the largest stack used by Chrome. The default Win32 |
403 // use the default, but this allows for expansion if it occurs. The size | 403 // reserved stack size is 1 MB and Chrome Windows threads currently always |
404 // beyond the actual stack size consists of unallocated virtual memory pages | 404 // use the default, but this allows for expansion if it occurs. The size |
405 // so carries little cost (just a bit of wasted address space). | 405 // beyond the actual stack size consists of unallocated virtual memory pages |
406 static constexpr size_t kStackCopyBufferSize = 2 * 1024 * 1024; | 406 // so carries little cost (just a bit of wasted address space). |
| 407 kStackCopyBufferSize = 2 * 1024 * 1024 |
| 408 }; |
407 | 409 |
408 // Attempts to query the module filename, base address, and id for | 410 // Attempts to query the module filename, base address, and id for |
409 // |module_handle|, and store them in |module|. Returns true if it succeeded. | 411 // |module_handle|, and store them in |module|. Returns true if it succeeded. |
410 static bool GetModuleForHandle(HMODULE module_handle, | 412 static bool GetModuleForHandle(HMODULE module_handle, |
411 StackSamplingProfiler::Module* module); | 413 StackSamplingProfiler::Module* module); |
412 | 414 |
413 // Gets the index for the Module corresponding to |module_handle| in | 415 // Gets the index for the Module corresponding to |module_handle| in |
414 // |modules|, adding it if it's not already present. Returns | 416 // |modules|, adding it if it's not already present. Returns |
415 // StackSamplingProfiler::Frame::kUnknownModuleIndex if no Module can be | 417 // StackSamplingProfiler::Frame::kUnknownModuleIndex if no Module can be |
416 // determined for |module|. | 418 // determined for |module|. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 void NativeStackSamplerWin::ProfileRecordingStarting( | 467 void NativeStackSamplerWin::ProfileRecordingStarting( |
466 std::vector<StackSamplingProfiler::Module>* modules) { | 468 std::vector<StackSamplingProfiler::Module>* modules) { |
467 current_modules_ = modules; | 469 current_modules_ = modules; |
468 profile_module_index_.clear(); | 470 profile_module_index_.clear(); |
469 } | 471 } |
470 | 472 |
471 void NativeStackSamplerWin::RecordStackSample( | 473 void NativeStackSamplerWin::RecordStackSample( |
472 StackSamplingProfiler::Sample* sample) { | 474 StackSamplingProfiler::Sample* sample) { |
473 DCHECK(current_modules_); | 475 DCHECK(current_modules_); |
474 | 476 |
| 477 if (!stack_copy_buffer_) |
| 478 return; |
| 479 |
475 std::vector<RecordedFrame> stack; | 480 std::vector<RecordedFrame> stack; |
476 SuspendThreadAndRecordStack(thread_handle_.Get(), thread_stack_base_address_, | 481 SuspendThreadAndRecordStack(thread_handle_.Get(), thread_stack_base_address_, |
477 stack_copy_buffer_.get(), kStackCopyBufferSize, | 482 stack_copy_buffer_.get(), kStackCopyBufferSize, |
478 &stack, annotator_, sample, test_delegate_); | 483 &stack, annotator_, sample, test_delegate_); |
479 CopyToSample(stack, sample, current_modules_); | 484 CopyToSample(stack, sample, current_modules_); |
480 } | 485 } |
481 | 486 |
482 void NativeStackSamplerWin::ProfileRecordingStopped() { | 487 void NativeStackSamplerWin::ProfileRecordingStopped() { |
483 current_modules_ = nullptr; | 488 current_modules_ = nullptr; |
484 } | 489 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 | 557 |
553 if (thread_handle) { | 558 if (thread_handle) { |
554 return std::unique_ptr<NativeStackSampler>(new NativeStackSamplerWin( | 559 return std::unique_ptr<NativeStackSampler>(new NativeStackSamplerWin( |
555 win::ScopedHandle(thread_handle), annotator, test_delegate)); | 560 win::ScopedHandle(thread_handle), annotator, test_delegate)); |
556 } | 561 } |
557 #endif | 562 #endif |
558 return std::unique_ptr<NativeStackSampler>(); | 563 return std::unique_ptr<NativeStackSampler>(); |
559 } | 564 } |
560 | 565 |
561 } // namespace base | 566 } // namespace base |
OLD | NEW |