38 #include "../include/v8-profiler.h"
43 static const int kProfilerStackSize = 64 *
KB;
51 generator_(generator),
55 last_code_event_id_(0), last_processed_code_event_id_(0) {
60 event.generic.order = ++last_code_event_id_;
61 events_buffer_.Enqueue(event);
71 regs.
sp = frame->sp();
72 regs.
fp = frame->fp();
73 regs.
pc = frame->pc();
76 ticks_from_vm_buffer_.Enqueue(record);
81 if (!running_)
return;
87 bool ProfilerEventsProcessor::ProcessCodeEvent() {
89 if (events_buffer_.Dequeue(&record)) {
91 #define PROFILER_TYPE_CASE(type, clss) \
92 case CodeEventRecord::type: \
93 record.clss##_.UpdateCodeMap(generator_->code_map()); \
98 #undef PROFILER_TYPE_CASE
107 ProfilerEventsProcessor::SampleProcessingResult
108 ProfilerEventsProcessor::ProcessOneSample() {
109 if (!ticks_from_vm_buffer_.IsEmpty()
110 && ticks_from_vm_buffer_.Peek()->order ==
111 last_processed_code_event_id_) {
112 TickSampleEventRecord record;
113 ticks_from_vm_buffer_.Dequeue(&record);
115 return OneSampleProcessed;
118 const TickSampleEventRecord* record = ticks_buffer_.Peek();
119 if (record ==
NULL) {
120 if (ticks_from_vm_buffer_.IsEmpty())
return NoSamplesInQueue;
121 return FoundSampleForNextCodeEvent;
123 if (record->order != last_processed_code_event_id_) {
124 return FoundSampleForNextCodeEvent;
127 ticks_buffer_.Remove();
128 return OneSampleProcessed;
138 if (FoundSampleForNextCodeEvent == ProcessOneSample()) {
143 }
while (!timer.HasExpired(period_));
151 SampleProcessingResult result;
153 result = ProcessOneSample();
154 }
while (result == OneSampleProcessed);
155 }
while (ProcessCodeEvent());
159 void* ProfilerEventsProcessor::operator
new(
size_t size) {
164 void ProfilerEventsProcessor::operator
delete(
void* ptr) {
171 return profiles_->
profiles()->length();
176 return profiles_->
profiles()->at(index);
181 if (is_profiling_) StopProcessor();
189 if (profiles_->
profiles()->is_empty() && !is_profiling_) {
197 return FLAG_prof_browser_mode
198 && (tag != Logger::CALLBACK_TAG
199 && tag != Logger::FUNCTION_TAG
200 && tag != Logger::LAZY_COMPILE_TAG
201 && tag != Logger::REG_EXP_TAG
202 && tag != Logger::SCRIPT_TAG);
207 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG))
return;
210 rec->
start = entry_point;
212 Logger::CALLBACK_TAG,
223 if (FilterOutCodeCreateEvent(tag))
return;
237 if (FilterOutCodeCreateEvent(tag))
return;
253 if (FilterOutCodeCreateEvent(tag))
return;
261 if (shared->script()->IsScript()) {
278 Name* source,
int line,
int column) {
279 if (FilterOutCodeCreateEvent(tag))
return;
307 if (FilterOutCodeCreateEvent(tag))
return;
313 profiles_->
GetName(args_count),
337 &evt_rec.SharedFunctionInfoMoveEventRecord_;
345 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG))
return;
348 rec->
start = entry_point;
350 Logger::CALLBACK_TAG,
360 if (FilterOutCodeCreateEvent(Logger::REG_EXP_TAG))
return;
374 if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG))
return;
377 rec->
start = entry_point;
379 Logger::CALLBACK_TAG,
390 sampling_interval_(TimeDelta::FromMicroseconds(
391 FLAG_cpu_profiler_sampling_interval)),
395 is_profiling_(
false) {
404 sampling_interval_(TimeDelta::FromMicroseconds(
405 FLAG_cpu_profiler_sampling_interval)),
406 profiles_(test_profiles),
407 generator_(test_generator),
408 processor_(test_processor),
409 is_profiling_(
false) {
421 sampling_interval_ = value;
425 void CpuProfiler::ResetProfiles() {
433 StartProcessorIfNotStarted();
444 void CpuProfiler::StartProcessorIfNotStarted() {
445 if (processor_ ==
NULL) {
448 saved_is_logging_ = logger->is_logging_;
449 logger->is_logging_ =
false;
453 generator_, sampler, sampling_interval_);
454 is_profiling_ =
true;
457 if (!FLAG_prof_browser_mode) {
472 if (!is_profiling_)
return NULL;
473 StopProcessorIfLastProfile(title);
475 if (result !=
NULL) {
483 if (!is_profiling_)
return NULL;
484 const char* profile_title = profiles_->
GetName(title);
485 StopProcessorIfLastProfile(profile_title);
490 void CpuProfiler::StopProcessorIfLastProfile(
const char* title) {
495 void CpuProfiler::StopProcessor() {
496 Logger* logger = isolate_->
logger();
497 Sampler* sampler =
reinterpret_cast<Sampler*
>(logger->ticker_);
498 is_profiling_ =
false;
504 sampler->SetHasProcessingThread(
false);
505 sampler->DecreaseProfilingDepth();
506 logger->is_logging_ = saved_is_logging_;
510 void CpuProfiler::LogBuiltins() {
511 Builtins* builtins = isolate_->
builtins();
512 ASSERT(builtins->is_initialized());
514 CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN);
515 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
517 rec->start = builtins->builtin(
id)->address();
518 rec->builtin_id = id;
void StartProfiling(const char *title, bool record_samples=false)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
void DeleteProfile(CpuProfile *profile)
bool IsLastProfile(const char *title)
virtual void CodeCreateEvent(Logger::LogEventsAndTags tag, Code *code, const char *comment)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths true
virtual void CodeDeleteEvent(Address from)
void AddCurrentStack(Isolate *isolate)
ProfilerEventsProcessor(ProfileGenerator *generator, Sampler *sampler, TimeDelta period)
void set_bailout_reason(const char *bailout_reason)
void LogCompiledFunctions()
CpuProfile * StopProfiling(const char *title)
#define CODE_EVENTS_TYPE_LIST(V)
#define ASSERT(condition)
static Script * cast(Object *obj)
const char * GetName(Name *name)
void set_no_frame_ranges(List< OffsetRange > *ranges)
virtual void SetterCallbackEvent(Name *name, Address entry_point)
HANDLE HANDLE LPSTACKFRAME64 StackFrame
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
void IncreaseProfilingDepth()
void RecordTickSample(const TickSample &sample)
StackFrame * frame() const
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
virtual void GetterCallbackEvent(Name *name, Address entry_point)
bool StartProfiling(const char *title, bool record_samples)
void Enqueue(const CodeEventsContainer &event)
Isolate * isolate() const
void RemoveProfile(CpuProfile *profile)
void StartSynchronously()
BailoutReason DisableOptimizationReason()
virtual void SharedFunctionInfoMoveEvent(Address from, Address to)
void AlignedFree(void *ptr)
void SetHasProcessingThread(bool value)
const char * GetBailoutReason(BailoutReason reason)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
void * AlignedAlloc(size_t size, size_t alignment)
CpuProfile * GetProfile(int index)
List< CpuProfile * > * profiles()
static const char *const kEmptyNamePrefix
const char * GetFunctionName(Name *name)
CpuProfiler(Isolate *isolate)
void set_sampling_interval(TimeDelta value)
void Init(Isolate *isolate, const RegisterState &state)
CodeEntry * NewCodeEntry(Logger::LogEventsAndTags tag, const char *name, const char *name_prefix=CodeEntry::kEmptyNamePrefix, const char *resource_name=CodeEntry::kEmptyResourceName, int line_number=v8::CpuProfileNode::kNoLineNumberInfo, int column_number=v8::CpuProfileNode::kNoColumnNumberInfo)
void LogAccessorCallbacks()
List< OffsetRange > * ReleaseNoFrameRanges()
virtual void RegExpCodeCreateEvent(Code *code, String *source)
CpuProfile * StopProfiling(const char *title)
#define PROFILER_TYPE_CASE(type, clss)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
virtual void CallbackEvent(Name *name, Address entry_point)
virtual void CodeMoveEvent(Address from, Address to)
void set_script_id(int script_id)