2010-03-19 09:46:53 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
|
|
|
// 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"
|
|
|
|
|
2010-04-14 18:48:05 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2010-04-06 10:36:38 +00:00
|
|
|
|
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 {
|
|
|
|
|
|
|
|
static const int kEventsBufferSize = 256*KB;
|
|
|
|
static const int kTickSamplesBufferChunkSize = 64*KB;
|
|
|
|
static const int kTickSamplesBufferChunksCount = 16;
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
ProfilerEventsProcessor::ProfilerEventsProcessor(Isolate* isolate,
|
|
|
|
ProfileGenerator* generator)
|
|
|
|
: Thread(isolate, "v8:ProfEvntProc"),
|
2011-01-04 09:09:50 +00:00
|
|
|
generator_(generator),
|
2010-08-18 15:36:00 +00:00
|
|
|
running_(true),
|
2010-03-19 09:46:53 +00:00
|
|
|
ticks_buffer_(sizeof(TickSampleEventRecord),
|
|
|
|
kTickSamplesBufferChunkSize,
|
|
|
|
kTickSamplesBufferChunksCount),
|
2011-02-22 16:31:24 +00:00
|
|
|
enqueue_order_(0) {
|
2010-06-01 13:52:49 +00:00
|
|
|
}
|
2010-03-19 09:46:53 +00:00
|
|
|
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
void ProfilerEventsProcessor::CallbackCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
const char* prefix,
|
|
|
|
String* name,
|
|
|
|
Address start) {
|
2010-04-07 14:18:26 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
2010-04-06 10:36:38 +00:00
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_CREATION;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->start = start;
|
|
|
|
rec->entry = generator_->NewCodeEntry(tag, prefix, name);
|
|
|
|
rec->size = 1;
|
2011-03-10 12:00:27 +00:00
|
|
|
rec->shared = NULL;
|
2010-04-06 10:36:38 +00:00
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
String* name,
|
|
|
|
String* resource_name,
|
|
|
|
int line_number,
|
|
|
|
Address start,
|
2011-02-22 16:31:24 +00:00
|
|
|
unsigned size,
|
2011-03-10 12:00:27 +00:00
|
|
|
Address shared) {
|
2010-04-07 14:18:26 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
2010-03-19 09:46:53 +00:00
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_CREATION;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->start = start;
|
|
|
|
rec->entry = generator_->NewCodeEntry(tag, name, resource_name, line_number);
|
|
|
|
rec->size = size;
|
2011-03-10 12:00:27 +00:00
|
|
|
rec->shared = shared;
|
2010-03-19 09:46:53 +00:00
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
const char* name,
|
|
|
|
Address start,
|
|
|
|
unsigned size) {
|
2010-04-07 14:18:26 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
2010-03-19 09:46:53 +00:00
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_CREATION;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->start = start;
|
|
|
|
rec->entry = generator_->NewCodeEntry(tag, name);
|
|
|
|
rec->size = size;
|
2011-03-10 12:00:27 +00:00
|
|
|
rec->shared = NULL;
|
2010-03-19 09:46:53 +00:00
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
int args_count,
|
|
|
|
Address start,
|
|
|
|
unsigned size) {
|
2010-04-07 14:18:26 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
2010-03-19 09:46:53 +00:00
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_CREATION;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->start = start;
|
|
|
|
rec->entry = generator_->NewCodeEntry(tag, args_count);
|
|
|
|
rec->size = size;
|
2011-03-10 12:00:27 +00:00
|
|
|
rec->shared = NULL;
|
2010-03-19 09:46:53 +00:00
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::CodeMoveEvent(Address from, Address to) {
|
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_MOVE;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->from = from;
|
|
|
|
rec->to = to;
|
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::CodeDeleteEvent(Address from) {
|
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeDeleteEventRecord* rec = &evt_rec.CodeDeleteEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_DELETE;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->start = from;
|
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 12:00:27 +00:00
|
|
|
void ProfilerEventsProcessor::SharedFunctionInfoMoveEvent(Address from,
|
|
|
|
Address to) {
|
2010-03-19 09:46:53 +00:00
|
|
|
CodeEventsContainer evt_rec;
|
2011-03-10 12:00:27 +00:00
|
|
|
SharedFunctionInfoMoveEventRecord* rec =
|
|
|
|
&evt_rec.SharedFunctionInfoMoveEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::SHARED_FUNC_MOVE;
|
2010-03-19 09:46:53 +00:00
|
|
|
rec->order = ++enqueue_order_;
|
2011-02-22 16:31:24 +00:00
|
|
|
rec->from = from;
|
|
|
|
rec->to = to;
|
2010-03-19 09:46:53 +00:00
|
|
|
events_buffer_.Enqueue(evt_rec);
|
2010-10-20 08:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 14:54:20 +00:00
|
|
|
void ProfilerEventsProcessor::RegExpCodeCreateEvent(
|
|
|
|
Logger::LogEventsAndTags tag,
|
|
|
|
const char* prefix,
|
|
|
|
String* name,
|
|
|
|
Address start,
|
|
|
|
unsigned size) {
|
2010-04-07 14:18:26 +00:00
|
|
|
if (FilterOutCodeCreateEvent(tag)) return;
|
2010-04-06 14:54:20 +00:00
|
|
|
CodeEventsContainer evt_rec;
|
|
|
|
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
|
|
|
|
rec->type = CodeEventRecord::CODE_CREATION;
|
|
|
|
rec->order = ++enqueue_order_;
|
|
|
|
rec->start = start;
|
|
|
|
rec->entry = generator_->NewCodeEntry(tag, prefix, name);
|
|
|
|
rec->size = size;
|
|
|
|
events_buffer_.Enqueue(evt_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-01 13:52:49 +00:00
|
|
|
void ProfilerEventsProcessor::AddCurrentStack() {
|
|
|
|
TickSampleEventRecord record;
|
|
|
|
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
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
sample->state = isolate->current_vm_state();
|
2010-06-01 13:52:49 +00:00
|
|
|
sample->pc = reinterpret_cast<Address>(sample); // Not NULL.
|
2011-02-22 16:31:24 +00:00
|
|
|
sample->tos = NULL;
|
2011-03-30 13:30:52 +00:00
|
|
|
sample->has_external_callback = false;
|
2010-06-01 13:52:49 +00:00
|
|
|
sample->frames_count = 0;
|
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
|
|
|
}
|
|
|
|
record.order = enqueue_order_;
|
|
|
|
ticks_from_vm_buffer_.Enqueue(record);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
bool ProfilerEventsProcessor::ProcessCodeEvent(unsigned* dequeue_order) {
|
|
|
|
if (!events_buffer_.IsEmpty()) {
|
|
|
|
CodeEventsContainer record;
|
|
|
|
events_buffer_.Dequeue(&record);
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
*dequeue_order = record.generic.order;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) {
|
|
|
|
while (true) {
|
2010-06-01 13:52:49 +00:00
|
|
|
if (!ticks_from_vm_buffer_.IsEmpty()
|
|
|
|
&& ticks_from_vm_buffer_.Peek()->order == dequeue_order) {
|
|
|
|
TickSampleEventRecord record;
|
|
|
|
ticks_from_vm_buffer_.Dequeue(&record);
|
|
|
|
generator_->RecordTickSample(record.sample);
|
|
|
|
}
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
const TickSampleEventRecord* rec =
|
2010-03-30 11:38:39 +00:00
|
|
|
TickSampleEventRecord::cast(ticks_buffer_.StartDequeue());
|
2010-06-01 13:52:49 +00:00
|
|
|
if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty();
|
2010-09-01 13:08:39 +00:00
|
|
|
// 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;
|
|
|
|
if (record.order == dequeue_order) {
|
|
|
|
// 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);
|
2010-03-19 09:46:53 +00:00
|
|
|
ticks_buffer_.FinishDequeue();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfilerEventsProcessor::Run() {
|
|
|
|
unsigned dequeue_order = 0;
|
|
|
|
|
|
|
|
while (running_) {
|
|
|
|
// Process ticks until we have any.
|
|
|
|
if (ProcessTicks(dequeue_order)) {
|
|
|
|
// All ticks of the current dequeue_order are processed,
|
|
|
|
// proceed to the next code event.
|
|
|
|
ProcessCodeEvent(&dequeue_order);
|
|
|
|
}
|
|
|
|
YieldCPU();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process remaining tick events.
|
|
|
|
ticks_buffer_.FlushResidualRecords();
|
|
|
|
// Perform processing until we have tick events, skip remaining code events.
|
|
|
|
while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { }
|
|
|
|
}
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
|
|
|
|
void CpuProfiler::StartProfiling(const char* title) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
|
|
|
Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::StartProfiling(String* title) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
|
|
|
Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfile* CpuProfiler::StopProfiling(const char* title) {
|
2011-04-22 06:40:22 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
return is_profiling(isolate) ?
|
|
|
|
isolate->cpu_profiler()->StopCollectingProfile(title) : NULL;
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) {
|
2011-04-22 06:40:22 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
return is_profiling(isolate) ?
|
|
|
|
isolate->cpu_profiler()->StopCollectingProfile(
|
2011-03-18 20:35:07 +00:00
|
|
|
security_token, title) : NULL;
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CpuProfiler::GetProfilesCount() {
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
2010-05-18 14:19:33 +00:00
|
|
|
// The count of profiles doesn't depend on a security token.
|
2011-03-18 20:35:07 +00:00
|
|
|
return Isolate::Current()->cpu_profiler()->profiles_->Profiles(
|
2010-06-08 11:27:00 +00:00
|
|
|
TokenEnumerator::kNoSecurityToken)->length();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
|
|
|
CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
|
|
|
|
const int token = profiler->token_enumerator_->GetTokenId(security_token);
|
|
|
|
return profiler->profiles_->Profiles(token)->at(index);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
|
|
|
CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
|
|
|
|
const int token = profiler->token_enumerator_->GetTokenId(security_token);
|
|
|
|
return profiler->profiles_->GetProfile(token, uid);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) {
|
|
|
|
if (CpuProfiler::is_profiling(isolate)) {
|
|
|
|
return isolate->cpu_profiler()->processor_->TickSampleEvent();
|
2010-04-06 10:36:38 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
void CpuProfiler::DeleteAllProfiles() {
|
2011-03-29 13:41:06 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
ASSERT(isolate->cpu_profiler() != NULL);
|
2011-04-22 06:40:22 +00:00
|
|
|
if (is_profiling(isolate)) {
|
2011-03-29 13:41:06 +00:00
|
|
|
isolate->cpu_profiler()->StopProcessor();
|
2011-04-22 06:40:22 +00:00
|
|
|
}
|
2011-03-29 13:41:06 +00:00
|
|
|
isolate->cpu_profiler()->ResetProfiles();
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::DeleteProfile(CpuProfile* profile) {
|
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
|
|
|
Isolate::Current()->cpu_profiler()->profiles_->RemoveProfile(profile);
|
|
|
|
delete profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CpuProfiler::HasDetachedProfiles() {
|
|
|
|
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
|
|
|
|
return Isolate::Current()->cpu_profiler()->profiles_->HasDetachedProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
void CpuProfiler::CallbackEvent(String* name, Address entry_point) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
Code* code, const char* comment) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
tag, comment, code->address(), code->ExecutableSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
Code* code, String* name) {
|
2011-03-29 13:41:06 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
isolate->cpu_profiler()->processor_->CodeCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
tag,
|
|
|
|
name,
|
2011-03-29 13:41:06 +00:00
|
|
|
isolate->heap()->empty_string(),
|
2010-04-06 14:54:20 +00:00
|
|
|
v8::CpuProfileNode::kNoLineNumberInfo,
|
2010-04-06 10:36:38 +00:00
|
|
|
code->address(),
|
2011-02-22 16:31:24 +00:00
|
|
|
code->ExecutableSize(),
|
|
|
|
NULL);
|
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,
|
|
|
|
String* name) {
|
2011-03-29 13:41:06 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
isolate->cpu_profiler()->processor_->CodeCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
tag,
|
|
|
|
name,
|
2011-03-29 13:41:06 +00:00
|
|
|
isolate->heap()->empty_string(),
|
2011-02-22 16:31:24 +00:00
|
|
|
v8::CpuProfileNode::kNoLineNumberInfo,
|
|
|
|
code->address(),
|
|
|
|
code->ExecutableSize(),
|
|
|
|
shared->address());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
Code* code,
|
|
|
|
SharedFunctionInfo* shared,
|
|
|
|
String* source, int line) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
|
2011-02-22 16:31:24 +00:00
|
|
|
tag,
|
|
|
|
shared->DebugName(),
|
2010-04-06 10:36:38 +00:00
|
|
|
source,
|
|
|
|
line,
|
|
|
|
code->address(),
|
2011-02-22 16:31:24 +00:00
|
|
|
code->ExecutableSize(),
|
|
|
|
shared->address());
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
|
|
|
|
Code* code, int args_count) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
tag,
|
|
|
|
args_count,
|
|
|
|
code->address(),
|
|
|
|
code->ExecutableSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeMoveEvent(Address from, Address to) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::CodeDeleteEvent(Address from) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CodeDeleteEvent(from);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 12:00:27 +00:00
|
|
|
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) {
|
2011-03-18 20:35:07 +00:00
|
|
|
CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
|
|
|
|
profiler->processor_->SharedFunctionInfoMoveEvent(from, to);
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::GetterCallbackEvent(String* name, Address entry_point) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
Logger::CALLBACK_TAG, "get ", name, entry_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
Logger::REG_EXP_TAG,
|
2010-04-06 14:54:20 +00:00
|
|
|
"RegExp: ",
|
2010-04-06 10:36:38 +00:00
|
|
|
source,
|
|
|
|
code->address(),
|
|
|
|
code->ExecutableSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
|
2010-04-06 10:36:38 +00:00
|
|
|
Logger::CALLBACK_TAG, "set ", name, entry_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfiler::CpuProfiler()
|
|
|
|
: profiles_(new CpuProfilesCollection()),
|
|
|
|
next_profile_uid_(1),
|
2010-05-18 14:19:33 +00:00
|
|
|
token_enumerator_(new TokenEnumerator()),
|
2010-04-06 10:36:38 +00:00
|
|
|
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),
|
2011-03-18 20:35:07 +00:00
|
|
|
is_profiling_(false) {
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfiler::~CpuProfiler() {
|
2010-05-18 14:19:33 +00:00
|
|
|
delete token_enumerator_;
|
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();
|
|
|
|
}
|
|
|
|
|
2010-04-06 10:36:38 +00:00
|
|
|
void CpuProfiler::StartCollectingProfile(const char* title) {
|
2010-04-06 14:54:20 +00:00
|
|
|
if (profiles_->StartProfiling(title, next_profile_uid_++)) {
|
2010-04-06 10:36:38 +00:00
|
|
|
StartProcessorIfNotStarted();
|
|
|
|
}
|
2010-06-01 13:52:49 +00:00
|
|
|
processor_->AddCurrentStack();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::StartCollectingProfile(String* title) {
|
2010-06-01 13:52:49 +00:00
|
|
|
StartCollectingProfile(profiles_->GetName(title));
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::StartProcessorIfNotStarted() {
|
|
|
|
if (processor_ == NULL) {
|
2011-03-29 13:41:06 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
|
2010-04-12 07:23:43 +00:00
|
|
|
// Disable logging when using the new implementation.
|
2011-03-29 13:41:06 +00:00
|
|
|
saved_logging_nesting_ = isolate->logger()->logging_nesting_;
|
|
|
|
isolate->logger()->logging_nesting_ = 0;
|
2010-04-06 10:36:38 +00:00
|
|
|
generator_ = new ProfileGenerator(profiles_);
|
2011-03-29 13:41:06 +00:00
|
|
|
processor_ = new ProfilerEventsProcessor(isolate, generator_);
|
2010-12-07 11:31:57 +00:00
|
|
|
NoBarrier_Store(&is_profiling_, true);
|
2010-04-06 10:36:38 +00:00
|
|
|
processor_->Start();
|
|
|
|
// Enumerate stuff we already have in the heap.
|
2011-03-29 13:41:06 +00:00
|
|
|
if (isolate->heap()->HasBeenSetup()) {
|
2010-09-24 11:45:12 +00:00
|
|
|
if (!FLAG_prof_browser_mode) {
|
|
|
|
bool saved_log_code_flag = FLAG_log_code;
|
|
|
|
FLAG_log_code = true;
|
2011-03-29 13:41:06 +00:00
|
|
|
isolate->logger()->LogCodeObjects();
|
2010-09-24 11:45:12 +00:00
|
|
|
FLAG_log_code = saved_log_code_flag;
|
|
|
|
}
|
2011-03-29 13:41:06 +00:00
|
|
|
isolate->logger()->LogCompiledFunctions();
|
|
|
|
isolate->logger()->LogAccessorCallbacks();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
2010-06-01 13:52:49 +00:00
|
|
|
// Enable stack sampling.
|
2011-03-29 13:41:06 +00:00
|
|
|
Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
|
2011-03-21 17:40:40 +00:00
|
|
|
if (!sampler->IsActive()) {
|
|
|
|
sampler->Start();
|
|
|
|
need_to_stop_sampler_ = true;
|
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
sampler->IncreaseProfilingDepth();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
|
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);
|
2010-06-08 11:27:00 +00:00
|
|
|
CpuProfile* result =
|
|
|
|
profiles_->StopProfiling(TokenEnumerator::kNoSecurityToken,
|
|
|
|
title,
|
|
|
|
actual_sampling_rate);
|
2010-04-06 10:36:38 +00:00
|
|
|
if (result != NULL) {
|
|
|
|
result->Print();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 14:19:33 +00:00
|
|
|
CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token,
|
|
|
|
String* title) {
|
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);
|
2010-05-18 14:19:33 +00:00
|
|
|
int token = token_enumerator_->GetTokenId(security_token);
|
2010-08-10 12:06:42 +00:00
|
|
|
return profiles_->StopProfiling(token, 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() {
|
2011-03-29 13:41:06 +00:00
|
|
|
Logger* logger = Isolate::Current()->logger();
|
|
|
|
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
|
|
|
}
|
2011-03-22 16:10:01 +00:00
|
|
|
processor_->Stop();
|
|
|
|
processor_->Join();
|
|
|
|
delete processor_;
|
|
|
|
delete generator_;
|
|
|
|
processor_ = NULL;
|
|
|
|
NoBarrier_Store(&is_profiling_, false);
|
|
|
|
generator_ = NULL;
|
2011-03-29 13:41:06 +00:00
|
|
|
logger->logging_nesting_ = saved_logging_nesting_;
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 09:46:53 +00:00
|
|
|
} } // namespace v8::internal
|
2010-03-30 11:38:39 +00:00
|
|
|
|
2010-04-14 18:48:05 +00:00
|
|
|
#endif // ENABLE_LOGGING_AND_PROFILING
|
2010-04-06 10:36:38 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
void CpuProfiler::Setup() {
|
2010-04-14 18:48:05 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
if (isolate->cpu_profiler() == NULL) {
|
|
|
|
isolate->set_cpu_profiler(new CpuProfiler());
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CpuProfiler::TearDown() {
|
2010-04-14 18:48:05 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate = Isolate::Current();
|
|
|
|
if (isolate->cpu_profiler() != NULL) {
|
|
|
|
delete isolate->cpu_profiler();
|
2010-04-06 10:36:38 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
isolate->set_cpu_profiler(NULL);
|
2010-04-06 10:36:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|