2012-02-07 08:00:36 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/cpu-profiler-inl.h"
|
2010-03-19 09:46:53 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/compiler.h"
|
2015-02-10 14:32:42 +00:00
|
|
|
#include "src/deoptimizer.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/frames-inl.h"
|
|
|
|
#include "src/hashmap.h"
|
|
|
|
#include "src/log-inl.h"
|
|
|
|
#include "src/vm-state-inl.h"
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "include/v8-profiler.h"
|
2010-04-06 14:54:20 +00:00
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2012-02-07 08:00:36 +00:00
|
|
|
static const int kProfilerStackSize = 64 * KB;
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
|
2014-10-07 14:45:17 +00:00
|
|
|
ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator,
|
|
|
|
Sampler* sampler,
|
|
|
|
base::TimeDelta period)
|
2012-01-24 15:48:16 +00:00
|
|
|
: Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
|
2011-01-04 09:09:50 +00:00
|
|
|
generator_(generator),
|
2013-08-26 07:17:12 +00:00
|
|
|
sampler_(sampler),
|
2014-10-07 14:45:17 +00:00
|
|
|
running_(1),
|
2013-08-29 09:15:13 +00:00
|
|
|
period_(period),
|
2014-10-07 14:45:17 +00:00
|
|
|
last_code_event_id_(0),
|
|
|
|
last_processed_code_event_id_(0) {}
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
|
2013-07-01 10:12:03 +00:00
|
|
|
void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {
|
2013-07-07 11:42:30 +00:00
|
|
|
event.generic.order = ++last_code_event_id_;
|
2013-07-01 10:12:03 +00:00
|
|
|
events_buffer_.Enqueue(event);
|
2010-04-06 14:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-10 14:32:42 +00:00
|
|
|
void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from,
|
|
|
|
int fp_to_sp_delta) {
|
|
|
|
TickSampleEventRecord record(last_code_event_id_);
|
|
|
|
RegisterState regs;
|
|
|
|
Address fp = isolate->c_entry_fp(isolate->thread_local_top());
|
|
|
|
regs.sp = fp - fp_to_sp_delta;
|
|
|
|
regs.fp = fp;
|
|
|
|
regs.pc = from;
|
|
|
|
record.sample.Init(isolate, regs, TickSample::kSkipCEntryFrame);
|
|
|
|
ticks_from_vm_buffer_.Enqueue(record);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-02 15:44:30 +00:00
|
|
|
void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate) {
|
2013-07-07 11:42:30 +00:00
|
|
|
TickSampleEventRecord record(last_code_event_id_);
|
2013-10-10 13:03:41 +00:00
|
|
|
RegisterState regs;
|
|
|
|
StackFrameIterator it(isolate);
|
|
|
|
if (!it.done()) {
|
|
|
|
StackFrame* frame = it.frame();
|
|
|
|
regs.sp = frame->sp();
|
|
|
|
regs.fp = frame->fp();
|
|
|
|
regs.pc = frame->pc();
|
2010-06-01 13:52:49 +00:00
|
|
|
}
|
2014-10-17 15:44:02 +00:00
|
|
|
record.sample.Init(isolate, regs, TickSample::kSkipCEntryFrame);
|
2010-06-01 13:52:49 +00:00
|
|
|
ticks_from_vm_buffer_.Enqueue(record);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-07 11:42:30 +00:00
|
|
|
void ProfilerEventsProcessor::StopSynchronously() {
|
2014-10-07 14:45:17 +00:00
|
|
|
if (!base::NoBarrier_AtomicExchange(&running_, 0)) return;
|
2013-07-07 11:42:30 +00:00
|
|
|
Join();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ProfilerEventsProcessor::ProcessCodeEvent() {
|
2013-06-20 06:23:34 +00:00
|
|
|
CodeEventsContainer record;
|
|
|
|
if (events_buffer_.Dequeue(&record)) {
|
2010-03-19 09:46:53 +00:00
|
|
|
switch (record.generic.type) {
|
|
|
|
#define PROFILER_TYPE_CASE(type, clss) \
|
|
|
|
case CodeEventRecord::type: \
|
|
|
|
record.clss##_.UpdateCodeMap(generator_->code_map()); \
|
|
|
|
break;
|
|
|
|
|
|
|
|
CODE_EVENTS_TYPE_LIST(PROFILER_TYPE_CASE)
|
|
|
|
|
|
|
|
#undef PROFILER_TYPE_CASE
|
|
|
|
default: return true; // Skip record.
|
|
|
|
}
|
2013-07-07 11:42:30 +00:00
|
|
|
last_processed_code_event_id_ = record.generic.order;
|
2010-03-19 09:46:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-06 06:25:06 +00:00
|
|
|
ProfilerEventsProcessor::SampleProcessingResult
|
|
|
|
ProfilerEventsProcessor::ProcessOneSample() {
|
|
|
|
if (!ticks_from_vm_buffer_.IsEmpty()
|
|
|
|
&& ticks_from_vm_buffer_.Peek()->order ==
|
|
|
|
last_processed_code_event_id_) {
|
|
|
|
TickSampleEventRecord record;
|
|
|
|
ticks_from_vm_buffer_.Dequeue(&record);
|
|
|
|
generator_->RecordTickSample(record.sample);
|
|
|
|
return OneSampleProcessed;
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
2012-10-02 09:58:11 +00:00
|
|
|
|
2013-09-06 06:25:06 +00:00
|
|
|
const TickSampleEventRecord* record = ticks_buffer_.Peek();
|
|
|
|
if (record == NULL) {
|
|
|
|
if (ticks_from_vm_buffer_.IsEmpty()) return NoSamplesInQueue;
|
|
|
|
return FoundSampleForNextCodeEvent;
|
|
|
|
}
|
|
|
|
if (record->order != last_processed_code_event_id_) {
|
|
|
|
return FoundSampleForNextCodeEvent;
|
2013-09-05 12:17:17 +00:00
|
|
|
}
|
2013-09-06 06:25:06 +00:00
|
|
|
generator_->RecordTickSample(record->sample);
|
|
|
|
ticks_buffer_.Remove();
|
|
|
|
return OneSampleProcessed;
|
2013-08-26 07:17:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::Run() {
|
2014-10-07 14:45:17 +00:00
|
|
|
while (!!base::NoBarrier_Load(&running_)) {
|
2015-05-04 22:53:22 +00:00
|
|
|
base::TimeTicks nextSampleTime =
|
|
|
|
base::TimeTicks::HighResolutionNow() + period_;
|
|
|
|
base::TimeTicks now;
|
|
|
|
SampleProcessingResult result;
|
|
|
|
// Keep processing existing events until we need to do next sample
|
|
|
|
// or the ticks buffer is empty.
|
2013-09-06 06:25:06 +00:00
|
|
|
do {
|
2015-05-04 22:53:22 +00:00
|
|
|
result = ProcessOneSample();
|
|
|
|
if (result == FoundSampleForNextCodeEvent) {
|
2013-09-06 06:25:06 +00:00
|
|
|
// All ticks of the current last_processed_code_event_id_ are
|
|
|
|
// processed, proceed to the next code event.
|
|
|
|
ProcessCodeEvent();
|
|
|
|
}
|
2015-05-04 22:53:22 +00:00
|
|
|
now = base::TimeTicks::HighResolutionNow();
|
|
|
|
} while (result != NoSamplesInQueue && now < nextSampleTime);
|
|
|
|
|
|
|
|
if (nextSampleTime > now) {
|
|
|
|
#if V8_OS_WIN
|
|
|
|
// Do not use Sleep on Windows as it is very imprecise.
|
|
|
|
// Could be up to 16ms jitter, which is unacceptable for the purpose.
|
|
|
|
while (base::TimeTicks::HighResolutionNow() < nextSampleTime) {
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
base::OS::Sleep(nextSampleTime - now);
|
|
|
|
#endif
|
|
|
|
}
|
2013-09-06 06:25:06 +00:00
|
|
|
|
|
|
|
// Schedule next sample. sampler_ is NULL in tests.
|
|
|
|
if (sampler_) sampler_->DoSample();
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
// Process remaining tick events.
|
2013-07-07 11:42:30 +00:00
|
|
|
do {
|
2013-09-06 06:25:06 +00:00
|
|
|
SampleProcessingResult result;
|
|
|
|
do {
|
|
|
|
result = ProcessOneSample();
|
|
|
|
} while (result == OneSampleProcessed);
|
2013-07-07 11:42:30 +00:00
|
|
|
} while (ProcessCodeEvent());
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2014-01-10 10:39:47 +00:00
|
|
|
void* ProfilerEventsProcessor::operator new(size_t size) {
|
|
|
|
return AlignedAlloc(size, V8_ALIGNOF(ProfilerEventsProcessor));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::operator delete(void* ptr) {
|
|
|
|
AlignedFree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
int CpuProfiler::GetProfilesCount() {
|
2010-05-18 14:19:33 +00:00
|
|
|
// The count of profiles doesn't depend on a security token.
|
2013-07-06 09:12:09 +00:00
|
|
|
return profiles_->profiles()->length();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-06 09:12:09 +00:00
|
|
|
CpuProfile* CpuProfiler::GetProfile(int index) {
|
|
|
|
return profiles_->profiles()->at(index);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void CpuProfiler::DeleteAllProfiles() {
|
2013-04-02 07:53:50 +00:00
|
|
|
if (is_profiling_) StopProcessor();
|
|
|
|
ResetProfiles();
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::DeleteProfile(CpuProfile* profile) {
|
2013-04-02 07:53:50 +00:00
|
|
|
profiles_->RemoveProfile(profile);
|
2011-03-22 16:10:01 +00:00
|
|
|
delete profile;
|
2013-12-11 14:39:18 +00:00
|
|
|
if (profiles_->profiles()->is_empty() && !is_profiling_) {
|
|
|
|
// If this was the last profile, clean up all accessory data as well.
|
|
|
|
ResetProfiles();
|
|
|
|
}
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-01 10:12:03 +00:00
|
|
|
static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag) {
|
|
|
|
return FLAG_prof_browser_mode
|
|
|
|
&& (tag != Logger::CALLBACK_TAG
|
|
|
|
&& tag != Logger::FUNCTION_TAG
|
|
|
|
&& tag != Logger::LAZY_COMPILE_TAG
|
|
|
|
&& tag != Logger::REG_EXP_TAG
|
|
|
|
&& tag != Logger::SCRIPT_TAG);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void CpuProfiler::CallbackEvent(Name* name, Address entry_point) {
|
2013-07-01 10:12:03 +00:00
|
|
|
if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = entry_point;
|
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
|
|
|
Logger::CALLBACK_TAG,
|
2013-07-06 09:12:09 +00:00
|
|
|
profiles_->GetName(name));
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = 1;
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
2013-07-01 10:12:03 +00:00
|
|
|
Code* code,
|
|
|
|
const char* name) {
|
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = code->address();
|
2014-11-06 09:16:34 +00:00
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
|
|
|
tag, profiles_->GetFunctionName(name), CodeEntry::kEmptyNamePrefix,
|
|
|
|
CodeEntry::kEmptyResourceName, CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
CpuProfileNode::kNoColumnNumberInfo, NULL, code->instruction_start());
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
2013-07-01 10:12:03 +00:00
|
|
|
Code* code,
|
|
|
|
Name* name) {
|
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = code->address();
|
2014-11-06 09:16:34 +00:00
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
|
|
|
tag, profiles_->GetFunctionName(name), CodeEntry::kEmptyNamePrefix,
|
|
|
|
CodeEntry::kEmptyResourceName, CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
CpuProfileNode::kNoColumnNumberInfo, NULL, code->instruction_start());
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-05 07:31:17 +00:00
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code,
|
2011-02-22 16:31:24 +00:00
|
|
|
SharedFunctionInfo* shared,
|
2014-08-05 07:31:17 +00:00
|
|
|
CompilationInfo* info, Name* script_name) {
|
2013-07-01 10:12:03 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = code->address();
|
2014-08-05 07:31:17 +00:00
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
|
|
|
tag, profiles_->GetFunctionName(shared->DebugName()),
|
2014-11-06 09:16:34 +00:00
|
|
|
CodeEntry::kEmptyNamePrefix, profiles_->GetName(script_name),
|
|
|
|
CpuProfileNode::kNoLineNumberInfo, CpuProfileNode::kNoColumnNumberInfo,
|
|
|
|
NULL, code->instruction_start());
|
2013-07-02 06:14:01 +00:00
|
|
|
if (info) {
|
|
|
|
rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
|
2015-03-24 12:46:13 +00:00
|
|
|
rec->entry->set_inlined_function_infos(info->inlined_function_infos());
|
2013-07-02 06:14:01 +00:00
|
|
|
}
|
2015-02-20 13:28:42 +00:00
|
|
|
rec->entry->FillFunctionInfo(shared);
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2011-02-22 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-05 07:31:17 +00:00
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code,
|
2011-02-22 16:31:24 +00:00
|
|
|
SharedFunctionInfo* shared,
|
2014-08-05 07:31:17 +00:00
|
|
|
CompilationInfo* info, Name* script_name,
|
|
|
|
int line, int column) {
|
2013-07-01 10:12:03 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = code->address();
|
2014-11-06 09:16:34 +00:00
|
|
|
Script* script = Script::cast(shared->script());
|
|
|
|
JITLineInfoTable* line_table = NULL;
|
|
|
|
if (script) {
|
|
|
|
line_table = new JITLineInfoTable();
|
|
|
|
for (RelocIterator it(code); !it.done(); it.next()) {
|
|
|
|
RelocInfo::Mode mode = it.rinfo()->rmode();
|
|
|
|
if (RelocInfo::IsPosition(mode)) {
|
|
|
|
int position = static_cast<int>(it.rinfo()->data());
|
|
|
|
if (position >= 0) {
|
|
|
|
int pc_offset = static_cast<int>(it.rinfo()->pc() - code->address());
|
2015-04-01 10:11:13 +00:00
|
|
|
int line_number = script->GetLineNumber(position) + 1;
|
|
|
|
line_table->SetPosition(pc_offset, line_number);
|
2014-11-06 09:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
2014-08-05 07:31:17 +00:00
|
|
|
tag, profiles_->GetFunctionName(shared->DebugName()),
|
|
|
|
CodeEntry::kEmptyNamePrefix, profiles_->GetName(script_name), line,
|
2014-11-06 09:16:34 +00:00
|
|
|
column, line_table, code->instruction_start());
|
2013-07-02 06:14:01 +00:00
|
|
|
if (info) {
|
|
|
|
rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
|
2015-03-24 12:46:13 +00:00
|
|
|
rec->entry->set_inlined_function_infos(info->inlined_function_infos());
|
2013-07-02 06:14:01 +00:00
|
|
|
}
|
2015-02-20 13:28:42 +00:00
|
|
|
rec->entry->FillFunctionInfo(shared);
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
2013-07-01 10:12:03 +00:00
|
|
|
Code* code,
|
|
|
|
int args_count) {
|
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = code->address();
|
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
2014-11-06 09:16:34 +00:00
|
|
|
tag, profiles_->GetName(args_count), "args_count: ",
|
|
|
|
CodeEntry::kEmptyResourceName, CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
CpuProfileNode::kNoColumnNumberInfo, NULL, code->instruction_start());
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeMoveEvent(Address from, Address to) {
|
2013-07-01 10:12:03 +00:00
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_MOVE);
|
|
|
|
CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_;
|
|
|
|
rec->from = from;
|
|
|
|
rec->to = to;
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-22 05:36:27 +00:00
|
|
|
void CpuProfiler::CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) {
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_DISABLE_OPT);
|
|
|
|
CodeDisableOptEventRecord* rec = &evt_rec.CodeDisableOptEventRecord_;
|
|
|
|
rec->start = code->address();
|
2014-11-13 09:55:48 +00:00
|
|
|
rec->bailout_reason = GetBailoutReason(shared->disable_optimization_reason());
|
2014-05-22 05:36:27 +00:00
|
|
|
processor_->Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-09 14:43:29 +00:00
|
|
|
void CpuProfiler::CodeDeoptEvent(Code* code, Address pc, int fp_to_sp_delta) {
|
2015-02-10 14:32:42 +00:00
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_DEOPT);
|
|
|
|
CodeDeoptEventRecord* rec = &evt_rec.CodeDeoptEventRecord_;
|
2015-03-09 14:43:29 +00:00
|
|
|
Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(code, pc);
|
2015-02-10 14:32:42 +00:00
|
|
|
rec->start = code->address();
|
|
|
|
rec->deopt_reason = Deoptimizer::GetDeoptReason(info.deopt_reason);
|
2015-02-27 13:34:23 +00:00
|
|
|
rec->position = info.position;
|
2015-03-17 18:50:02 +00:00
|
|
|
rec->pc_offset = pc - code->instruction_start();
|
2015-02-10 14:32:42 +00:00
|
|
|
processor_->Enqueue(evt_rec);
|
|
|
|
processor_->AddDeoptStack(isolate_, pc, fp_to_sp_delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
void CpuProfiler::CodeDeleteEvent(Address from) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) {
|
2013-07-01 10:12:03 +00:00
|
|
|
if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = entry_point;
|
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
|
|
|
Logger::CALLBACK_TAG,
|
|
|
|
profiles_->GetName(name),
|
|
|
|
"get ");
|
|
|
|
rec->size = 1;
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
|
2013-07-01 10:12:03 +00:00
|
|
|
if (FilterOutCodeCreateEvent(Logger::REG_EXP_TAG)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = code->address();
|
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
2014-11-06 09:16:34 +00:00
|
|
|
Logger::REG_EXP_TAG, profiles_->GetName(source), "RegExp: ",
|
|
|
|
CodeEntry::kEmptyResourceName, CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
CpuProfileNode::kNoColumnNumberInfo, NULL, code->instruction_start());
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {
|
2013-07-01 10:12:03 +00:00
|
|
|
if (FilterOutCodeCreateEvent(Logger::CALLBACK_TAG)) return;
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->start = entry_point;
|
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
|
|
|
Logger::CALLBACK_TAG,
|
|
|
|
profiles_->GetName(name),
|
|
|
|
"set ");
|
|
|
|
rec->size = 1;
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:53:50 +00:00
|
|
|
CpuProfiler::CpuProfiler(Isolate* isolate)
|
|
|
|
: isolate_(isolate),
|
2014-06-30 13:25:46 +00:00
|
|
|
sampling_interval_(base::TimeDelta::FromMicroseconds(
|
2013-09-04 11:55:28 +00:00
|
|
|
FLAG_cpu_profiler_sampling_interval)),
|
2013-09-11 07:14:41 +00:00
|
|
|
profiles_(new CpuProfilesCollection(isolate->heap())),
|
2010-04-06 10:36:38 +00:00
|
|
|
generator_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
processor_(NULL),
|
2013-07-01 10:12:03 +00:00
|
|
|
is_profiling_(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfiler::CpuProfiler(Isolate* isolate,
|
|
|
|
CpuProfilesCollection* test_profiles,
|
|
|
|
ProfileGenerator* test_generator,
|
|
|
|
ProfilerEventsProcessor* test_processor)
|
|
|
|
: isolate_(isolate),
|
2014-06-30 13:25:46 +00:00
|
|
|
sampling_interval_(base::TimeDelta::FromMicroseconds(
|
2013-09-04 11:55:28 +00:00
|
|
|
FLAG_cpu_profiler_sampling_interval)),
|
2013-07-01 10:12:03 +00:00
|
|
|
profiles_(test_profiles),
|
|
|
|
generator_(test_generator),
|
|
|
|
processor_(test_processor),
|
2011-03-18 20:35:07 +00:00
|
|
|
is_profiling_(false) {
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfiler::~CpuProfiler() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!is_profiling_);
|
2010-04-06 10:36:38 +00:00
|
|
|
delete profiles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-30 13:25:46 +00:00
|
|
|
void CpuProfiler::set_sampling_interval(base::TimeDelta value) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!is_profiling_);
|
2013-09-04 11:55:28 +00:00
|
|
|
sampling_interval_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void CpuProfiler::ResetProfiles() {
|
|
|
|
delete profiles_;
|
2013-09-11 07:14:41 +00:00
|
|
|
profiles_ = new CpuProfilesCollection(isolate()->heap());
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-04-02 07:53:50 +00:00
|
|
|
void CpuProfiler::StartProfiling(const char* title, bool record_samples) {
|
2013-12-18 08:59:09 +00:00
|
|
|
if (profiles_->StartProfiling(title, record_samples)) {
|
2010-04-06 10:36:38 +00:00
|
|
|
StartProcessorIfNotStarted();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:53:50 +00:00
|
|
|
void CpuProfiler::StartProfiling(String* title, bool record_samples) {
|
|
|
|
StartProfiling(profiles_->GetName(title), record_samples);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::StartProcessorIfNotStarted() {
|
2014-05-06 08:18:09 +00:00
|
|
|
if (processor_ != NULL) {
|
2014-04-25 18:53:06 +00:00
|
|
|
processor_->AddCurrentStack(isolate_);
|
2014-05-06 08:18:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Logger* logger = isolate_->logger();
|
|
|
|
// Disable logging when using the new implementation.
|
|
|
|
saved_is_logging_ = logger->is_logging_;
|
|
|
|
logger->is_logging_ = false;
|
|
|
|
generator_ = new ProfileGenerator(profiles_);
|
|
|
|
Sampler* sampler = logger->sampler();
|
|
|
|
processor_ = new ProfilerEventsProcessor(
|
|
|
|
generator_, sampler, sampling_interval_);
|
|
|
|
is_profiling_ = true;
|
|
|
|
// Enumerate stuff we already have in the heap.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate_->heap()->HasBeenSetUp());
|
2014-05-06 08:18:09 +00:00
|
|
|
if (!FLAG_prof_browser_mode) {
|
|
|
|
logger->LogCodeObjects();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
2014-05-06 08:18:09 +00:00
|
|
|
logger->LogCompiledFunctions();
|
|
|
|
logger->LogAccessorCallbacks();
|
|
|
|
LogBuiltins();
|
|
|
|
// Enable stack sampling.
|
|
|
|
sampler->SetHasProcessingThread(true);
|
|
|
|
sampler->IncreaseProfilingDepth();
|
|
|
|
processor_->AddCurrentStack(isolate_);
|
|
|
|
processor_->StartSynchronously();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:53:50 +00:00
|
|
|
CpuProfile* CpuProfiler::StopProfiling(const char* title) {
|
|
|
|
if (!is_profiling_) return NULL;
|
2010-08-10 12:06:42 +00:00
|
|
|
StopProcessorIfLastProfile(title);
|
2013-07-30 07:01:16 +00:00
|
|
|
CpuProfile* result = profiles_->StopProfiling(title);
|
2010-04-06 10:36:38 +00:00
|
|
|
if (result != NULL) {
|
|
|
|
result->Print();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-06 09:12:09 +00:00
|
|
|
CpuProfile* CpuProfiler::StopProfiling(String* title) {
|
2013-04-02 07:53:50 +00:00
|
|
|
if (!is_profiling_) return NULL;
|
2010-08-10 12:06:42 +00:00
|
|
|
const char* profile_title = profiles_->GetName(title);
|
|
|
|
StopProcessorIfLastProfile(profile_title);
|
2013-07-30 07:01:16 +00:00
|
|
|
return profiles_->StopProfiling(profile_title);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-10 12:06:42 +00:00
|
|
|
void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
|
2011-03-22 16:10:01 +00:00
|
|
|
if (profiles_->IsLastProfile(title)) StopProcessor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::StopProcessor() {
|
2013-04-02 07:53:50 +00:00
|
|
|
Logger* logger = isolate_->logger();
|
2012-11-30 10:26:21 +00:00
|
|
|
Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_);
|
2013-02-26 12:27:55 +00:00
|
|
|
is_profiling_ = false;
|
2013-07-07 11:42:30 +00:00
|
|
|
processor_->StopSynchronously();
|
2011-03-22 16:10:01 +00:00
|
|
|
delete processor_;
|
|
|
|
delete generator_;
|
|
|
|
processor_ = NULL;
|
|
|
|
generator_ = NULL;
|
2013-08-29 14:03:38 +00:00
|
|
|
sampler->SetHasProcessingThread(false);
|
|
|
|
sampler->DecreaseProfilingDepth();
|
2013-08-29 10:42:55 +00:00
|
|
|
logger->is_logging_ = saved_is_logging_;
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-02 07:51:09 +00:00
|
|
|
void CpuProfiler::LogBuiltins() {
|
|
|
|
Builtins* builtins = isolate_->builtins();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(builtins->is_initialized());
|
2013-07-02 07:51:09 +00:00
|
|
|
for (int i = 0; i < Builtins::builtin_count; i++) {
|
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::REPORT_BUILTIN);
|
|
|
|
ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
|
|
|
|
Builtins::Name id = static_cast<Builtins::Name>(i);
|
|
|
|
rec->start = builtins->builtin(id)->address();
|
|
|
|
rec->builtin_id = id;
|
|
|
|
processor_->Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-01 22:46:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|