HeapProfiler* GetHeapProfiler();
/**
- * Returns CPU profiler for this isolate. Will return NULL until the isolate
- * is initialized.
+ * Returns CPU profiler for this isolate. Will return NULL unless the isolate
+ * is initialized. It is the embedder's responsibility to stop all CPU
+ * profiling activities if it has started any.
*/
CpuProfiler* GetCpuProfiler();
CpuProfiler::~CpuProfiler() {
+ ASSERT(!is_profiling_);
delete token_enumerator_;
delete profiles_;
}
void CpuProfiler::StartProcessorIfNotStarted() {
if (processor_ == NULL) {
+ Logger* logger = isolate_->logger();
// Disable logging when using the new implementation.
- saved_logging_nesting_ = isolate_->logger()->logging_nesting_;
- isolate_->logger()->logging_nesting_ = 0;
+ saved_logging_nesting_ = logger->logging_nesting_;
+ logger->logging_nesting_ = 0;
generator_ = new ProfileGenerator(profiles_);
processor_ = new ProfilerEventsProcessor(generator_);
is_profiling_ = true;
processor_->StartSynchronously();
// Enumerate stuff we already have in the heap.
- if (isolate_->heap()->HasBeenSetUp()) {
- if (!FLAG_prof_browser_mode) {
- isolate_->logger()->LogCodeObjects();
- }
- isolate_->logger()->LogCompiledFunctions();
- isolate_->logger()->LogAccessorCallbacks();
+ ASSERT(isolate_->heap()->HasBeenSetUp());
+ if (!FLAG_prof_browser_mode) {
+ logger->LogCodeObjects();
}
+ logger->LogCompiledFunctions();
+ logger->LogAccessorCallbacks();
// Enable stack sampling.
- Sampler* sampler = isolate_->logger()->sampler();
+ Sampler* sampler = logger->sampler();
sampler->IncreaseProfilingDepth();
if (!sampler->IsActive()) {
sampler->Start();
}
+TEST(GetProfilerWhenIsolateIsNotInitialized) {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ CHECK(i::Isolate::Current()->IsDefaultIsolate());
+ CHECK(!i::Isolate::Current()->IsInitialized());
+ CHECK_EQ(NULL, isolate->GetCpuProfiler());
+ {
+ v8::Isolate::Scope isolateScope(isolate);
+ LocalContext env;
+ v8::HandleScope scope(isolate);
+ CHECK_NE(NULL, isolate->GetCpuProfiler());
+ isolate->GetCpuProfiler()->StartCpuProfiling(v8::String::New("Test"));
+ isolate->GetCpuProfiler()->StopCpuProfiling(v8::String::New("Test"));
+ }
+ CHECK(i::Isolate::Current()->IsInitialized());
+ CHECK_NE(NULL, isolate->GetCpuProfiler());
+ isolate->Dispose();
+ CHECK_EQ(NULL, isolate->GetCpuProfiler());
+}
+
+
static bool ContainsString(v8::Handle<v8::String> string,
const Vector<v8::Handle<v8::String> >& vector) {
for (int i = 0; i < vector.length(); i++) {