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-11-30 10:26:21 +00:00
|
|
|
static const int kTickSamplesBufferChunkSize = 64 * KB;
|
|
|
|
static const int kTickSamplesBufferChunksCount = 16;
|
2012-02-07 08:00:36 +00:00
|
|
|
static const int kProfilerStackSize = 64 * KB;
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
|
2013-07-01 12:24:26 +00:00
|
|
|
ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
|
2012-01-24 15:48:16 +00:00
|
|
|
: Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
|
2011-01-04 09:09:50 +00:00
|
|
|
generator_(generator),
|
2010-08-18 15:36:00 +00:00
|
|
|
running_(true),
|
2012-11-30 10:26:21 +00:00
|
|
|
ticks_buffer_(sizeof(TickSampleEventRecord),
|
|
|
|
kTickSamplesBufferChunkSize,
|
2013-03-07 09:12:48 +00:00
|
|
|
kTickSamplesBufferChunksCount),
|
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_);
|
2010-06-01 13:52:49 +00:00
|
|
|
TickSample* sample = &record.sample;
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
sample->state = isolate->current_vm_state();
|
2010-06-01 13:52:49 +00:00
|
|
|
sample->pc = reinterpret_cast<Address>(sample); // Not NULL.
|
Simplify isolates access during stack iteration (WAS: Move SafeStackFrameIterator::active_count_...)
While trying to fix Mac and Windows versions for this change:
http://codereview.chromium.org/6771047/, I figured out, that we
already store an isolate in StackFrameIterator, so we can use it in
frame objects, instead of requiring it from caller.
I've changed iterators usage to the following scheme: whenever a
caller maintains an isolate pointer, it just passes it to stack
iterator, and no more worries about passing it to frame content
accessors. If a caller uses current isolate, it can omit passing it
to iterator, in this case, an iterator will use the current isolate,
too.
There was a special case with LiveEdit, which creates
detached copies of frame objects.
R=vitalyr@chromium.org
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6794019
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7499 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-04-05 09:01:47 +00:00
|
|
|
for (StackTraceFrameIterator it(isolate);
|
2010-06-01 13:52:49 +00:00
|
|
|
!it.done() && sample->frames_count < TickSample::kMaxFramesCount;
|
|
|
|
it.Advance()) {
|
2011-02-22 16:31:24 +00:00
|
|
|
sample->stack[sample->frames_count++] = it.frame()->pc();
|
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-07-07 11:42:30 +00:00
|
|
|
bool ProfilerEventsProcessor::ProcessTicks() {
|
2012-10-02 10:51:00 +00:00
|
|
|
while (true) {
|
2010-06-01 13:52:49 +00:00
|
|
|
if (!ticks_from_vm_buffer_.IsEmpty()
|
2013-07-07 11:42:30 +00:00
|
|
|
&& ticks_from_vm_buffer_.Peek()->order ==
|
|
|
|
last_processed_code_event_id_) {
|
2010-06-01 13:52:49 +00:00
|
|
|
TickSampleEventRecord record;
|
|
|
|
ticks_from_vm_buffer_.Dequeue(&record);
|
|
|
|
generator_->RecordTickSample(record.sample);
|
|
|
|
}
|
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
const TickSampleEventRecord* rec =
|
|
|
|
TickSampleEventRecord::cast(ticks_buffer_.StartDequeue());
|
|
|
|
if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty();
|
|
|
|
// Make a local copy of tick sample record to ensure that it won't
|
|
|
|
// be modified as we are processing it. This is possible as the
|
|
|
|
// sampler writes w/o any sync to the queue, so if the processor
|
|
|
|
// will get far behind, a record may be modified right under its
|
|
|
|
// feet.
|
|
|
|
TickSampleEventRecord record = *rec;
|
2013-07-07 11:42:30 +00:00
|
|
|
if (record.order != last_processed_code_event_id_) return true;
|
|
|
|
|
|
|
|
// A paranoid check to make sure that we don't get a memory overrun
|
|
|
|
// in case of frames_count having a wild value.
|
|
|
|
if (record.sample.frames_count < 0
|
|
|
|
|| record.sample.frames_count > TickSample::kMaxFramesCount)
|
|
|
|
record.sample.frames_count = 0;
|
|
|
|
generator_->RecordTickSample(record.sample);
|
|
|
|
ticks_buffer_.FinishDequeue();
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
2012-10-02 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
void ProfilerEventsProcessor::Run() {
|
|
|
|
while (running_) {
|
2013-03-07 09:12:48 +00:00
|
|
|
// Process ticks until we have any.
|
2013-07-07 11:42:30 +00:00
|
|
|
if (ProcessTicks()) {
|
|
|
|
// All ticks of the current last_processed_code_event_id_ are processed,
|
2013-03-07 09:12:48 +00:00
|
|
|
// proceed to the next code event.
|
2013-07-07 11:42:30 +00:00
|
|
|
ProcessCodeEvent();
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
2013-03-07 09:12:48 +00:00
|
|
|
YieldCPU();
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 10:26:21 +00:00
|
|
|
// Process remaining tick events.
|
|
|
|
ticks_buffer_.FlushResidualRecords();
|
2013-07-07 11:42:30 +00:00
|
|
|
do {
|
|
|
|
ProcessTicks();
|
|
|
|
} while (ProcessCodeEvent());
|
2010-03-19 09:46:53 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 07:53:50 +00:00
|
|
|
TickSample* CpuProfiler::TickSampleEvent() {
|
|
|
|
if (is_profiling_) return processor_->TickSampleEvent();
|
|
|
|
return NULL;
|
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-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-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-07-23 08:12:15 +00:00
|
|
|
Name* source, int line) {
|
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),
|
|
|
|
line);
|
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();
|
|
|
|
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),
|
|
|
|
profiles_(new CpuProfilesCollection()),
|
2010-04-06 10:36:38 +00:00
|
|
|
next_profile_uid_(1),
|
|
|
|
generator_(NULL),
|
2011-03-18 20:35:07 +00:00
|
|
|
processor_(NULL),
|
2011-03-21 17:40:40 +00:00
|
|
|
need_to_stop_sampler_(false),
|
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),
|
|
|
|
profiles_(test_profiles),
|
|
|
|
next_profile_uid_(1),
|
|
|
|
generator_(test_generator),
|
|
|
|
processor_(test_processor),
|
|
|
|
need_to_stop_sampler_(false),
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void CpuProfiler::ResetProfiles() {
|
|
|
|
delete profiles_;
|
|
|
|
profiles_ = new CpuProfilesCollection();
|
|
|
|
}
|
|
|
|
|
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-04-02 07:48:25 +00:00
|
|
|
if (profiles_->StartProfiling(title, next_profile_uid_++, 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-07-01 12:32:52 +00:00
|
|
|
saved_logging_nesting_ = logger->logging_nesting_;
|
|
|
|
logger->logging_nesting_ = 0;
|
2010-04-06 10:36:38 +00:00
|
|
|
generator_ = new ProfileGenerator(profiles_);
|
2013-07-01 12:24:26 +00:00
|
|
|
processor_ = new ProfilerEventsProcessor(generator_);
|
2013-02-26 12:27:55 +00:00
|
|
|
is_profiling_ = true;
|
2013-04-10 09:47:44 +00:00
|
|
|
processor_->StartSynchronously();
|
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-07-01 12:32:52 +00:00
|
|
|
Sampler* sampler = logger->sampler();
|
2013-04-10 09:47:44 +00:00
|
|
|
sampler->IncreaseProfilingDepth();
|
2011-03-21 17:40:40 +00:00
|
|
|
if (!sampler->IsActive()) {
|
|
|
|
sampler->Start();
|
|
|
|
need_to_stop_sampler_ = true;
|
|
|
|
}
|
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-04-15 11:37:29 +00:00
|
|
|
const double actual_sampling_rate = generator_->actual_sampling_rate();
|
2010-08-10 12:06:42 +00:00
|
|
|
StopProcessorIfLastProfile(title);
|
2013-07-06 09:12:09 +00:00
|
|
|
CpuProfile* result = profiles_->StopProfiling(title, actual_sampling_rate);
|
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-04-15 11:37:29 +00:00
|
|
|
const double actual_sampling_rate = generator_->actual_sampling_rate();
|
2010-08-10 12:06:42 +00:00
|
|
|
const char* profile_title = profiles_->GetName(title);
|
|
|
|
StopProcessorIfLastProfile(profile_title);
|
2013-07-06 09:12:09 +00:00
|
|
|
return profiles_->StopProfiling(profile_title, actual_sampling_rate);
|
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_);
|
2011-03-22 16:10:01 +00:00
|
|
|
sampler->DecreaseProfilingDepth();
|
|
|
|
if (need_to_stop_sampler_) {
|
|
|
|
sampler->Stop();
|
|
|
|
need_to_stop_sampler_ = false;
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
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;
|
2011-03-29 13:41:06 +00:00
|
|
|
logger->logging_nesting_ = saved_logging_nesting_;
|
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
|