Revision: 15415
Author: [email protected]
Date: Mon Jul 1 05:32:52 2013
Log: Test that profiler is stopped when isolate is being disposed
The only way to get v8::CpuProfiler instance in the V8 public API is to
call v8::Iolate::GetCpuProfiler(). The method will return NULL if the
isolate has not been initialized yet or has been torn down already. It is
the client's reponsibility to make sure that CPU profiling has been stopped
before disposing of the isolate.
This CL adds a test for this and several ASSRTS enforcing that assumptions.
This allowed to be sure that heap is always setup when CPU profiling is
being started. Based on that the number of places where already compiled
functions are reported to the profiler event processor boils down to the
single place (CpuProfiler::StartProcessorIfNotStarted). I'm going to rely
on this assumption in further changes.
BUG=None
[email protected], [email protected]
Review URL: https://codereview.chromium.org/18336002
http://code.google.com/p/v8/source/detail?r=15415
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/cpu-profiler.cc
/branches/bleeding_edge/test/cctest/test-cpu-profiler.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Mon Jul 1 03:54:39 2013
+++ /branches/bleeding_edge/include/v8.h Mon Jul 1 05:32:52 2013
@@ -3993,8 +3993,9 @@
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();
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.cc Mon Jul 1 05:24:26 2013
+++ /branches/bleeding_edge/src/cpu-profiler.cc Mon Jul 1 05:32:52 2013
@@ -405,6 +405,7 @@
CpuProfiler::~CpuProfiler() {
+ ASSERT(!is_profiling_);
delete token_enumerator_;
delete profiles_;
}
@@ -430,23 +431,23 @@
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();
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Mon Jul 1
05:24:26 2013
+++ /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Mon Jul 1
05:32:52 2013
@@ -448,6 +448,26 @@
CHECK_EQ(0, cpu_profiler->GetProfileCount());
CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid3));
}
+
+
+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,
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.