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

Side by Side Diff: base/profiler/native_stack_sampler.h

Issue 2601633002: Use a common buffer across all instances for stack-copy. (Closed)
Patch Set: use common StackBuffer; update Mac native sampler Created 3 years, 7 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 #ifndef BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 5 #ifndef BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
6 #define BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 6 #define BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/profiler/stack_sampling_profiler.h" 12 #include "base/profiler/stack_sampling_profiler.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 class NativeStackSamplerTestDelegate; 17 class NativeStackSamplerTestDelegate;
18 18
19 // NativeStackSampler is an implementation detail of StackSamplingProfiler. It 19 // NativeStackSampler is an implementation detail of StackSamplingProfiler. It
20 // abstracts the native implementation required to record a stack sample for a 20 // abstracts the native implementation required to record a stack sample for a
21 // given thread. 21 // given thread.
22 class NativeStackSampler { 22 class NativeStackSampler {
23 public: 23 public:
24 // This class contains data structures that can be shared across multiple
25 // instances of NativeStackSampler so long as they do not run concurrently.
26 // This supports having a single instance of large structures such as copy
27 // buffers.
Mike Wittman 2017/05/10 01:29:56 For this comment I think it's sufficient to say ju
bcwhite 2017/05/10 13:50:37 The "no concurrent" clause is important.
Mike Wittman 2017/05/10 17:17:21 "It's not safe to share a writable memory buffer a
bcwhite 2017/05/11 16:56:31 Done.
28 class StackBuffer {
29 public:
30 StackBuffer(size_t buffer_size);
31 ~StackBuffer();
32
33 unsigned char* buffer() { return buffer_.get(); }
Mike Wittman 2017/05/10 01:29:57 void* for return type. There's no natural size for
bcwhite 2017/05/10 13:50:37 Done.
34 size_t size() { return size_; }
35
36 private:
37 const std::unique_ptr<unsigned char[]> buffer_;
38 const size_t size_;
39
40 DISALLOW_COPY_AND_ASSIGN(StackBuffer);
41 };
42
24 // The callback type used to add annotations to a sample during collection. 43 // The callback type used to add annotations to a sample during collection.
25 // This is passed to the native sampler to be applied at the most appropriate 44 // This is passed to the native sampler to be applied at the most appropriate
26 // time. It is a simple function-pointer because the generated code must be 45 // time. It is a simple function-pointer because the generated code must be
27 // completely predictable and do nothing that could acquire a mutex; a 46 // completely predictable and do nothing that could acquire a mutex; a
28 // Callback object is code outside the control of this object and could, 47 // Callback object is code outside the control of this object and could,
29 // for example, acquire a mutex as part of allocating memory for a LOG 48 // for example, acquire a mutex as part of allocating memory for a LOG
30 // message. 49 // message.
31 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*); 50 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*);
32 51
33 virtual ~NativeStackSampler(); 52 virtual ~NativeStackSampler();
34 53
35 // Creates a stack sampler that records samples for |thread_handle|. Returns 54 // Creates a stack sampler that records samples for |thread_handle|. Returns
36 // null if this platform does not support stack sampling. 55 // null if this platform does not support stack sampling.
37 static std::unique_ptr<NativeStackSampler> Create( 56 static std::unique_ptr<NativeStackSampler> Create(
38 PlatformThreadId thread_id, 57 PlatformThreadId thread_id,
39 AnnotateCallback annotator, 58 AnnotateCallback annotator,
40 NativeStackSamplerTestDelegate* test_delegate); 59 NativeStackSamplerTestDelegate* test_delegate);
41 60
61 // Creates an instance of the necessary stack buffer.
62 static std::unique_ptr<StackBuffer> CreateStackBuffer();
63
42 // The following functions are all called on the SamplingThread (not the 64 // The following functions are all called on the SamplingThread (not the
43 // thread being sampled). 65 // thread being sampled).
44 66
45 // Notifies the sampler that we're starting to record a new profile. Modules 67 // Notifies the sampler that we're starting to record a new profile. Modules
46 // shared across samples in the profile should be recorded in |modules|. 68 // shared across samples in the profile should be recorded in |modules|.
47 virtual void ProfileRecordingStarting( 69 virtual void ProfileRecordingStarting(
48 std::vector<StackSamplingProfiler::Module>* modules) = 0; 70 std::vector<StackSamplingProfiler::Module>* modules) = 0;
49 71
50 // Records a stack sample to |sample|. 72 // Records a stack sample to |sample|.
51 virtual void RecordStackSample(StackSamplingProfiler::Sample* sample) = 0; 73 virtual void RecordStackSample(StackBuffer* stackbuffer,
Mike Wittman 2017/05/10 01:29:57 nit: stack_buffer (applies throughout)
bcwhite 2017/05/10 13:50:37 Done.
74 StackSamplingProfiler::Sample* sample) = 0;
52 75
53 // Notifies the sampler that we've stopped recording the current 76 // Notifies the sampler that we've stopped recording the current
54 // profile. 77 // profile.
55 virtual void ProfileRecordingStopped() = 0; 78 virtual void ProfileRecordingStopped(StackBuffer* stackbuffer) = 0;
56 79
57 protected: 80 protected:
58 NativeStackSampler(); 81 NativeStackSampler();
59 82
60 private: 83 private:
61 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler); 84 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler);
62 }; 85 };
63 86
64 // NativeStackSamplerTestDelegate provides seams for test code to execute during 87 // NativeStackSamplerTestDelegate provides seams for test code to execute during
65 // stack collection. 88 // stack collection.
66 class BASE_EXPORT NativeStackSamplerTestDelegate { 89 class BASE_EXPORT NativeStackSamplerTestDelegate {
67 public: 90 public:
68 virtual ~NativeStackSamplerTestDelegate(); 91 virtual ~NativeStackSamplerTestDelegate();
69 92
70 // Called after copying the stack and resuming the target thread, but prior to 93 // Called after copying the stack and resuming the target thread, but prior to
71 // walking the stack. Invoked on the SamplingThread. 94 // walking the stack. Invoked on the SamplingThread.
72 virtual void OnPreStackWalk() = 0; 95 virtual void OnPreStackWalk() = 0;
73 96
74 protected: 97 protected:
75 NativeStackSamplerTestDelegate(); 98 NativeStackSamplerTestDelegate();
76 99
77 private: 100 private:
78 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate); 101 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate);
79 }; 102 };
80 103
81 } // namespace base 104 } // namespace base
82 105
83 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 106 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
84 107
OLDNEW
« no previous file with comments | « no previous file | base/profiler/native_stack_sampler.cc » ('j') | base/profiler/native_stack_sampler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698