Isolatify CPU profiler

Relanding r13987 that was reverted in r14031

TBR=danno
BUG=None

Review URL: https://codereview.chromium.org/13457002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14105 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yurys@chromium.org 2013-04-02 07:53:50 +00:00
parent c7532f0f0b
commit 9cbb34a0b5
19 changed files with 179 additions and 239 deletions

View File

@ -6478,11 +6478,12 @@ const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
void CpuProfile::Delete() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfile::Delete");
i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
if (i::CpuProfiler::GetProfilesCount() == 0 &&
!i::CpuProfiler::HasDetachedProfiles()) {
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
if (profiler->GetProfilesCount() == 0 && !profiler->HasDetachedProfiles()) {
// If this was the last profile, clean up all accessory data as well.
i::CpuProfiler::DeleteAllProfiles();
profiler->DeleteAllProfiles();
}
}
@ -6525,7 +6526,9 @@ int CpuProfile::GetSamplesCount() const {
int CpuProfiler::GetProfilesCount() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount");
return i::CpuProfiler::GetProfilesCount();
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
return profiler->GetProfilesCount();
}
@ -6533,8 +6536,10 @@ const CpuProfile* CpuProfiler::GetProfile(int index,
Handle<Value> security_token) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile");
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
return reinterpret_cast<const CpuProfile*>(
i::CpuProfiler::GetProfile(
profiler->GetProfile(
security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
index));
}
@ -6544,8 +6549,10 @@ const CpuProfile* CpuProfiler::FindProfile(unsigned uid,
Handle<Value> security_token) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile");
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
return reinterpret_cast<const CpuProfile*>(
i::CpuProfiler::FindProfile(
profiler->FindProfile(
security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
uid));
}
@ -6554,7 +6561,9 @@ const CpuProfile* CpuProfiler::FindProfile(unsigned uid,
void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling");
i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title), record_samples);
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
profiler->StartProfiling(*Utils::OpenHandle(*title), record_samples);
}
@ -6562,8 +6571,10 @@ const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title,
Handle<Value> security_token) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling");
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
return reinterpret_cast<const CpuProfile*>(
i::CpuProfiler::StopProfiling(
profiler->StopProfiling(
security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
*Utils::OpenHandle(*title)));
}
@ -6572,7 +6583,9 @@ const CpuProfile* CpuProfiler::StopProfiling(Handle<String> title,
void CpuProfiler::DeleteAllProfiles() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles");
i::CpuProfiler::DeleteAllProfiles();
i::CpuProfiler* profiler = isolate->cpu_profiler();
ASSERT(profiler != NULL);
profiler->DeleteAllProfiles();
}

View File

@ -171,7 +171,8 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
bool CodeGenerator::ShouldGenerateLog(Expression* type) {
ASSERT(type != NULL);
Isolate* isolate = Isolate::Current();
if (!isolate->logger()->is_logging() && !CpuProfiler::is_profiling(isolate)) {
if (!isolate->logger()->is_logging() &&
!isolate->cpu_profiler()->is_profiling()) {
return false;
}
Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());

View File

@ -1134,7 +1134,7 @@ void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
// script name and line number. Check explicitly whether logging is
// enabled as finding the line number is not free.
if (info->isolate()->logger()->is_logging_code_events() ||
CpuProfiler::is_profiling(info->isolate())) {
info->isolate()->cpu_profiler()->is_profiling()) {
Handle<Script> script = info->script();
Handle<Code> code = info->code();
if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))

View File

@ -258,110 +258,66 @@ void ProfilerEventsProcessor::Run() {
}
void CpuProfiler::StartProfiling(const char* title) {
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
Isolate::Current()->cpu_profiler()->StartCollectingProfile(title, false);
}
void CpuProfiler::StartProfiling(String* title, bool record_samples) {
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
Isolate::Current()->cpu_profiler()->StartCollectingProfile(
title, record_samples);
}
CpuProfile* CpuProfiler::StopProfiling(const char* title) {
Isolate* isolate = Isolate::Current();
return is_profiling(isolate) ?
isolate->cpu_profiler()->StopCollectingProfile(title) : NULL;
}
CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) {
Isolate* isolate = Isolate::Current();
return is_profiling(isolate) ?
isolate->cpu_profiler()->StopCollectingProfile(
security_token, title) : NULL;
}
int CpuProfiler::GetProfilesCount() {
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
// The count of profiles doesn't depend on a security token.
return Isolate::Current()->cpu_profiler()->profiles_->Profiles(
TokenEnumerator::kNoSecurityToken)->length();
return profiles_->Profiles(TokenEnumerator::kNoSecurityToken)->length();
}
CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) {
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);
const int token = token_enumerator_->GetTokenId(security_token);
return profiles_->Profiles(token)->at(index);
}
CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) {
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);
const int token = token_enumerator_->GetTokenId(security_token);
return profiles_->GetProfile(token, uid);
}
TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) {
if (CpuProfiler::is_profiling(isolate)) {
return isolate->cpu_profiler()->processor_->TickSampleEvent();
} else {
return NULL;
}
TickSample* CpuProfiler::TickSampleEvent() {
if (is_profiling_) return processor_->TickSampleEvent();
return NULL;
}
void CpuProfiler::DeleteAllProfiles() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate->cpu_profiler() != NULL);
if (is_profiling(isolate)) {
isolate->cpu_profiler()->StopProcessor();
}
isolate->cpu_profiler()->ResetProfiles();
if (is_profiling_) StopProcessor();
ResetProfiles();
}
void CpuProfiler::DeleteProfile(CpuProfile* profile) {
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
Isolate::Current()->cpu_profiler()->profiles_->RemoveProfile(profile);
profiles_->RemoveProfile(profile);
delete profile;
}
bool CpuProfiler::HasDetachedProfiles() {
ASSERT(Isolate::Current()->cpu_profiler() != NULL);
return Isolate::Current()->cpu_profiler()->profiles_->HasDetachedProfiles();
return profiles_->HasDetachedProfiles();
}
void CpuProfiler::CallbackEvent(Name* name, Address entry_point) {
Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
processor_->CallbackCreateEvent(
Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point);
}
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, const char* comment) {
Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
processor_->CodeCreateEvent(
tag, comment, code->address(), code->ExecutableSize());
}
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, Name* name) {
Isolate* isolate = Isolate::Current();
isolate->cpu_profiler()->processor_->CodeCreateEvent(
processor_->CodeCreateEvent(
tag,
name,
isolate->heap()->empty_string(),
isolate_->heap()->empty_string(),
v8::CpuProfileNode::kNoLineNumberInfo,
code->address(),
code->ExecutableSize(),
@ -373,11 +329,10 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
SharedFunctionInfo* shared,
Name* name) {
Isolate* isolate = Isolate::Current();
isolate->cpu_profiler()->processor_->CodeCreateEvent(
processor_->CodeCreateEvent(
tag,
name,
isolate->heap()->empty_string(),
isolate_->heap()->empty_string(),
v8::CpuProfileNode::kNoLineNumberInfo,
code->address(),
code->ExecutableSize(),
@ -389,7 +344,7 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
SharedFunctionInfo* shared,
String* source, int line) {
Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
processor_->CodeCreateEvent(
tag,
shared->DebugName(),
source,
@ -402,7 +357,7 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count) {
Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
processor_->CodeCreateEvent(
tag,
args_count,
code->address(),
@ -411,7 +366,7 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
void CpuProfiler::CodeMoveEvent(Address from, Address to) {
Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to);
processor_->CodeMoveEvent(from, to);
}
@ -420,19 +375,18 @@ void CpuProfiler::CodeDeleteEvent(Address from) {
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) {
CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
profiler->processor_->SharedFunctionInfoMoveEvent(from, to);
processor_->SharedFunctionInfoMoveEvent(from, to);
}
void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) {
Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
processor_->CallbackCreateEvent(
Logger::CALLBACK_TAG, "get ", name, entry_point);
}
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent(
processor_->RegExpCodeCreateEvent(
Logger::REG_EXP_TAG,
"RegExp: ",
source,
@ -442,13 +396,14 @@ void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {
Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
processor_->CallbackCreateEvent(
Logger::CALLBACK_TAG, "set ", name, entry_point);
}
CpuProfiler::CpuProfiler()
: profiles_(new CpuProfilesCollection()),
CpuProfiler::CpuProfiler(Isolate* isolate)
: isolate_(isolate),
profiles_(new CpuProfilesCollection()),
next_profile_uid_(1),
token_enumerator_(new TokenEnumerator()),
generator_(NULL),
@ -469,8 +424,7 @@ void CpuProfiler::ResetProfiles() {
profiles_ = new CpuProfilesCollection();
}
void CpuProfiler::StartCollectingProfile(const char* title,
bool record_samples) {
void CpuProfiler::StartProfiling(const char* title, bool record_samples) {
if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) {
StartProcessorIfNotStarted();
}
@ -478,35 +432,33 @@ void CpuProfiler::StartCollectingProfile(const char* title,
}
void CpuProfiler::StartCollectingProfile(String* title, bool record_samples) {
StartCollectingProfile(profiles_->GetName(title), record_samples);
void CpuProfiler::StartProfiling(String* title, bool record_samples) {
StartProfiling(profiles_->GetName(title), record_samples);
}
void CpuProfiler::StartProcessorIfNotStarted() {
if (processor_ == NULL) {
Isolate* isolate = Isolate::Current();
// Disable logging when using the new implementation.
saved_logging_nesting_ = isolate->logger()->logging_nesting_;
isolate->logger()->logging_nesting_ = 0;
saved_logging_nesting_ = isolate_->logger()->logging_nesting_;
isolate_->logger()->logging_nesting_ = 0;
generator_ = new ProfileGenerator(profiles_);
processor_ = new ProfilerEventsProcessor(generator_);
is_profiling_ = true;
processor_->Start();
// Enumerate stuff we already have in the heap.
if (isolate->heap()->HasBeenSetUp()) {
if (isolate_->heap()->HasBeenSetUp()) {
if (!FLAG_prof_browser_mode) {
bool saved_log_code_flag = FLAG_log_code;
FLAG_log_code = true;
isolate->logger()->LogCodeObjects();
isolate_->logger()->LogCodeObjects();
FLAG_log_code = saved_log_code_flag;
}
isolate->logger()->LogCompiledFunctions();
isolate->logger()->LogAccessorCallbacks();
isolate_->logger()->LogCompiledFunctions();
isolate_->logger()->LogAccessorCallbacks();
}
// Enable stack sampling.
Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
Sampler* sampler = reinterpret_cast<Sampler*>(isolate_->logger()->ticker_);
if (!sampler->IsActive()) {
sampler->Start();
need_to_stop_sampler_ = true;
@ -516,7 +468,8 @@ void CpuProfiler::StartProcessorIfNotStarted() {
}
CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
CpuProfile* CpuProfiler::StopProfiling(const char* title) {
if (!is_profiling_) return NULL;
const double actual_sampling_rate = generator_->actual_sampling_rate();
StopProcessorIfLastProfile(title);
CpuProfile* result =
@ -530,8 +483,8 @@ CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
}
CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token,
String* title) {
CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) {
if (!is_profiling_) return NULL;
const double actual_sampling_rate = generator_->actual_sampling_rate();
const char* profile_title = profiles_->GetName(title);
StopProcessorIfLastProfile(profile_title);
@ -546,7 +499,7 @@ void CpuProfiler::StopProcessorIfLastProfile(const char* title) {
void CpuProfiler::StopProcessor() {
Logger* logger = Isolate::Current()->logger();
Logger* logger = isolate_->logger();
Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_);
sampler->DecreaseProfilingDepth();
if (need_to_stop_sampler_) {
@ -564,20 +517,4 @@ void CpuProfiler::StopProcessor() {
}
void CpuProfiler::SetUp() {
Isolate* isolate = Isolate::Current();
if (isolate->cpu_profiler() == NULL) {
isolate->set_cpu_profiler(new CpuProfiler());
}
}
void CpuProfiler::TearDown() {
Isolate* isolate = Isolate::Current();
if (isolate->cpu_profiler() != NULL) {
delete isolate->cpu_profiler();
}
isolate->set_cpu_profiler(NULL);
}
} } // namespace v8::internal

View File

@ -184,84 +184,71 @@ class ProfilerEventsProcessor : public Thread {
unsigned enqueue_order_;
};
} } // namespace v8::internal
#define PROFILE(isolate, Call) \
LOG_CODE_EVENT(isolate, Call); \
do { \
if (v8::internal::CpuProfiler::is_profiling(isolate)) { \
v8::internal::CpuProfiler::Call; \
} \
#define PROFILE(IsolateGetter, Call) \
do { \
Isolate* cpu_profiler_isolate = (IsolateGetter); \
LOG_CODE_EVENT(cpu_profiler_isolate, Call); \
CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \
if (cpu_profiler->is_profiling()) { \
cpu_profiler->Call; \
} \
} while (false)
namespace v8 {
namespace internal {
// TODO(isolates): isolatify this class.
class CpuProfiler {
public:
static void SetUp();
static void TearDown();
explicit CpuProfiler(Isolate* isolate);
~CpuProfiler();
static void StartProfiling(const char* title);
static void StartProfiling(String* title, bool record_samples);
static CpuProfile* StopProfiling(const char* title);
static CpuProfile* StopProfiling(Object* security_token, String* title);
static int GetProfilesCount();
static CpuProfile* GetProfile(Object* security_token, int index);
static CpuProfile* FindProfile(Object* security_token, unsigned uid);
static void DeleteAllProfiles();
static void DeleteProfile(CpuProfile* profile);
static bool HasDetachedProfiles();
void StartProfiling(const char* title, bool record_samples = false);
void StartProfiling(String* title, bool record_samples);
CpuProfile* StopProfiling(const char* title);
CpuProfile* StopProfiling(Object* security_token, String* title);
int GetProfilesCount();
CpuProfile* GetProfile(Object* security_token, int index);
CpuProfile* FindProfile(Object* security_token, unsigned uid);
void DeleteAllProfiles();
void DeleteProfile(CpuProfile* profile);
bool HasDetachedProfiles();
// Invoked from stack sampler (thread or signal handler.)
static TickSample* TickSampleEvent(Isolate* isolate);
TickSample* TickSampleEvent();
// Must be called via PROFILE macro, otherwise will crash when
// profiling is not enabled.
static void CallbackEvent(Name* name, Address entry_point);
static void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, const char* comment);
static void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, Name* name);
static void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
void CallbackEvent(Name* name, Address entry_point);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, const char* comment);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, Name* name);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
SharedFunctionInfo* shared,
Name* name);
static void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
SharedFunctionInfo* shared,
String* source, int line);
static void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count);
static void CodeMovingGCEvent() {}
static void CodeMoveEvent(Address from, Address to);
static void CodeDeleteEvent(Address from);
static void GetterCallbackEvent(Name* name, Address entry_point);
static void RegExpCodeCreateEvent(Code* code, String* source);
static void SetterCallbackEvent(Name* name, Address entry_point);
static void SharedFunctionInfoMoveEvent(Address from, Address to);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
SharedFunctionInfo* shared,
String* source, int line);
void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count);
void CodeMovingGCEvent() {}
void CodeMoveEvent(Address from, Address to);
void CodeDeleteEvent(Address from);
void GetterCallbackEvent(Name* name, Address entry_point);
void RegExpCodeCreateEvent(Code* code, String* source);
void SetterCallbackEvent(Name* name, Address entry_point);
void SharedFunctionInfoMoveEvent(Address from, Address to);
static INLINE(bool is_profiling(Isolate* isolate)) {
CpuProfiler* profiler = isolate->cpu_profiler();
return profiler != NULL && profiler->is_profiling_;
}
INLINE(bool is_profiling() const) { return is_profiling_; }
private:
CpuProfiler();
~CpuProfiler();
void StartCollectingProfile(const char* title, bool record_samples);
void StartCollectingProfile(String* title, bool record_samples);
void StartProcessorIfNotStarted();
CpuProfile* StopCollectingProfile(const char* title);
CpuProfile* StopCollectingProfile(Object* security_token, String* title);
void StopProcessorIfLastProfile(const char* title);
void StopProcessor();
void ResetProfiles();
Isolate* isolate_;
CpuProfilesCollection* profiles_;
unsigned next_profile_uid_;
TokenEnumerator* token_enumerator_;

View File

@ -1858,7 +1858,7 @@ class ScavengingVisitor : public StaticVisitorBase {
HEAP_PROFILE(heap, ObjectMoveEvent(source->address(), target->address()));
Isolate* isolate = heap->isolate();
if (isolate->logger()->is_logging_code_events() ||
CpuProfiler::is_profiling(isolate)) {
isolate->cpu_profiler()->is_profiling()) {
if (target->IsSharedFunctionInfo()) {
PROFILE(isolate, SharedFunctionInfoMoveEvent(
source->address(), target->address()));
@ -2114,7 +2114,7 @@ static void InitializeScavengingVisitorsTables() {
void Heap::SelectScavengingVisitorsTable() {
bool logging_and_profiling =
isolate()->logger()->is_logging() ||
CpuProfiler::is_profiling(isolate()) ||
isolate()->cpu_profiler()->is_profiling() ||
(isolate()->heap_profiler() != NULL &&
isolate()->heap_profiler()->is_profiling());

View File

@ -1693,6 +1693,7 @@ Isolate::Isolate()
date_cache_(NULL),
code_stub_interface_descriptors_(NULL),
context_exit_happened_(false),
cpu_profiler_(NULL),
deferred_handles_head_(NULL),
optimizing_compiler_thread_(this),
marking_thread_(NULL),
@ -1825,7 +1826,9 @@ void Isolate::Deinit() {
PreallocatedMemoryThreadStop();
HeapProfiler::TearDown();
CpuProfiler::TearDown();
delete cpu_profiler_;
cpu_profiler_ = NULL;
if (runtime_profiler_ != NULL) {
runtime_profiler_->TearDown();
delete runtime_profiler_;
@ -2054,7 +2057,7 @@ bool Isolate::Init(Deserializer* des) {
// Enable logging before setting up the heap
logger_->SetUp();
CpuProfiler::SetUp();
cpu_profiler_ = new CpuProfiler(this);
HeapProfiler::SetUp();
// Initialize other runtime facilities

View File

@ -357,9 +357,6 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache;
V(FunctionInfoListener*, active_function_info_listener, NULL) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, NULL) \
/* State for CodeEntry in profile-generator. */ \
V(CodeGenerator*, current_code_generator, NULL) \
V(bool, jump_target_compiling_deferred_code, false) \
V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \
V(Object*, string_stream_current_security_token, NULL) \
/* TODO(isolates): Release this on destruction? */ \
@ -371,7 +368,6 @@ typedef List<HeapObject*, PreallocatedStorageAllocationPolicy> DebugObjectCache;
V(unsigned, ast_node_count, 0) \
/* SafeStackFrameIterator activations count. */ \
V(int, safe_stack_iterator_counter, 0) \
V(CpuProfiler*, cpu_profiler, NULL) \
V(HeapProfiler*, heap_profiler, NULL) \
V(bool, observer_delivery_pending, false) \
V(HStatistics*, hstatistics, NULL) \
@ -979,6 +975,8 @@ class Isolate {
inline bool IsDebuggerActive();
inline bool DebuggerHasBreakPoints();
CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
#ifdef DEBUG
HistogramInfo* heap_histograms() { return heap_histograms_; }
@ -1314,6 +1312,7 @@ class Isolate {
Debugger* debugger_;
Debug* debug_;
#endif
CpuProfiler* cpu_profiler_;
#define GLOBAL_BACKING_STORE(type, name, initialvalue) \
type name##_;

View File

@ -1682,7 +1682,7 @@ void Logger::LogCodeObject(Object* object) {
tag = Logger::KEYED_CALL_IC_TAG;
break;
}
PROFILE(ISOLATE, CodeCreateEvent(tag, code_object, description));
PROFILE(isolate_, CodeCreateEvent(tag, code_object, description));
}
}
@ -1786,20 +1786,20 @@ void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
Handle<String> script_name(String::cast(script->name()));
int line_num = GetScriptLineNumber(script, shared->start_position());
if (line_num > 0) {
PROFILE(ISOLATE,
PROFILE(isolate_,
CodeCreateEvent(
Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
*code, *shared,
*script_name, line_num + 1));
} else {
// Can't distinguish eval and script here, so always use Script.
PROFILE(ISOLATE,
PROFILE(isolate_,
CodeCreateEvent(
Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
*code, *shared, *script_name));
}
} else {
PROFILE(ISOLATE,
PROFILE(isolate_,
CodeCreateEvent(
Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
*code, *shared, *func_name));
@ -1812,10 +1812,10 @@ void Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data);
Object* callback_obj = call_data->callback();
Address entry_point = v8::ToCData<Address>(callback_obj);
PROFILE(ISOLATE, CallbackEvent(*func_name, entry_point));
PROFILE(isolate_, CallbackEvent(*func_name, entry_point));
}
} else {
PROFILE(ISOLATE,
PROFILE(isolate_,
CodeCreateEvent(
Logger::LAZY_COMPILE_TAG, *code, *shared, *func_name));
}
@ -1856,11 +1856,11 @@ void Logger::LogAccessorCallbacks() {
Address getter_entry = v8::ToCData<Address>(ai->getter());
Name* name = Name::cast(ai->name());
if (getter_entry != 0) {
PROFILE(ISOLATE, GetterCallbackEvent(name, getter_entry));
PROFILE(isolate_, GetterCallbackEvent(name, getter_entry));
}
Address setter_entry = v8::ToCData<Address>(ai->setter());
if (setter_entry != 0) {
PROFILE(ISOLATE, SetterCallbackEvent(name, setter_entry));
PROFILE(isolate_, SetterCallbackEvent(name, setter_entry));
}
}
}

View File

@ -687,13 +687,14 @@ class SamplerThread : public Thread {
CONTEXT context;
memset(&context, 0, sizeof(context));
Isolate* isolate = sampler->isolate();
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate());
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
static const DWORD kSuspendFailed = static_cast<DWORD>(-1);
if (SuspendThread(profiled_thread) == kSuspendFailed) return;
sample->state = sampler->isolate()->current_vm_state();
sample->state = isolate->current_vm_state();
context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) {

View File

@ -715,7 +715,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.

View File

@ -1088,7 +1088,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.

View File

@ -818,8 +818,9 @@ class SamplerThread : public Thread {
void SampleContext(Sampler* sampler) {
thread_act_t profiled_thread = sampler->platform_data()->profiled_thread();
Isolate* isolate = sampler->isolate();
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate());
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
if (KERN_SUCCESS != thread_suspend(profiled_thread)) return;
@ -850,7 +851,7 @@ class SamplerThread : public Thread {
flavor,
reinterpret_cast<natural_t*>(&state),
&count) == KERN_SUCCESS) {
sample->state = sampler->isolate()->current_vm_state();
sample->state = isolate->current_vm_state();
sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip));
sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp));
sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp));

View File

@ -748,7 +748,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.

View File

@ -682,7 +682,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.

View File

@ -2064,13 +2064,14 @@ class SamplerThread : public Thread {
CONTEXT context;
memset(&context, 0, sizeof(context));
Isolate* isolate = sampler->isolate();
TickSample sample_obj;
TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate());
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
static const DWORD kSuspendFailed = static_cast<DWORD>(-1);
if (SuspendThread(profiled_thread) == kSuspendFailed) return;
sample->state = sampler->isolate()->current_vm_state();
sample->state = isolate->current_vm_state();
context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) {

View File

@ -2364,7 +2364,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SetCode) {
target->set_literals(*literals);
if (isolate->logger()->is_logging_code_events() ||
CpuProfiler::is_profiling(isolate)) {
isolate->cpu_profiler()->is_profiling()) {
isolate->logger()->LogExistingFunction(
source_shared, Handle<Code>(source_shared->code()));
}

View File

@ -219,12 +219,11 @@ TEST(TickEvents) {
TEST(CrashIfStoppingLastNonExistentProfile) {
InitializeVM();
TestSetup test_setup;
CpuProfiler::SetUp();
CpuProfiler::StartProfiling("1");
CpuProfiler::StopProfiling("2");
CpuProfiler::StartProfiling("1");
CpuProfiler::StopProfiling("");
CpuProfiler::TearDown();
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
profiler->StartProfiling("1");
profiler->StopProfiling("2");
profiler->StartProfiling("1");
profiler->StopProfiling("");
}
@ -271,32 +270,30 @@ TEST(Issue1398) {
TEST(DeleteAllCpuProfiles) {
InitializeVM();
TestSetup test_setup;
CpuProfiler::SetUp();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CpuProfiler::DeleteAllProfiles();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
CHECK_EQ(0, profiler->GetProfilesCount());
profiler->DeleteAllProfiles();
CHECK_EQ(0, profiler->GetProfilesCount());
CpuProfiler::StartProfiling("1");
CpuProfiler::StopProfiling("1");
CHECK_EQ(1, CpuProfiler::GetProfilesCount());
CpuProfiler::DeleteAllProfiles();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CpuProfiler::StartProfiling("1");
CpuProfiler::StartProfiling("2");
CpuProfiler::StopProfiling("2");
CpuProfiler::StopProfiling("1");
CHECK_EQ(2, CpuProfiler::GetProfilesCount());
CpuProfiler::DeleteAllProfiles();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
profiler->StartProfiling("1");
profiler->StopProfiling("1");
CHECK_EQ(1, profiler->GetProfilesCount());
profiler->DeleteAllProfiles();
CHECK_EQ(0, profiler->GetProfilesCount());
profiler->StartProfiling("1");
profiler->StartProfiling("2");
profiler->StopProfiling("2");
profiler->StopProfiling("1");
CHECK_EQ(2, profiler->GetProfilesCount());
profiler->DeleteAllProfiles();
CHECK_EQ(0, profiler->GetProfilesCount());
// Test profiling cancellation by the 'delete' command.
CpuProfiler::StartProfiling("1");
CpuProfiler::StartProfiling("2");
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CpuProfiler::DeleteAllProfiles();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CpuProfiler::TearDown();
profiler->StartProfiling("1");
profiler->StartProfiling("2");
CHECK_EQ(0, profiler->GetProfilesCount());
profiler->DeleteAllProfiles();
CHECK_EQ(0, profiler->GetProfilesCount());
}
@ -313,7 +310,7 @@ TEST(DeleteCpuProfile) {
unsigned uid1 = p1->GetUid();
CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1));
const_cast<v8::CpuProfile*>(p1)->Delete();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
v8::Local<v8::String> name2 = v8::String::New("2");
@ -339,7 +336,7 @@ TEST(DeleteCpuProfile) {
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
const_cast<v8::CpuProfile*>(p3)->Delete();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3));
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
@ -364,11 +361,11 @@ TEST(DeleteCpuProfileDifferentTokens) {
CHECK_NE(p1, p1_t1);
CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
const_cast<v8::CpuProfile*>(p1)->Delete();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1, token1));
const_cast<v8::CpuProfile*>(p1_t1)->Delete();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
v8::Local<v8::String> name2 = v8::String::New("2");
v8::CpuProfiler::StartProfiling(name2);
@ -397,6 +394,6 @@ TEST(DeleteCpuProfileDifferentTokens) {
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
const_cast<v8::CpuProfile*>(p3)->Delete();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3));
}

View File

@ -876,16 +876,16 @@ TEST(RecordStackTraceAtStartProfiling) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
env->Enter();
CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
CHECK_EQ(0, profiler->GetProfilesCount());
CompileRun(
"function c() { startProfiling(); }\n"
"function b() { c(); }\n"
"function a() { b(); }\n"
"a();\n"
"stopProfiling();");
CHECK_EQ(1, CpuProfiler::GetProfilesCount());
CpuProfile* profile =
CpuProfiler::GetProfile(NULL, 0);
CHECK_EQ(1, profiler->GetProfilesCount());
CpuProfile* profile = profiler->GetProfile(NULL, 0);
const ProfileTree* topDown = profile->top_down();
const ProfileNode* current = topDown->root();
const_cast<ProfileNode*>(current)->Print(0);