Index: src/cpu-profiler.cc |
=================================================================== |
--- src/cpu-profiler.cc (revision 7267) |
+++ src/cpu-profiler.cc (working copy) |
@@ -46,8 +46,9 @@ |
static const int kTickSamplesBufferChunksCount = 16; |
-ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) |
- : Thread("v8:ProfEvntProc"), |
+ProfilerEventsProcessor::ProfilerEventsProcessor(Isolate* isolate, |
+ ProfileGenerator* generator) |
+ : Thread(isolate, "v8:ProfEvntProc"), |
generator_(generator), |
running_(true), |
ticks_buffer_(sizeof(TickSampleEventRecord), |
@@ -183,7 +184,7 @@ |
void ProfilerEventsProcessor::AddCurrentStack() { |
TickSampleEventRecord record; |
TickSample* sample = &record.sample; |
- sample->state = Top::current_vm_state(); |
+ sample->state = Isolate::Current()->current_vm_state(); |
sample->pc = reinterpret_cast<Address>(sample); // Not NULL. |
sample->tos = NULL; |
sample->frames_count = 0; |
@@ -272,57 +273,58 @@ |
} |
-CpuProfiler* CpuProfiler::singleton_ = NULL; |
-Atomic32 CpuProfiler::is_profiling_ = false; |
- |
void CpuProfiler::StartProfiling(const char* title) { |
- ASSERT(singleton_ != NULL); |
- singleton_->StartCollectingProfile(title); |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
+ Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
} |
void CpuProfiler::StartProfiling(String* title) { |
- ASSERT(singleton_ != NULL); |
- singleton_->StartCollectingProfile(title); |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
+ Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
} |
CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
- return is_profiling() ? singleton_->StopCollectingProfile(title) : NULL; |
+ return is_profiling() ? |
+ Isolate::Current()->cpu_profiler()->StopCollectingProfile(title) : NULL; |
} |
CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { |
return is_profiling() ? |
- singleton_->StopCollectingProfile(security_token, title) : NULL; |
+ Isolate::Current()->cpu_profiler()->StopCollectingProfile( |
+ security_token, title) : NULL; |
} |
int CpuProfiler::GetProfilesCount() { |
- ASSERT(singleton_ != NULL); |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
// The count of profiles doesn't depend on a security token. |
- return singleton_->profiles_->Profiles( |
+ return Isolate::Current()->cpu_profiler()->profiles_->Profiles( |
TokenEnumerator::kNoSecurityToken)->length(); |
} |
CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { |
- ASSERT(singleton_ != NULL); |
- const int token = singleton_->token_enumerator_->GetTokenId(security_token); |
- return singleton_->profiles_->Profiles(token)->at(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); |
} |
CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) { |
- ASSERT(singleton_ != NULL); |
- const int token = singleton_->token_enumerator_->GetTokenId(security_token); |
- return singleton_->profiles_->GetProfile(token, 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); |
} |
-TickSample* CpuProfiler::TickSampleEvent() { |
- if (CpuProfiler::is_profiling()) { |
- return singleton_->processor_->TickSampleEvent(); |
+TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { |
+ if (CpuProfiler::is_profiling(isolate)) { |
+ return isolate->cpu_profiler()->processor_->TickSampleEvent(); |
} else { |
return NULL; |
} |
@@ -330,24 +332,24 @@ |
void CpuProfiler::CallbackEvent(String* name, Address entry_point) { |
- singleton_->processor_->CallbackCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point); |
} |
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, const char* comment) { |
- singleton_->processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, comment, code->address(), code->ExecutableSize()); |
} |
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, String* name) { |
- singleton_->processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
name, |
- Heap::empty_string(), |
+ HEAP->empty_string(), |
v8::CpuProfileNode::kNoLineNumberInfo, |
code->address(), |
code->ExecutableSize(), |
@@ -359,10 +361,10 @@ |
Code* code, |
SharedFunctionInfo* shared, |
String* name) { |
- singleton_->processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
name, |
- Heap::empty_string(), |
+ HEAP->empty_string(), |
v8::CpuProfileNode::kNoLineNumberInfo, |
code->address(), |
code->ExecutableSize(), |
@@ -374,7 +376,7 @@ |
Code* code, |
SharedFunctionInfo* shared, |
String* source, int line) { |
- singleton_->processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
shared->DebugName(), |
source, |
@@ -387,7 +389,7 @@ |
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, int args_count) { |
- singleton_->processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
args_count, |
code->address(), |
@@ -396,28 +398,29 @@ |
void CpuProfiler::CodeMoveEvent(Address from, Address to) { |
- singleton_->processor_->CodeMoveEvent(from, to); |
+ Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to); |
} |
void CpuProfiler::CodeDeleteEvent(Address from) { |
- singleton_->processor_->CodeDeleteEvent(from); |
+ Isolate::Current()->cpu_profiler()->processor_->CodeDeleteEvent(from); |
} |
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) { |
- singleton_->processor_->SharedFunctionInfoMoveEvent(from, to); |
+ CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
+ profiler->processor_->SharedFunctionInfoMoveEvent(from, to); |
} |
void CpuProfiler::GetterCallbackEvent(String* name, Address entry_point) { |
- singleton_->processor_->CallbackCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
Logger::CALLBACK_TAG, "get ", name, entry_point); |
} |
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { |
- singleton_->processor_->RegExpCodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent( |
Logger::REG_EXP_TAG, |
"RegExp: ", |
source, |
@@ -427,7 +430,7 @@ |
void CpuProfiler::SetterCallbackEvent(String* name, Address entry_point) { |
- singleton_->processor_->CallbackCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
Logger::CALLBACK_TAG, "set ", name, entry_point); |
} |
@@ -437,7 +440,8 @@ |
next_profile_uid_(1), |
token_enumerator_(new TokenEnumerator()), |
generator_(NULL), |
- processor_(NULL) { |
+ processor_(NULL), |
+ is_profiling_(false) { |
} |
@@ -463,25 +467,25 @@ |
void CpuProfiler::StartProcessorIfNotStarted() { |
if (processor_ == NULL) { |
// Disable logging when using the new implementation. |
- saved_logging_nesting_ = Logger::logging_nesting_; |
- Logger::logging_nesting_ = 0; |
+ saved_logging_nesting_ = LOGGER->logging_nesting_; |
+ LOGGER->logging_nesting_ = 0; |
generator_ = new ProfileGenerator(profiles_); |
- processor_ = new ProfilerEventsProcessor(generator_); |
+ processor_ = new ProfilerEventsProcessor(Isolate::Current(), generator_); |
NoBarrier_Store(&is_profiling_, true); |
processor_->Start(); |
// Enumerate stuff we already have in the heap. |
- if (Heap::HasBeenSetup()) { |
+ if (HEAP->HasBeenSetup()) { |
if (!FLAG_prof_browser_mode) { |
bool saved_log_code_flag = FLAG_log_code; |
FLAG_log_code = true; |
- Logger::LogCodeObjects(); |
+ LOGGER->LogCodeObjects(); |
FLAG_log_code = saved_log_code_flag; |
} |
- Logger::LogCompiledFunctions(); |
- Logger::LogAccessorCallbacks(); |
+ LOGGER->LogCompiledFunctions(); |
+ LOGGER->LogAccessorCallbacks(); |
} |
// Enable stack sampling. |
- Sampler* sampler = reinterpret_cast<Sampler*>(Logger::ticker_); |
+ Sampler* sampler = reinterpret_cast<Sampler*>(LOGGER->ticker_); |
if (!sampler->IsActive()) sampler->Start(); |
sampler->IncreaseProfilingDepth(); |
} |
@@ -514,7 +518,7 @@ |
void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
if (profiles_->IsLastProfile(title)) { |
- Sampler* sampler = reinterpret_cast<Sampler*>(Logger::ticker_); |
+ Sampler* sampler = reinterpret_cast<Sampler*>(LOGGER->ticker_); |
sampler->DecreaseProfilingDepth(); |
sampler->Stop(); |
processor_->Stop(); |
@@ -524,7 +528,7 @@ |
processor_ = NULL; |
NoBarrier_Store(&is_profiling_, false); |
generator_ = NULL; |
- Logger::logging_nesting_ = saved_logging_nesting_; |
+ LOGGER->logging_nesting_ = saved_logging_nesting_; |
} |
} |
@@ -537,8 +541,9 @@ |
void CpuProfiler::Setup() { |
#ifdef ENABLE_LOGGING_AND_PROFILING |
- if (singleton_ == NULL) { |
- singleton_ = new CpuProfiler(); |
+ Isolate* isolate = Isolate::Current(); |
+ if (isolate->cpu_profiler() == NULL) { |
+ isolate->set_cpu_profiler(new CpuProfiler()); |
} |
#endif |
} |
@@ -546,10 +551,11 @@ |
void CpuProfiler::TearDown() { |
#ifdef ENABLE_LOGGING_AND_PROFILING |
- if (singleton_ != NULL) { |
- delete singleton_; |
+ Isolate* isolate = Isolate::Current(); |
+ if (isolate->cpu_profiler() != NULL) { |
+ delete isolate->cpu_profiler(); |
} |
- singleton_ = NULL; |
+ isolate->set_cpu_profiler(NULL); |
#endif |
} |