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

Side by Side Diff: src/profiler/cpu-profiler.h

Issue 2053523003: Refactor CpuProfiler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 6 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/log.cc ('k') | src/profiler/cpu-profiler.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_CPU_PROFILER_H_ 5 #ifndef V8_PROFILER_CPU_PROFILER_H_
6 #define V8_PROFILER_CPU_PROFILER_H_ 6 #define V8_PROFILER_CPU_PROFILER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
11 #include "src/base/atomic-utils.h" 11 #include "src/base/atomic-utils.h"
12 #include "src/base/atomicops.h" 12 #include "src/base/atomicops.h"
13 #include "src/base/platform/time.h" 13 #include "src/base/platform/time.h"
14 #include "src/compiler.h" 14 #include "src/compiler.h"
15 #include "src/isolate.h" 15 #include "src/isolate.h"
16 #include "src/libsampler/v8-sampler.h" 16 #include "src/libsampler/v8-sampler.h"
17 #include "src/locked-queue.h" 17 #include "src/locked-queue.h"
18 #include "src/profiler/circular-queue.h" 18 #include "src/profiler/circular-queue.h"
19 #include "src/profiler/profiler-listener.h"
19 #include "src/profiler/tick-sample.h" 20 #include "src/profiler/tick-sample.h"
20 21
21 namespace v8 { 22 namespace v8 {
22 namespace internal { 23 namespace internal {
23 24
24 // Forward declarations. 25 // Forward declarations.
25 class CodeEntry; 26 class CodeEntry;
26 class CodeMap; 27 class CodeMap;
27 class CpuProfile; 28 class CpuProfile;
28 class CpuProfilesCollection; 29 class CpuProfilesCollection;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 INLINE(void UpdateCodeMap(CodeMap* code_map)); 79 INLINE(void UpdateCodeMap(CodeMap* code_map));
79 }; 80 };
80 81
81 82
82 class CodeDeoptEventRecord : public CodeEventRecord { 83 class CodeDeoptEventRecord : public CodeEventRecord {
83 public: 84 public:
84 Address start; 85 Address start;
85 const char* deopt_reason; 86 const char* deopt_reason;
86 SourcePosition position; 87 SourcePosition position;
87 int deopt_id; 88 int deopt_id;
89 void* pc;
90 int fp_to_sp_delta;
88 91
89 INLINE(void UpdateCodeMap(CodeMap* code_map)); 92 INLINE(void UpdateCodeMap(CodeMap* code_map));
90 }; 93 };
91 94
92 95
93 class ReportBuiltinEventRecord : public CodeEventRecord { 96 class ReportBuiltinEventRecord : public CodeEventRecord {
94 public: 97 public:
95 Address start; 98 Address start;
96 Builtins::Name builtin_id; 99 Builtins::Name builtin_id;
97 100
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 static const size_t kTickSampleBufferSize = 1 * MB; 179 static const size_t kTickSampleBufferSize = 1 * MB;
177 static const size_t kTickSampleQueueLength = 180 static const size_t kTickSampleQueueLength =
178 kTickSampleBufferSize / sizeof(TickSampleEventRecord); 181 kTickSampleBufferSize / sizeof(TickSampleEventRecord);
179 SamplingCircularQueue<TickSampleEventRecord, 182 SamplingCircularQueue<TickSampleEventRecord,
180 kTickSampleQueueLength> ticks_buffer_; 183 kTickSampleQueueLength> ticks_buffer_;
181 LockedQueue<TickSampleEventRecord> ticks_from_vm_buffer_; 184 LockedQueue<TickSampleEventRecord> ticks_from_vm_buffer_;
182 base::AtomicNumber<unsigned> last_code_event_id_; 185 base::AtomicNumber<unsigned> last_code_event_id_;
183 unsigned last_processed_code_event_id_; 186 unsigned last_processed_code_event_id_;
184 }; 187 };
185 188
186 class CpuProfiler : public CodeEventListener { 189 class CpuProfiler : public CodeEventObserver {
187 public: 190 public:
188 explicit CpuProfiler(Isolate* isolate); 191 explicit CpuProfiler(Isolate* isolate);
189 192
190 CpuProfiler(Isolate* isolate, CpuProfilesCollection* profiles, 193 CpuProfiler(Isolate* isolate, CpuProfilesCollection* profiles,
191 ProfileGenerator* test_generator, 194 ProfileGenerator* test_generator,
192 ProfilerEventsProcessor* test_processor); 195 ProfilerEventsProcessor* test_processor);
193 196
194 ~CpuProfiler() override; 197 ~CpuProfiler() override;
195 198
196 void set_sampling_interval(base::TimeDelta value); 199 void set_sampling_interval(base::TimeDelta value);
197 void CollectSample(); 200 void CollectSample();
198 void StartProfiling(const char* title, bool record_samples = false); 201 void StartProfiling(const char* title, bool record_samples = false);
199 void StartProfiling(String* title, bool record_samples); 202 void StartProfiling(String* title, bool record_samples);
200 CpuProfile* StopProfiling(const char* title); 203 CpuProfile* StopProfiling(const char* title);
201 CpuProfile* StopProfiling(String* title); 204 CpuProfile* StopProfiling(String* title);
202 int GetProfilesCount(); 205 int GetProfilesCount();
203 CpuProfile* GetProfile(int index); 206 CpuProfile* GetProfile(int index);
204 void DeleteAllProfiles(); 207 void DeleteAllProfiles();
205 void DeleteProfile(CpuProfile* profile); 208 void DeleteProfile(CpuProfile* profile);
206 209
210 void CodeEventHandler(const CodeEventsContainer& evt_rec) override;
211
207 // Invoked from stack sampler (thread or signal handler.) 212 // Invoked from stack sampler (thread or signal handler.)
208 inline TickSample* StartTickSample(); 213 inline TickSample* StartTickSample();
209 inline void FinishTickSample(); 214 inline void FinishTickSample();
210 215
211 // Must be called via PROFILE macro, otherwise will crash when
212 // profiling is not enabled.
213 void CallbackEvent(Name* name, Address entry_point) override;
214 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
215 const char* comment) override;
216 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
217 Name* name) override;
218 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
219 SharedFunctionInfo* shared, Name* script_name) override;
220 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
221 SharedFunctionInfo* shared, Name* script_name, int line,
222 int column) override;
223 void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
224 int args_count) override;
225 void CodeMovingGCEvent() override {}
226 void CodeMoveEvent(AbstractCode* from, Address to) override;
227 void CodeDisableOptEvent(AbstractCode* code,
228 SharedFunctionInfo* shared) override;
229 void CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) override;
230 void GetterCallbackEvent(Name* name, Address entry_point) override;
231 void RegExpCodeCreateEvent(AbstractCode* code, String* source) override;
232 void SetterCallbackEvent(Name* name, Address entry_point) override;
233 void SharedFunctionInfoMoveEvent(Address from, Address to) override {}
234
235 bool is_profiling() const { return is_profiling_; } 216 bool is_profiling() const { return is_profiling_; }
236 217
237 ProfileGenerator* generator() const { return generator_.get(); } 218 ProfileGenerator* generator() const { return generator_.get(); }
238 ProfilerEventsProcessor* processor() const { return processor_.get(); } 219 ProfilerEventsProcessor* processor() const { return processor_.get(); }
239 Isolate* isolate() const { return isolate_; } 220 Isolate* isolate() const { return isolate_; }
240 221
241 private: 222 private:
242 void StartProcessorIfNotStarted(); 223 void StartProcessorIfNotStarted();
243 void StopProcessorIfLastProfile(const char* title); 224 void StopProcessorIfLastProfile(const char* title);
244 void StopProcessor(); 225 void StopProcessor();
245 void ResetProfiles(); 226 void ResetProfiles();
246 void LogBuiltins(); 227 void LogBuiltins();
247 void RecordInliningInfo(CodeEntry* entry, AbstractCode* abstract_code);
248 void RecordDeoptInlinedFrames(CodeEntry* entry, AbstractCode* abstract_code);
249 Name* InferScriptName(Name* name, SharedFunctionInfo* info);
250 228
251 Isolate* const isolate_; 229 Isolate* const isolate_;
252 base::TimeDelta sampling_interval_; 230 base::TimeDelta sampling_interval_;
253 std::unique_ptr<CpuProfilesCollection> profiles_; 231 std::unique_ptr<CpuProfilesCollection> profiles_;
254 std::unique_ptr<ProfileGenerator> generator_; 232 std::unique_ptr<ProfileGenerator> generator_;
255 std::unique_ptr<ProfilerEventsProcessor> processor_; 233 std::unique_ptr<ProfilerEventsProcessor> processor_;
256 bool saved_is_logging_; 234 bool saved_is_logging_;
257 bool is_profiling_; 235 bool is_profiling_;
258 236
259 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); 237 DISALLOW_COPY_AND_ASSIGN(CpuProfiler);
260 }; 238 };
261 239
262 } // namespace internal 240 } // namespace internal
263 } // namespace v8 241 } // namespace v8
264 242
265 243
266 #endif // V8_PROFILER_CPU_PROFILER_H_ 244 #endif // V8_PROFILER_CPU_PROFILER_H_
OLDNEW
« no previous file with comments | « src/log.cc ('k') | src/profiler/cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698