5 #ifndef V8_PROFILER_CPU_PROFILER_H_ 6 #define V8_PROFILER_CPU_PROFILER_H_ 10 #include "src/allocation.h" 11 #include "src/base/atomic-utils.h" 12 #include "src/base/atomicops.h" 13 #include "src/base/platform/time.h" 14 #include "src/isolate.h" 15 #include "src/libsampler/sampler.h" 16 #include "src/locked-queue.h" 17 #include "src/profiler/circular-queue.h" 18 #include "src/profiler/profiler-listener.h" 19 #include "src/profiler/tick-sample.h" 28 class CpuProfilesCollection;
29 class ProfileGenerator;
31 #define CODE_EVENTS_TYPE_LIST(V) \ 32 V(CODE_CREATION, CodeCreateEventRecord) \ 33 V(CODE_MOVE, CodeMoveEventRecord) \ 34 V(CODE_DISABLE_OPT, CodeDisableOptEventRecord) \ 35 V(CODE_DEOPT, CodeDeoptEventRecord) \ 36 V(REPORT_BUILTIN, ReportBuiltinEventRecord) 41 #define DECLARE_TYPE(type, ignore) type, 44 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE)
49 mutable unsigned order;
57 unsigned instruction_size;
59 V8_INLINE
void UpdateCodeMap(
CodeMap* code_map);
68 V8_INLINE
void UpdateCodeMap(
CodeMap* code_map);
75 const char* bailout_reason;
77 V8_INLINE
void UpdateCodeMap(
CodeMap* code_map);
84 const char* deopt_reason;
89 int deopt_frame_count;
91 V8_INLINE
void UpdateCodeMap(
CodeMap* code_map);
98 Builtins::Name builtin_id;
100 V8_INLINE
void UpdateCodeMap(
CodeMap* code_map);
119 CodeEventRecord::Type
type = CodeEventRecord::NONE) {
124 #define DECLARE_CLASS(ignore, type) type type##_; 125 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS)
140 void Run()
override = 0;
141 void StopSynchronously();
142 V8_INLINE
bool running() {
return !!base::Relaxed_Load(&running_); }
146 void AddCurrentStack(
bool update_stats =
false);
147 void AddDeoptStack(
Address from,
int fp_to_sp_delta);
155 bool ProcessCodeEvent();
157 enum SampleProcessingResult {
159 FoundSampleForNextCodeEvent,
162 virtual SampleProcessingResult ProcessOneSample() = 0;
165 base::Atomic32 running_;
168 std::atomic<unsigned> last_code_event_id_;
169 unsigned last_processed_code_event_id_;
181 void*
operator new(
size_t size);
182 void operator delete(
void* ptr);
193 inline void FinishTickSample();
198 SampleProcessingResult ProcessOneSample()
override;
200 static const size_t kTickSampleBufferSize = 1 * MB;
201 static const size_t kTickSampleQueueLength =
204 kTickSampleQueueLength> ticks_buffer_;
205 std::unique_ptr<sampler::Sampler> sampler_;
219 static void CollectSample(
Isolate* isolate);
221 typedef v8::CpuProfilingMode ProfilingMode;
224 void CollectSample();
225 void StartProfiling(
const char* title,
bool record_samples =
false,
226 ProfilingMode mode = ProfilingMode::kLeafNodeLineNumbers);
227 void StartProfiling(
String title,
bool record_samples, ProfilingMode mode);
230 int GetProfilesCount();
232 void DeleteAllProfiles();
235 bool is_profiling()
const {
return is_profiling_; }
239 Isolate* isolate()
const {
return isolate_; }
242 return profiler_listener_.get();
246 void StartProcessorIfNotStarted();
247 void StopProcessorIfLastProfile(
const char* title);
248 void StopProcessor();
249 void ResetProfiles();
251 void CreateEntriesForRuntimeCallStats();
255 std::unique_ptr<CpuProfilesCollection> profiles_;
256 std::unique_ptr<ProfileGenerator> generator_;
257 std::unique_ptr<ProfilerEventsProcessor> processor_;
258 std::unique_ptr<ProfilerListener> profiler_listener_;
259 bool saved_is_logging_;
268 #endif // V8_PROFILER_CPU_PROFILER_H_