2012-02-07 08:00:36 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2010-03-19 09:46:53 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "cpu-profiler-inl.h"
|
|
|
|
|
2013-05-14 22:51:33 +00:00
|
|
|
#include "compiler.h"
|
2010-06-01 13:52:49 +00:00
|
|
|
#include "frames-inl.h"
|
2010-09-24 11:45:12 +00:00
|
|
|
#include "hashmap.h"
|
2010-04-06 10:36:38 +00:00
|
|
|
#include "log-inl.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "vm-state-inl.h"
|
2010-04-06 10:36:38 +00:00
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
#include "../include/v8-profiler.h"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2013-08-26 07:17:12 +00:00
|
|
|
ProfilerEventsProcessor::ProfilerEventsProcessor(
|
|
|
|
ProfileGenerator* generator,
|
|
|
|
Sampler* sampler,
|
2013-08-29 09:15:13 +00:00
|
|
|
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),
|
2010-08-18 15:36:00 +00:00
|
|
|
running_(true),
|
2013-08-29 09:15:13 +00:00
|
|
|
period_(period),
|
2013-07-07 11:42:30 +00:00
|
|
|
last_code_event_id_(0), last_processed_code_event_id_(0) {
|
2010-06-01 13:52:49 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2013-10-10 13:03:41 +00:00
|
|
|
record.sample.Init(isolate, regs);
|
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() {
|
|
|
|
if (!running_) return;
|
|
|
|
running_ = false;
|
|
|
|
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() {
|
|
|
|
while (running_) {
|
2013-09-06 06:25:06 +00:00
|
|
|
ElapsedTimer timer;
|
|
|
|
timer.Start();
|
|
|
|
// Keep processing existing events until we need to do next sample.
|
|
|
|
do {
|
|
|
|
if (FoundSampleForNextCodeEvent == ProcessOneSample()) {
|
|
|
|
// All ticks of the current last_processed_code_event_id_ are
|
|
|
|
// processed, proceed to the next code event.
|
|
|
|
ProcessCodeEvent();
|
|
|
|
}
|
|
|
|
} while (!timer.HasExpired(period_));
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
rec->shared = NULL;
|
|
|
|
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();
|
|
|
|
rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
|
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
rec->shared = NULL;
|
|
|
|
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();
|
|
|
|
rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
|
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
rec->shared = NULL;
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
2011-02-22 16:31:24 +00:00
|
|
|
Code* code,
|
|
|
|
SharedFunctionInfo* shared,
|
2013-05-14 22:51:33 +00:00
|
|
|
CompilationInfo* info,
|
2013-03-04 15:00:57 +00:00
|
|
|
Name* 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();
|
|
|
|
rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
|
2013-07-02 06:14:01 +00:00
|
|
|
if (info) {
|
|
|
|
rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
|
|
|
|
}
|
|
|
|
if (shared->script()->IsScript()) {
|
|
|
|
ASSERT(Script::cast(shared->script()));
|
|
|
|
Script* script = Script::cast(shared->script());
|
|
|
|
rec->entry->set_script_id(script->id()->value());
|
2013-09-05 13:20:51 +00:00
|
|
|
rec->entry->set_bailout_reason(
|
|
|
|
GetBailoutReason(shared->DisableOptimizationReason()));
|
2013-07-02 06:14:01 +00:00
|
|
|
}
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
rec->shared = shared->address();
|
|
|
|
processor_->Enqueue(evt_rec);
|
2011-02-22 16:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
Code* code,
|
|
|
|
SharedFunctionInfo* shared,
|
2013-05-14 22:51:33 +00:00
|
|
|
CompilationInfo* info,
|
2013-10-10 13:15:47 +00:00
|
|
|
Name* source, 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();
|
|
|
|
rec->entry = profiles_->NewCodeEntry(
|
2011-02-22 16:31:24 +00:00
|
|
|
tag,
|
2013-07-01 10:12:03 +00:00
|
|
|
profiles_->GetFunctionName(shared->DebugName()),
|
|
|
|
CodeEntry::kEmptyNamePrefix,
|
|
|
|
profiles_->GetName(source),
|
2013-10-10 13:15:47 +00:00
|
|
|
line,
|
|
|
|
column);
|
2013-07-02 06:14:01 +00:00
|
|
|
if (info) {
|
|
|
|
rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
|
|
|
|
}
|
|
|
|
ASSERT(Script::cast(shared->script()));
|
|
|
|
Script* script = Script::cast(shared->script());
|
|
|
|
rec->entry->set_script_id(script->id()->value());
|
2013-07-01 10:12:03 +00:00
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
rec->shared = shared->address();
|
2013-09-05 13:20:51 +00:00
|
|
|
rec->entry->set_bailout_reason(
|
|
|
|
GetBailoutReason(shared->DisableOptimizationReason()));
|
2013-07-01 10:12:03 +00:00
|
|
|
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(
|
2010-04-06 10:36:38 +00:00
|
|
|
tag,
|
2013-07-01 10:12:03 +00:00
|
|
|
profiles_->GetName(args_count),
|
|
|
|
"args_count: ");
|
|
|
|
rec->size = code->ExecutableSize();
|
|
|
|
rec->shared = NULL;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeDeleteEvent(Address from) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 12:00:27 +00:00
|
|
|
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) {
|
2013-07-01 10:12:03 +00:00
|
|
|
CodeEventsContainer evt_rec(CodeEventRecord::SHARED_FUNC_MOVE);
|
|
|
|
SharedFunctionInfoMoveEventRecord* rec =
|
|
|
|
&evt_rec.SharedFunctionInfoMoveEventRecord_;
|
|
|
|
rec->from = from;
|
|
|
|
rec->to = to;
|
|
|
|
processor_->Enqueue(evt_rec);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
rec->shared = NULL;
|
|
|
|
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(
|
2010-04-06 10:36:38 +00:00
|
|
|
Logger::REG_EXP_TAG,
|
2013-07-01 10:12:03 +00:00
|
|
|
profiles_->GetName(source),
|
|
|
|
"RegExp: ");
|
|
|
|
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;
|
|
|
|
rec->shared = NULL;
|
|
|
|
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),
|
2013-09-04 11:55:28 +00:00
|
|
|
sampling_interval_(TimeDelta::FromMicroseconds(
|
|
|
|
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),
|
2013-09-04 11:55:28 +00:00
|
|
|
sampling_interval_(TimeDelta::FromMicroseconds(
|
|
|
|
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() {
|
2013-07-01 12:32:52 +00:00
|
|
|
ASSERT(!is_profiling_);
|
2010-04-06 10:36:38 +00:00
|
|
|
delete profiles_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-04 11:55:28 +00:00
|
|
|
void CpuProfiler::set_sampling_interval(TimeDelta value) {
|
|
|
|
ASSERT(!is_profiling_);
|
|
|
|
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-07-02 15:44:30 +00:00
|
|
|
processor_->AddCurrentStack(isolate_);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
if (processor_ == NULL) {
|
2013-07-01 12:32:52 +00:00
|
|
|
Logger* logger = isolate_->logger();
|
2010-04-12 07:23:43 +00:00
|
|
|
// Disable logging when using the new implementation.
|
2013-08-29 10:42:55 +00:00
|
|
|
saved_is_logging_ = logger->is_logging_;
|
|
|
|
logger->is_logging_ = false;
|
2010-04-06 10:36:38 +00:00
|
|
|
generator_ = new ProfileGenerator(profiles_);
|
2013-08-26 07:17:12 +00:00
|
|
|
Sampler* sampler = logger->sampler();
|
|
|
|
processor_ = new ProfilerEventsProcessor(
|
2013-09-04 11:55:28 +00:00
|
|
|
generator_, sampler, sampling_interval_);
|
2013-02-26 12:27:55 +00:00
|
|
|
is_profiling_ = true;
|
2010-04-06 10:36:38 +00:00
|
|
|
// Enumerate stuff we already have in the heap.
|
2013-07-01 12:32:52 +00:00
|
|
|
ASSERT(isolate_->heap()->HasBeenSetUp());
|
|
|
|
if (!FLAG_prof_browser_mode) {
|
|
|
|
logger->LogCodeObjects();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
2013-07-01 12:32:52 +00:00
|
|
|
logger->LogCompiledFunctions();
|
|
|
|
logger->LogAccessorCallbacks();
|
2013-07-02 07:51:09 +00:00
|
|
|
LogBuiltins();
|
2010-06-01 13:52:49 +00:00
|
|
|
// Enable stack sampling.
|
2013-08-29 14:03:38 +00:00
|
|
|
sampler->SetHasProcessingThread(true);
|
2013-04-10 09:47:44 +00:00
|
|
|
sampler->IncreaseProfilingDepth();
|
2013-08-26 11:53:29 +00:00
|
|
|
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();
|
|
|
|
ASSERT(builtins->is_initialized());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
} } // namespace v8::internal
|