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

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: change from shared static buffer to caller-owned 'common' buffer Created 3 years, 10 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.
28 class Common {
Mike Wittman 2017/01/24 17:20:56 We should just call this StackBuffer. If the conce
bcwhite 2017/02/07 15:16:35 Done.
29 public:
30 virtual ~Common() {}
31
32 protected:
33 Common() {}
34 };
Mike Wittman 2017/01/24 17:20:56 DISALLOW_COPY_AND_ASSIGN
bcwhite 2017/02/07 15:16:35 Done.
35
24 // The callback type used to add annotations to a sample during collection. 36 // 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 37 // 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 38 // 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 39 // completely predictable and do nothing that could acquire a mutex; a
28 // Callback object is code outside the control of this object and could, 40 // 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 41 // for example, acquire a mutex as part of allocating memory for a LOG
30 // message. 42 // message.
31 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*); 43 using AnnotateCallback = void (*)(StackSamplingProfiler::Sample*);
32 44
33 virtual ~NativeStackSampler(); 45 virtual ~NativeStackSampler();
34 46
35 // Creates a stack sampler that records samples for |thread_handle|. Returns 47 // Creates a stack sampler that records samples for |thread_handle|. Returns
36 // null if this platform does not support stack sampling. 48 // null if this platform does not support stack sampling.
37 static std::unique_ptr<NativeStackSampler> Create( 49 static std::unique_ptr<NativeStackSampler> Create(
38 PlatformThreadId thread_id, 50 PlatformThreadId thread_id,
39 AnnotateCallback annotator, 51 AnnotateCallback annotator,
40 NativeStackSamplerTestDelegate* test_delegate); 52 NativeStackSamplerTestDelegate* test_delegate);
41 53
42 // The following functions are all called on the SamplingThread (not the 54 // The following functions are all called on the SamplingThread (not the
43 // thread being sampled). 55 // thread being sampled).
44 56
57 // Creates an instance of "common" data buffers.
58 virtual std::unique_ptr<Common> CreateCommon();
Mike Wittman 2017/01/24 17:20:56 This function doesn't depend on the instance so sh
bcwhite 2017/02/07 15:16:35 Done.
59
45 // Notifies the sampler that we're starting to record a new profile. Modules 60 // 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|. 61 // shared across samples in the profile should be recorded in |modules|.
47 virtual void ProfileRecordingStarting( 62 virtual void ProfileRecordingStarting(
63 Common* common,
Mike Wittman 2017/01/24 17:20:57 No need to pass this to ProfileRecordingStarting o
bcwhite 2017/02/07 15:16:35 Done.
48 std::vector<StackSamplingProfiler::Module>* modules) = 0; 64 std::vector<StackSamplingProfiler::Module>* modules) = 0;
49 65
50 // Records a stack sample to |sample|. 66 // Records a stack sample to |sample|.
51 virtual void RecordStackSample(StackSamplingProfiler::Sample* sample) = 0; 67 virtual void RecordStackSample(Common* common,
Mike Wittman 2017/01/24 17:20:57 Doesn't the calling code need to be updated?
bcwhite 2017/02/07 15:16:35 Yes but since the calling code is in the middle of
68 StackSamplingProfiler::Sample* sample) = 0;
52 69
53 // Notifies the sampler that we've stopped recording the current 70 // Notifies the sampler that we've stopped recording the current
54 // profile. 71 // profile.
55 virtual void ProfileRecordingStopped() = 0; 72 virtual void ProfileRecordingStopped(Common* common) = 0;
56 73
57 protected: 74 protected:
58 NativeStackSampler(); 75 NativeStackSampler();
59 76
60 private: 77 private:
61 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler); 78 DISALLOW_COPY_AND_ASSIGN(NativeStackSampler);
62 }; 79 };
63 80
64 // NativeStackSamplerTestDelegate provides seams for test code to execute during 81 // NativeStackSamplerTestDelegate provides seams for test code to execute during
65 // stack collection. 82 // stack collection.
66 class BASE_EXPORT NativeStackSamplerTestDelegate { 83 class BASE_EXPORT NativeStackSamplerTestDelegate {
67 public: 84 public:
68 virtual ~NativeStackSamplerTestDelegate(); 85 virtual ~NativeStackSamplerTestDelegate();
69 86
70 // Called after copying the stack and resuming the target thread, but prior to 87 // Called after copying the stack and resuming the target thread, but prior to
71 // walking the stack. Invoked on the SamplingThread. 88 // walking the stack. Invoked on the SamplingThread.
72 virtual void OnPreStackWalk() = 0; 89 virtual void OnPreStackWalk() = 0;
73 90
74 protected: 91 protected:
75 NativeStackSamplerTestDelegate(); 92 NativeStackSamplerTestDelegate();
76 93
77 private: 94 private:
78 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate); 95 DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate);
79 }; 96 };
80 97
81 } // namespace base 98 } // namespace base
82 99
83 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ 100 #endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_
84 101
OLDNEW
« no previous file with comments | « no previous file | base/profiler/native_stack_sampler_win.cc » ('j') | base/profiler/native_stack_sampler_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698