Index: src/cpu-profiler.cc |
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc |
index 7979eb4d21a0c33e1630992244f15cb54bab43df..15edc1ebdc0096b23eef5361d24c4f1613b6ebb4 100644 |
--- a/src/cpu-profiler.cc |
+++ b/src/cpu-profiler.cc |
@@ -258,66 +258,109 @@ void ProfilerEventsProcessor::Run() { |
} |
+void CpuProfiler::StartProfiling(const char* title) { |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
+ Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
+} |
+ |
+ |
+void CpuProfiler::StartProfiling(String* title) { |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
+ Isolate::Current()->cpu_profiler()->StartCollectingProfile(title); |
+} |
+ |
+ |
+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 profiles_->Profiles(TokenEnumerator::kNoSecurityToken)->length(); |
+ return Isolate::Current()->cpu_profiler()->profiles_->Profiles( |
+ TokenEnumerator::kNoSecurityToken)->length(); |
} |
CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) { |
- const int token = token_enumerator_->GetTokenId(security_token); |
- return 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) { |
- const int token = token_enumerator_->GetTokenId(security_token); |
- return 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 (is_profiling_) return processor_->TickSampleEvent(); |
- return NULL; |
+TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) { |
+ if (CpuProfiler::is_profiling(isolate)) { |
+ return isolate->cpu_profiler()->processor_->TickSampleEvent(); |
+ } else { |
+ return NULL; |
+ } |
} |
void CpuProfiler::DeleteAllProfiles() { |
- if (is_profiling_) StopProcessor(); |
- ResetProfiles(); |
+ Isolate* isolate = Isolate::Current(); |
+ ASSERT(isolate->cpu_profiler() != NULL); |
+ if (is_profiling(isolate)) { |
+ isolate->cpu_profiler()->StopProcessor(); |
+ } |
+ isolate->cpu_profiler()->ResetProfiles(); |
} |
void CpuProfiler::DeleteProfile(CpuProfile* profile) { |
- profiles_->RemoveProfile(profile); |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
+ Isolate::Current()->cpu_profiler()->profiles_->RemoveProfile(profile); |
delete profile; |
} |
bool CpuProfiler::HasDetachedProfiles() { |
- return profiles_->HasDetachedProfiles(); |
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL); |
+ return Isolate::Current()->cpu_profiler()->profiles_->HasDetachedProfiles(); |
} |
void CpuProfiler::CallbackEvent(Name* name, Address entry_point) { |
- 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) { |
- processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, comment, code->address(), code->ExecutableSize()); |
} |
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, Name* name) { |
- processor_->CodeCreateEvent( |
+ Isolate* isolate = Isolate::Current(); |
+ isolate->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
name, |
- isolate_->heap()->empty_string(), |
+ isolate->heap()->empty_string(), |
v8::CpuProfileNode::kNoLineNumberInfo, |
code->address(), |
code->ExecutableSize(), |
@@ -329,10 +372,11 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, |
SharedFunctionInfo* shared, |
Name* name) { |
- processor_->CodeCreateEvent( |
+ Isolate* isolate = Isolate::Current(); |
+ isolate->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
name, |
- isolate_->heap()->empty_string(), |
+ isolate->heap()->empty_string(), |
v8::CpuProfileNode::kNoLineNumberInfo, |
code->address(), |
code->ExecutableSize(), |
@@ -344,7 +388,7 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, |
SharedFunctionInfo* shared, |
String* source, int line) { |
- processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
shared->DebugName(), |
source, |
@@ -357,7 +401,7 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
Code* code, int args_count) { |
- processor_->CodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent( |
tag, |
args_count, |
code->address(), |
@@ -366,7 +410,7 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, |
void CpuProfiler::CodeMoveEvent(Address from, Address to) { |
- processor_->CodeMoveEvent(from, to); |
+ Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to); |
} |
@@ -375,18 +419,19 @@ void CpuProfiler::CodeDeleteEvent(Address from) { |
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) { |
- processor_->SharedFunctionInfoMoveEvent(from, to); |
+ CpuProfiler* profiler = Isolate::Current()->cpu_profiler(); |
+ profiler->processor_->SharedFunctionInfoMoveEvent(from, to); |
} |
void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) { |
- processor_->CallbackCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
Logger::CALLBACK_TAG, "get ", name, entry_point); |
} |
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { |
- processor_->RegExpCodeCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent( |
Logger::REG_EXP_TAG, |
"RegExp: ", |
source, |
@@ -396,14 +441,13 @@ void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) { |
void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) { |
- processor_->CallbackCreateEvent( |
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent( |
Logger::CALLBACK_TAG, "set ", name, entry_point); |
} |
-CpuProfiler::CpuProfiler(Isolate* isolate) |
- : isolate_(isolate), |
- profiles_(new CpuProfilesCollection()), |
+CpuProfiler::CpuProfiler() |
+ : profiles_(new CpuProfilesCollection()), |
next_profile_uid_(1), |
token_enumerator_(new TokenEnumerator()), |
generator_(NULL), |
@@ -424,41 +468,43 @@ void CpuProfiler::ResetProfiles() { |
profiles_ = new CpuProfilesCollection(); |
} |
-void CpuProfiler::StartProfiling(const char* title, bool record_samples) { |
- if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) { |
+void CpuProfiler::StartCollectingProfile(const char* title) { |
+ if (profiles_->StartProfiling(title, next_profile_uid_++)) { |
StartProcessorIfNotStarted(); |
} |
processor_->AddCurrentStack(); |
} |
-void CpuProfiler::StartProfiling(String* title, bool record_samples) { |
- StartProfiling(profiles_->GetName(title), record_samples); |
+void CpuProfiler::StartCollectingProfile(String* title) { |
+ StartCollectingProfile(profiles_->GetName(title)); |
} |
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; |
@@ -468,8 +514,7 @@ void CpuProfiler::StartProcessorIfNotStarted() { |
} |
-CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
- if (!is_profiling_) return NULL; |
+CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) { |
const double actual_sampling_rate = generator_->actual_sampling_rate(); |
StopProcessorIfLastProfile(title); |
CpuProfile* result = |
@@ -483,8 +528,8 @@ CpuProfile* CpuProfiler::StopProfiling(const char* title) { |
} |
-CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) { |
- if (!is_profiling_) return NULL; |
+CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token, |
+ String* title) { |
const double actual_sampling_rate = generator_->actual_sampling_rate(); |
const char* profile_title = profiles_->GetName(title); |
StopProcessorIfLastProfile(profile_title); |
@@ -499,7 +544,7 @@ void CpuProfiler::StopProcessorIfLastProfile(const char* title) { |
void CpuProfiler::StopProcessor() { |
- Logger* logger = isolate_->logger(); |
+ Logger* logger = Isolate::Current()->logger(); |
Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_); |
sampler->DecreaseProfilingDepth(); |
if (need_to_stop_sampler_) { |
@@ -517,4 +562,20 @@ 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 |