Reviewers: alph, loislo, Jakob,

Description:
Do not stop profiling if all finished profiles were deleted

Deleting finished profiles shouldn't interrupt profile recording.

BUG=None
LOG=N

Please review this at https://codereview.chromium.org/103893003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+38, -8 lines):
  M include/v8-profiler.h
  M src/api.cc
  M src/cpu-profiler.cc
  M test/cctest/test-cpu-profiler.cc


Index: include/v8-profiler.h
diff --git a/include/v8-profiler.h b/include/v8-profiler.h
index 0ed6c5d216b3f8708bea6ae794937b18f844591f..8d5e4baa3beaeada58116c787a0f40d7c60b8d22 100644
--- a/include/v8-profiler.h
+++ b/include/v8-profiler.h
@@ -132,10 +132,6 @@ class V8_EXPORT CpuProfile {
   /**
    * Deletes the profile and removes it from CpuProfiler's list.
    * All pointers to nodes previously returned become invalid.
-   * Profiles with the same uid but obtained using different
-   * security token are not deleted, but become inaccessible
-   * using FindProfile method. It is embedder's responsibility
-   * to call Delete on these profiles.
    */
   void Delete();
 };
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 290fcba97aa188a1fe1affb11ca1a4d3e86f62a7..45480baaf01e769567d4113b99284013f26cda59 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -7206,10 +7206,6 @@ void CpuProfile::Delete() {
   i::CpuProfiler* profiler = isolate->cpu_profiler();
   ASSERT(profiler != NULL);
   profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
-  if (profiler->GetProfilesCount() == 0) {
-    // If this was the last profile, clean up all accessory data as well.
-    profiler->DeleteAllProfiles();
-  }
 }


Index: src/cpu-profiler.cc
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc
index b1af621cccc1a3425e87534faafa8b14cea77c7f..0c5beeedfe1a1a3a1613528b056d259cf25f6dce 100644
--- a/src/cpu-profiler.cc
+++ b/src/cpu-profiler.cc
@@ -176,6 +176,10 @@ void CpuProfiler::DeleteAllProfiles() {
 void CpuProfiler::DeleteProfile(CpuProfile* profile) {
   profiles_->RemoveProfile(profile);
   delete profile;
+  if (profiles_->profiles()->is_empty() && !is_profiling_) {
+      // If this was the last profile, clean up all accessory data as well.
+      ResetProfiles();
+  }
 }


Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index 9ddfde0773a5a60861f3fef902010d7cf3821c8f..5f6e91647b756734bf813b8bd2e73ee875a95147 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -1533,3 +1533,37 @@ TEST(FunctionDetails) {
   CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a",
                        script_a->GetId(), 3, 14);
 }
+
+
+TEST(DontStopOnFinishedProfileDelete) {
+  const char* extensions[] = { "v8/profiler" };
+  v8::ExtensionConfiguration config(1, extensions);
+  LocalContext env(&config);
+  v8::Isolate* isolate = env->GetIsolate();
+  v8::HandleScope handleScope(isolate);
+
+  v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
+
+  CHECK_EQ(0, profiler->GetProfileCount());
+  v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer");
+  profiler->StartCpuProfiling(outer);
+  CHECK_EQ(0, profiler->GetProfileCount());
+
+ v8::Handle<v8::String> innter = v8::String::NewFromUtf8(isolate, "inner");
+  profiler->StartCpuProfiling(innter);
+  CHECK_EQ(0, profiler->GetProfileCount());
+
+  const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(innter);
+  CHECK(inner_profile);
+  CHECK_EQ(1, profiler->GetProfileCount());
+  const_cast<v8::CpuProfile*>(inner_profile)->Delete();
+  inner_profile = NULL;
+  CHECK_EQ(0, profiler->GetProfileCount());
+
+  const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer);
+  CHECK(outer_profile);
+  CHECK_EQ(1, profiler->GetProfileCount());
+  const_cast<v8::CpuProfile*>(outer_profile)->Delete();
+  outer_profile = NULL;
+  CHECK_EQ(0, profiler->GetProfileCount());
+}


--
--
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.

Reply via email to