Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: base/profiler/native_stack_sampler_win.cc

Issue 2702463003: NativeStackSampler implementation for Mac. (Closed)
Patch Set: rev Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 enum { 401 // Intended to hold the largest stack used by Chrome. The default Win32
402 // Intended to hold the largest stack used by Chrome. The default Win32 402 // reserved stack size is 1 MB and Chrome Windows threads currently always
403 // reserved stack size is 1 MB and Chrome Windows threads currently always 403 // use the default, but this allows for expansion if it occurs. The size
404 // use the default, but this allows for expansion if it occurs. The size 404 // beyond the actual stack size consists of unallocated virtual memory pages
405 // beyond the actual stack size consists of unallocated virtual memory pages 405 // so carries little cost (just a bit of wasted address space).
406 // so carries little cost (just a bit of wasted address space). 406 static constexpr size_t kStackCopyBufferSize = 2 * 1024 * 1024;
407 kStackCopyBufferSize = 2 * 1024 * 1024
408 };
409 407
410 // Attempts to query the module filename, base address, and id for 408 // Attempts to query the module filename, base address, and id for
411 // |module_handle|, and store them in |module|. Returns true if it succeeded. 409 // |module_handle|, and store them in |module|. Returns true if it succeeded.
412 static bool GetModuleForHandle(HMODULE module_handle, 410 static bool GetModuleForHandle(HMODULE module_handle,
413 StackSamplingProfiler::Module* module); 411 StackSamplingProfiler::Module* module);
414 412
415 // Gets the index for the Module corresponding to |module_handle| in 413 // Gets the index for the Module corresponding to |module_handle| in
416 // |modules|, adding it if it's not already present. Returns 414 // |modules|, adding it if it's not already present. Returns
417 // StackSamplingProfiler::Frame::kUnknownModuleIndex if no Module can be 415 // StackSamplingProfiler::Frame::kUnknownModuleIndex if no Module can be
418 // determined for |module|. 416 // determined for |module|.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 void NativeStackSamplerWin::ProfileRecordingStarting( 465 void NativeStackSamplerWin::ProfileRecordingStarting(
468 std::vector<StackSamplingProfiler::Module>* modules) { 466 std::vector<StackSamplingProfiler::Module>* modules) {
469 current_modules_ = modules; 467 current_modules_ = modules;
470 profile_module_index_.clear(); 468 profile_module_index_.clear();
471 } 469 }
472 470
473 void NativeStackSamplerWin::RecordStackSample( 471 void NativeStackSamplerWin::RecordStackSample(
474 StackSamplingProfiler::Sample* sample) { 472 StackSamplingProfiler::Sample* sample) {
475 DCHECK(current_modules_); 473 DCHECK(current_modules_);
476 474
477 if (!stack_copy_buffer_)
478 return;
479
480 std::vector<RecordedFrame> stack; 475 std::vector<RecordedFrame> stack;
481 SuspendThreadAndRecordStack(thread_handle_.Get(), thread_stack_base_address_, 476 SuspendThreadAndRecordStack(thread_handle_.Get(), thread_stack_base_address_,
482 stack_copy_buffer_.get(), kStackCopyBufferSize, 477 stack_copy_buffer_.get(), kStackCopyBufferSize,
483 &stack, annotator_, sample, test_delegate_); 478 &stack, annotator_, sample, test_delegate_);
484 CopyToSample(stack, sample, current_modules_); 479 CopyToSample(stack, sample, current_modules_);
485 } 480 }
486 481
487 void NativeStackSamplerWin::ProfileRecordingStopped() { 482 void NativeStackSamplerWin::ProfileRecordingStopped() {
488 current_modules_ = nullptr; 483 current_modules_ = nullptr;
489 } 484 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 552
558 if (thread_handle) { 553 if (thread_handle) {
559 return std::unique_ptr<NativeStackSampler>(new NativeStackSamplerWin( 554 return std::unique_ptr<NativeStackSampler>(new NativeStackSamplerWin(
560 win::ScopedHandle(thread_handle), annotator, test_delegate)); 555 win::ScopedHandle(thread_handle), annotator, test_delegate));
561 } 556 }
562 #endif 557 #endif
563 return std::unique_ptr<NativeStackSampler>(); 558 return std::unique_ptr<NativeStackSampler>();
564 } 559 }
565 560
566 } // namespace base 561 } // namespace base
OLDNEW
« no previous file with comments | « base/profiler/native_stack_sampler_mac.cc ('k') | base/profiler/stack_sampling_profiler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698