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();
}
}
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();
}
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));
}
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));
}
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);
}
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)));
}
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();
}
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());
// 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))
}
-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(),
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(),
Code* code,
SharedFunctionInfo* shared,
String* source, int line) {
- Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
+ processor_->CodeCreateEvent(
tag,
shared->DebugName(),
source,
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count) {
- Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
+ processor_->CodeCreateEvent(
tag,
args_count,
code->address(),
void CpuProfiler::CodeMoveEvent(Address from, Address to) {
- Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to);
+ processor_->CodeMoveEvent(from, to);
}
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,
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),
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();
}
}
-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;
}
-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 =
}
-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);
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_) {
}
-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
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();
-
- 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();
+ explicit CpuProfiler(Isolate* isolate);
+ ~CpuProfiler();
+
+ 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);
-
- static INLINE(bool is_profiling(Isolate* isolate)) {
- CpuProfiler* profiler = isolate->cpu_profiler();
- return profiler != NULL && profiler->is_profiling_;
- }
+ 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);
+
+ 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_;
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()));
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());
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),
PreallocatedMemoryThreadStop();
HeapProfiler::TearDown();
- CpuProfiler::TearDown();
+ delete cpu_profiler_;
+ cpu_profiler_ = NULL;
+
if (runtime_profiler_ != NULL) {
runtime_profiler_->TearDown();
delete runtime_profiler_;
// Enable logging before setting up the heap
logger_->SetUp();
- CpuProfiler::SetUp();
+ cpu_profiler_ = new CpuProfiler(this);
HeapProfiler::SetUp();
// Initialize other runtime facilities
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? */ \
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) \
inline bool IsDebuggerActive();
inline bool DebuggerHasBreakPoints();
+ CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
+
#ifdef DEBUG
HistogramInfo* heap_histograms() { return heap_histograms_; }
Debugger* debugger_;
Debug* debug_;
#endif
+ CpuProfiler* cpu_profiler_;
#define GLOBAL_BACKING_STORE(type, name, initialvalue) \
type name##_;
tag = Logger::KEYED_CALL_IC_TAG;
break;
}
- PROFILE(ISOLATE, CodeCreateEvent(tag, code_object, description));
+ PROFILE(isolate_, CodeCreateEvent(tag, code_object, description));
}
}
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));
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));
}
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));
}
}
}
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) {
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.
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.
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;
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));
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.
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.
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) {
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()));
}
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("");
}
TEST(DeleteAllCpuProfiles) {
InitializeVM();
TestSetup test_setup;
- CpuProfiler::SetUp();
- CHECK_EQ(0, CpuProfiler::GetProfilesCount());
- CpuProfiler::DeleteAllProfiles();
- CHECK_EQ(0, CpuProfiler::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());
+ CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
+ CHECK_EQ(0, profiler->GetProfilesCount());
+ profiler->DeleteAllProfiles();
+ CHECK_EQ(0, profiler->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());
}
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");
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));
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);
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));
}
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);