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

Side by Side Diff: src/profiler/tick-sample.h

Issue 1952393002: Split TickSample and Sampler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « src/profiler/sampler.cc ('k') | src/profiler/tick-sample.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project 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 V8_PROFILER_SAMPLER_H_ 5 #ifndef V8_PROFILER_TICK_SAMPLE_H_
6 #define V8_PROFILER_SAMPLER_H_ 6 #define V8_PROFILER_TICK_SAMPLE_H_
7 7
8 #include "include/v8.h" 8 #include "include/v8.h"
9 9
10 #include "src/base/atomicops.h"
11 #include "src/base/platform/time.h" 10 #include "src/base/platform/time.h"
12 #include "src/frames.h" 11 #include "src/frames.h"
13 #include "src/globals.h" 12 #include "src/globals.h"
14 13
15 namespace v8 { 14 namespace v8 {
16 namespace internal { 15 namespace internal {
17 16
18 class Isolate; 17 class Isolate;
19 18
20 // ---------------------------------------------------------------------------- 19 // ----------------------------------------------------------------------------
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static const unsigned kMaxFramesCountLog2 = 8; 53 static const unsigned kMaxFramesCountLog2 = 8;
55 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; 54 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
56 Address stack[kMaxFramesCount]; // Call stack. 55 Address stack[kMaxFramesCount]; // Call stack.
57 base::TimeTicks timestamp; 56 base::TimeTicks timestamp;
58 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. 57 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
59 bool has_external_callback : 1; 58 bool has_external_callback : 1;
60 bool update_stats : 1; // Whether the sample should update aggregated stats. 59 bool update_stats : 1; // Whether the sample should update aggregated stats.
61 StackFrame::Type top_frame_type : 5; 60 StackFrame::Type top_frame_type : 5;
62 }; 61 };
63 62
64 class Sampler {
65 public:
66 // Initializes the Sampler support. Called once at VM startup.
67 static void SetUp();
68 static void TearDown();
69
70 // Initialize sampler.
71 Sampler(Isolate* isolate, int interval);
72 virtual ~Sampler();
73
74 Isolate* isolate() const { return isolate_; }
75 int interval() const { return interval_; }
76
77 // Performs stack sampling.
78 void SampleStack(const v8::RegisterState& regs);
79
80 // Start and stop sampler.
81 void Start();
82 void Stop();
83
84 // Whether the sampling thread should use this Sampler for CPU profiling?
85 bool IsProfiling() const {
86 return base::NoBarrier_Load(&profiling_) > 0 &&
87 !base::NoBarrier_Load(&has_processing_thread_);
88 }
89 void IncreaseProfilingDepth();
90 void DecreaseProfilingDepth();
91
92 // Whether the sampler is running (that is, consumes resources).
93 bool IsActive() const { return base::NoBarrier_Load(&active_); }
94
95 // CpuProfiler collects samples by calling DoSample directly
96 // without calling Start. To keep it working, we register the sampler
97 // with the CpuProfiler.
98 bool IsRegistered() const { return base::NoBarrier_Load(&registered_); }
99
100 void DoSample();
101 // If true next sample must be initiated on the profiler event processor
102 // thread right after latest sample is processed.
103 void SetHasProcessingThread(bool value) {
104 base::NoBarrier_Store(&has_processing_thread_, value);
105 }
106
107 // Used in tests to make sure that stack sampling is performed.
108 unsigned js_sample_count() const { return js_sample_count_; }
109 unsigned external_sample_count() const { return external_sample_count_; }
110 void StartCountingSamples() {
111 js_sample_count_ = 0;
112 external_sample_count_ = 0;
113 is_counting_samples_ = true;
114 }
115
116 class PlatformData;
117 PlatformData* platform_data() const { return data_; }
118
119 protected:
120 // This method is called for each sampling period with the current
121 // program counter.
122 virtual void Tick(TickSample* sample) = 0;
123
124 private:
125 void SetActive(bool value) { base::NoBarrier_Store(&active_, value); }
126
127 void SetRegistered(bool value) { base::NoBarrier_Store(&registered_, value); }
128
129 Isolate* isolate_;
130 const int interval_;
131 base::Atomic32 profiling_;
132 base::Atomic32 has_processing_thread_;
133 base::Atomic32 active_;
134 base::Atomic32 registered_;
135 PlatformData* data_; // Platform specific data.
136 // Counts stack samples taken in various VM states.
137 bool is_counting_samples_;
138 unsigned js_sample_count_;
139 unsigned external_sample_count_;
140 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
141 };
142
143 63
144 #if defined(USE_SIMULATOR) 64 #if defined(USE_SIMULATOR)
145 class SimulatorHelper : AllStatic { 65 class SimulatorHelper {
146 public: 66 public:
147 // Returns true if register values were successfully retrieved 67 // Returns true if register values were successfully retrieved
148 // from the simulator, otherwise returns false. 68 // from the simulator, otherwise returns false.
149 static bool FillRegisters(Isolate* isolate, v8::RegisterState* state); 69 static bool FillRegisters(Isolate* isolate, v8::RegisterState* state);
150 }; 70 };
151 #endif // USE_SIMULATOR 71 #endif // USE_SIMULATOR
152 72
153
154 } // namespace internal 73 } // namespace internal
155 } // namespace v8 74 } // namespace v8
156 75
157 #endif // V8_PROFILER_SAMPLER_H_ 76 #endif // V8_PROFILER_TICK_SAMPLE_H_
OLDNEW
« no previous file with comments | « src/profiler/sampler.cc ('k') | src/profiler/tick-sample.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698