Delete several deprecated methods on v8::CpuProfiler
authoryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 18 Dec 2013 08:59:09 +0000 (08:59 +0000)
committeryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 18 Dec 2013 08:59:09 +0000 (08:59 +0000)
All methods for accessing collected profiles by index are deprecated. The indexed storage may well be implemented by the embedder should he need it. CpuProfiler's responsibility is just to create CpuProfile object that contains all collected data and whose lifetime can be managed by the embedder.

BUG=chromium:327298
LOG=Y
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/117353002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18337 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

12 files changed:
include/v8-profiler.h
src/api.cc
src/cpu-profiler.cc
src/cpu-profiler.h
src/profile-generator.cc
src/profile-generator.h
test/cctest/cctest.gyp
test/cctest/profiler-extension.cc [new file with mode: 0644]
test/cctest/profiler-extension.h [new file with mode: 0644]
test/cctest/test-api.cc
test/cctest/test-cpu-profiler.cc
test/cctest/test-profile-generator.cc

index d933af6..e88f472 100644 (file)
@@ -96,9 +96,6 @@ class V8_EXPORT CpuProfileNode {
  */
 class V8_EXPORT CpuProfile {
  public:
-  /** Returns CPU profile UID (assigned by the profiler.) */
-  unsigned GetUid() const;
-
   /** Returns CPU profile title. */
   Handle<String> GetTitle() const;
 
@@ -151,15 +148,6 @@ class V8_EXPORT CpuProfiler {
   void SetSamplingInterval(int us);
 
   /**
-   * Returns the number of profiles collected (doesn't include
-   * profiles that are being collected at the moment of call.)
-   */
-  int GetProfileCount();
-
-  /** Returns a profile by index. */
-  const CpuProfile* GetCpuProfile(int index);
-
-  /**
    * Starts collecting CPU profile. Title may be an empty string. It
    * is allowed to have several profiles being collected at
    * once. Attempts to start collecting several profiles with the same
@@ -179,13 +167,6 @@ class V8_EXPORT CpuProfiler {
   const CpuProfile* StopCpuProfiling(Handle<String> title);
 
   /**
-   * Deletes all existing profiles, also cancelling all profiling
-   * activity.  All previously returned pointers to profiles and their
-   * contents become invalid after this call.
-   */
-  void DeleteAllCpuProfiles();
-
-  /**
    * Tells the profiler whether the embedder is idle.
    */
   void SetIdle(bool is_idle);
index 3572265..c470f84 100644 (file)
@@ -6963,11 +6963,6 @@ void CpuProfile::Delete() {
 }
 
 
-unsigned CpuProfile::GetUid() const {
-  return reinterpret_cast<const i::CpuProfile*>(this)->uid();
-}
-
-
 Handle<String> CpuProfile::GetTitle() const {
   i::Isolate* isolate = i::Isolate::Current();
   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
@@ -7005,11 +7000,6 @@ int CpuProfile::GetSamplesCount() const {
 }
 
 
-int CpuProfiler::GetProfileCount() {
-  return reinterpret_cast<i::CpuProfiler*>(this)->GetProfilesCount();
-}
-
-
 void CpuProfiler::SetSamplingInterval(int us) {
   ASSERT(us >= 0);
   return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
@@ -7017,12 +7007,6 @@ void CpuProfiler::SetSamplingInterval(int us) {
 }
 
 
-const CpuProfile* CpuProfiler::GetCpuProfile(int index) {
-  return reinterpret_cast<const CpuProfile*>(
-      reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index));
-}
-
-
 void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) {
   reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
       *Utils::OpenHandle(*title), record_samples);
@@ -7036,11 +7020,6 @@ const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title) {
 }
 
 
-void CpuProfiler::DeleteAllCpuProfiles() {
-  reinterpret_cast<i::CpuProfiler*>(this)->DeleteAllProfiles();
-}
-
-
 void CpuProfiler::SetIdle(bool is_idle) {
   i::Isolate* isolate = reinterpret_cast<i::CpuProfiler*>(this)->isolate();
   i::StateTag state = isolate->current_vm_state();
index ef39341..c36850c 100644 (file)
@@ -380,7 +380,6 @@ CpuProfiler::CpuProfiler(Isolate* isolate)
       sampling_interval_(TimeDelta::FromMicroseconds(
           FLAG_cpu_profiler_sampling_interval)),
       profiles_(new CpuProfilesCollection(isolate->heap())),
-      next_profile_uid_(1),
       generator_(NULL),
       processor_(NULL),
       is_profiling_(false) {
@@ -395,7 +394,6 @@ CpuProfiler::CpuProfiler(Isolate* isolate,
       sampling_interval_(TimeDelta::FromMicroseconds(
           FLAG_cpu_profiler_sampling_interval)),
       profiles_(test_profiles),
-      next_profile_uid_(1),
       generator_(test_generator),
       processor_(test_processor),
       is_profiling_(false) {
@@ -421,7 +419,7 @@ void CpuProfiler::ResetProfiles() {
 
 
 void CpuProfiler::StartProfiling(const char* title, bool record_samples) {
-  if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) {
+  if (profiles_->StartProfiling(title, record_samples)) {
     StartProcessorIfNotStarted();
   }
   processor_->AddCurrentStack(isolate_);
index fcb9a67..53f00ff 100644 (file)
@@ -268,7 +268,6 @@ class CpuProfiler : public CodeEventListener {
   Isolate* isolate_;
   TimeDelta sampling_interval_;
   CpuProfilesCollection* profiles_;
-  unsigned next_profile_uid_;
   ProfileGenerator* generator_;
   ProfilerEventsProcessor* processor_;
   bool saved_is_logging_;
index acf54da..30783c6 100644 (file)
@@ -352,9 +352,8 @@ void ProfileTree::TraverseDepthFirst(Callback* callback) {
 }
 
 
-CpuProfile::CpuProfile(const char* title, unsigned uid, bool record_samples)
+CpuProfile::CpuProfile(const char* title, bool record_samples)
     : title_(title),
-      uid_(uid),
       record_samples_(record_samples),
       start_time_(Time::NowFromSystemTime()) {
   timer_.Start();
@@ -486,7 +485,7 @@ CpuProfilesCollection::~CpuProfilesCollection() {
 }
 
 
-bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid,
+bool CpuProfilesCollection::StartProfiling(const char* title,
                                            bool record_samples) {
   ASSERT(uid > 0);
   current_profiles_semaphore_.Wait();
@@ -501,7 +500,7 @@ bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid,
       return false;
     }
   }
-  current_profiles_.Add(new CpuProfile(title, uid, record_samples));
+  current_profiles_.Add(new CpuProfile(title, record_samples));
   current_profiles_semaphore_.Signal();
   return true;
 }
@@ -537,9 +536,8 @@ bool CpuProfilesCollection::IsLastProfile(const char* title) {
 
 void CpuProfilesCollection::RemoveProfile(CpuProfile* profile) {
   // Called from VM thread for a completed profile.
-  unsigned uid = profile->uid();
   for (int i = 0; i < finished_profiles_.length(); i++) {
-    if (uid == finished_profiles_[i]->uid()) {
+    if (profile == finished_profiles_[i]) {
       finished_profiles_.Remove(i);
       return;
     }
index 6e4758b..81980bf 100644 (file)
@@ -196,14 +196,13 @@ class ProfileTree {
 
 class CpuProfile {
  public:
-  CpuProfile(const char* title, unsigned uid, bool record_samples);
+  CpuProfile(const char* title, bool record_samples);
 
   // Add pc -> ... -> main() call path to the profile.
   void AddPath(const Vector<CodeEntry*>& path);
   void CalculateTotalTicksAndSamplingRate();
 
   const char* title() const { return title_; }
-  unsigned uid() const { return uid_; }
   const ProfileTree* top_down() const { return &top_down_; }
 
   int samples_count() const { return samples_.length(); }
@@ -218,7 +217,6 @@ class CpuProfile {
 
  private:
   const char* title_;
-  unsigned uid_;
   bool record_samples_;
   Time start_time_;
   Time end_time_;
@@ -281,7 +279,7 @@ class CpuProfilesCollection {
   explicit CpuProfilesCollection(Heap* heap);
   ~CpuProfilesCollection();
 
-  bool StartProfiling(const char* title, unsigned uid, bool record_samples);
+  bool StartProfiling(const char* title, bool record_samples);
   CpuProfile* StopProfiling(const char* title);
   List<CpuProfile*>* profiles() { return &finished_profiles_; }
   const char* GetName(Name* name) {
index 2017d61..af1183f 100644 (file)
@@ -47,6 +47,7 @@
         'gay-fixed.cc',
         'gay-precision.cc',
         'gay-shortest.cc',
+        'profiler-extension.cc',
         'test-accessors.cc',
         'test-alloc.cc',
         'test-api.cc',
diff --git a/test/cctest/profiler-extension.cc b/test/cctest/profiler-extension.cc
new file mode 100644 (file)
index 0000000..7b0b099
--- /dev/null
@@ -0,0 +1,72 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Tests of profiles generator and utilities.
+
+#include "profiler-extension.h"
+
+#include "cctest.h"
+
+const v8::CpuProfile* ProfilerExtension::last_profile = NULL;
+const char* ProfilerExtension::kSource =
+    "native function startProfiling();"
+    "native function stopProfiling();";
+
+v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate(
+    v8::Isolate* isolate, v8::Handle<v8::String> name) {
+  if (name->Equals(v8::String::NewFromUtf8(isolate, "startProfiling"))) {
+    return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling);
+  } else if (name->Equals(v8::String::NewFromUtf8(isolate, "stopProfiling"))) {
+    return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling);
+  } else {
+    CHECK(false);
+    return v8::Handle<v8::FunctionTemplate>();
+  }
+}
+
+
+void ProfilerExtension::StartProfiling(
+    const v8::FunctionCallbackInfo<v8::Value>& args) {
+  last_profile = NULL;
+  v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
+  cpu_profiler->StartCpuProfiling((args.Length() > 0)
+      ? args[0].As<v8::String>()
+      : v8::String::Empty(args.GetIsolate()));
+}
+
+
+void ProfilerExtension::StopProfiling(
+    const v8::FunctionCallbackInfo<v8::Value>& args) {
+  v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
+  last_profile = cpu_profiler->StopCpuProfiling((args.Length() > 0)
+      ? args[0].As<v8::String>()
+      : v8::String::Empty(args.GetIsolate()));
+}
+
+
+static ProfilerExtension kProfilerExtension;
+v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension);
diff --git a/test/cctest/profiler-extension.h b/test/cctest/profiler-extension.h
new file mode 100644 (file)
index 0000000..5d36f4f
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Tests of profiles generator and utilities.
+
+#include "v8-profiler.h"
+
+class ProfilerExtension : public v8::Extension {
+ public:
+  ProfilerExtension() : v8::Extension("v8/profiler", kSource) { }
+  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
+      v8::Isolate* isolate,
+      v8::Handle<v8::String> name);
+  static void StartProfiling(const v8::FunctionCallbackInfo<v8::Value>& args);
+  static void StopProfiling(const v8::FunctionCallbackInfo<v8::Value>& args);
+  static const v8::CpuProfile* last_profile;
+ private:
+  static const char* kSource;
+};
index 91f3736..bb85bd9 100644 (file)
@@ -94,7 +94,7 @@ void RunWithProfiler(void (*test)()) {
 
   cpu_profiler->StartCpuProfiling(profile_name);
   (*test)();
-  cpu_profiler->DeleteAllCpuProfiles();
+  reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles();
 }
 
 
index 6703ada..604f01e 100644 (file)
@@ -31,6 +31,7 @@
 #include "cpu-profiler-inl.h"
 #include "cctest.h"
 #include "platform.h"
+#include "profiler-extension.h"
 #include "smart-pointers.h"
 #include "utils.h"
 #include "../include/v8-profiler.h"
@@ -138,7 +139,7 @@ TEST(CodeEvents) {
   i::Code* args4_code = CreateCode(&env);
 
   CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
-  profiles->StartProfiling("", 1, false);
+  profiles->StartProfiling("", false);
   ProfileGenerator generator(profiles);
   SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
           &generator, NULL, TimeDelta::FromMicroseconds(100)));
@@ -200,7 +201,7 @@ TEST(TickEvents) {
   i::Code* frame3_code = CreateCode(&env);
 
   CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
-  profiles->StartProfiling("", 1, false);
+  profiles->StartProfiling("", false);
   ProfileGenerator generator(profiles);
   SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
           &generator, NULL, TimeDelta::FromMicroseconds(100)));
@@ -269,7 +270,7 @@ TEST(Issue1398) {
   i::Code* code = CreateCode(&env);
 
   CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap());
-  profiles->StartProfiling("", 1, false);
+  profiles->StartProfiling("", false);
   ProfileGenerator generator(profiles);
   SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor(
           &generator, NULL, TimeDelta::FromMicroseconds(100)));
@@ -332,16 +333,17 @@ TEST(DeleteAllCpuProfiles) {
 }
 
 
-static const v8::CpuProfile* FindCpuProfile(v8::CpuProfiler* profiler,
-                                            unsigned uid) {
-  int length = profiler->GetProfileCount();
+static bool FindCpuProfile(v8::CpuProfiler* v8profiler,
+                           const v8::CpuProfile* v8profile) {
+  i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(v8profiler);
+  const i::CpuProfile* profile =
+      reinterpret_cast<const i::CpuProfile*>(v8profile);
+  int length = profiler->GetProfilesCount();
   for (int i = 0; i < length; i++) {
-    const v8::CpuProfile* profile = profiler->GetCpuProfile(i);
-    if (profile->GetUid() == uid) {
-      return profile;
-    }
+    if (profile == profiler->GetProfile(i))
+      return true;
   }
-  return NULL;
+  return false;
 }
 
 
@@ -349,46 +351,38 @@ TEST(DeleteCpuProfile) {
   LocalContext env;
   v8::HandleScope scope(env->GetIsolate());
   v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
+  i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler);
 
-  CHECK_EQ(0, cpu_profiler->GetProfileCount());
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
   v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1");
   cpu_profiler->StartCpuProfiling(name1);
   const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
   CHECK_NE(NULL, p1);
-  CHECK_EQ(1, cpu_profiler->GetProfileCount());
-  unsigned uid1 = p1->GetUid();
-  CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1));
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
+  CHECK(FindCpuProfile(cpu_profiler, p1));
   const_cast<v8::CpuProfile*>(p1)->Delete();
-  CHECK_EQ(0, cpu_profiler->GetProfileCount());
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
 
   v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2");
   cpu_profiler->StartCpuProfiling(name2);
   const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2);
   CHECK_NE(NULL, p2);
-  CHECK_EQ(1, cpu_profiler->GetProfileCount());
-  unsigned uid2 = p2->GetUid();
-  CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
-  CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2));
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
+  CHECK(FindCpuProfile(cpu_profiler, p2));
   v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3");
   cpu_profiler->StartCpuProfiling(name3);
   const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
   CHECK_NE(NULL, p3);
-  CHECK_EQ(2, cpu_profiler->GetProfileCount());
-  unsigned uid3 = p3->GetUid();
-  CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
-  CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3));
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
+  CHECK_EQ(2, iprofiler->GetProfilesCount());
+  CHECK_NE(p2, p3);
+  CHECK(FindCpuProfile(cpu_profiler, p3));
+  CHECK(FindCpuProfile(cpu_profiler, p2));
   const_cast<v8::CpuProfile*>(p2)->Delete();
-  CHECK_EQ(1, cpu_profiler->GetProfileCount());
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2));
-  CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3));
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
+  CHECK(!FindCpuProfile(cpu_profiler, p2));
+  CHECK(FindCpuProfile(cpu_profiler, p3));
   const_cast<v8::CpuProfile*>(p3)->Delete();
-  CHECK_EQ(0, cpu_profiler->GetProfileCount());
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3));
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2));
-  CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1));
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
 }
 
 
@@ -589,8 +583,7 @@ TEST(CollectCpuProfile) {
   CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch,
                     ARRAY_SIZE(delayBranch));
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -657,8 +650,7 @@ TEST(SampleWhenFrameIsNotSetup) {
     }
   }
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -759,8 +751,7 @@ TEST(NativeAccessorUninitializedIC) {
   GetChild(env->GetIsolate(), startNode, "get foo");
   GetChild(env->GetIsolate(), startNode, "set foo");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -814,8 +805,7 @@ TEST(NativeAccessorMonomorphicIC) {
   GetChild(env->GetIsolate(), startNode, "get foo");
   GetChild(env->GetIsolate(), startNode, "set foo");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -865,8 +855,7 @@ TEST(NativeMethodUninitializedIC) {
       GetChild(env->GetIsolate(), root, "start");
   GetChild(env->GetIsolate(), startNode, "fooMethod");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -919,8 +908,7 @@ TEST(NativeMethodMonomorphicIC) {
       GetChild(env->GetIsolate(), root, "start");
   GetChild(env->GetIsolate(), startNode, "fooMethod");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -967,8 +955,7 @@ TEST(BoundFunctionCall) {
       GetChild(env->GetIsolate(), root, "start");
   GetChild(env->GetIsolate(), startNode, "foo");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1049,8 +1036,7 @@ TEST(FunctionCallSample) {
     CheckChildrenNames(unresolvedNode, names);
   }
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1137,8 +1123,7 @@ TEST(FunctionApplySample) {
     }
   }
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1226,8 +1211,7 @@ TEST(JsNativeJsSample) {
   CHECK_EQ(1, barNode->GetChildrenCount());
   GetChild(env->GetIsolate(), barNode, "foo");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1309,8 +1293,7 @@ TEST(JsNativeJsRuntimeJsSample) {
   CHECK_EQ(1, barNode->GetChildrenCount());
   GetChild(env->GetIsolate(), barNode, "foo");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1407,8 +1390,7 @@ TEST(JsNative1JsNative2JsSample) {
   CHECK_EQ(1, nativeNode2->GetChildrenCount());
   GetChild(env->GetIsolate(), nativeNode2, "foo");
 
-  v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1465,7 +1447,7 @@ TEST(IdleTime) {
   CHECK_EQ(0, idleNode->GetChildrenCount());
   CHECK_GE(idleNode->GetHitCount(), 3);
 
-  cpu_profiler->DeleteAllCpuProfiles();
+  const_cast<v8::CpuProfile*>(profile)->Delete();
 }
 
 
@@ -1489,8 +1471,6 @@ TEST(FunctionDetails) {
   LocalContext env(&config);
   v8::HandleScope handleScope(env->GetIsolate());
 
-  v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
-  CHECK_EQ(0, profiler->GetProfileCount());
   v8::Handle<v8::Script> script_a = v8::Script::Compile(
       v8::String::NewFromUtf8(
           env->GetIsolate(),
@@ -1506,8 +1486,7 @@ TEST(FunctionDetails) {
           "stopProfiling();\n"),
       v8::String::NewFromUtf8(env->GetIsolate(), "script_b"));
   script_b->Run();
-  CHECK_EQ(1, profiler->GetProfileCount());
-  const v8::CpuProfile* profile = profiler->GetCpuProfile(0);
+  const v8::CpuProfile* profile = ProfilerExtension::last_profile;
   const v8::CpuProfileNode* current = profile->GetTopDownRoot();
   reinterpret_cast<ProfileNode*>(
       const_cast<v8::CpuProfileNode*>(current))->Print(0);
@@ -1543,27 +1522,28 @@ TEST(DontStopOnFinishedProfileDelete) {
   v8::HandleScope handleScope(isolate);
 
   v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
+  i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
 
-  CHECK_EQ(0, profiler->GetProfileCount());
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
   v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer");
   profiler->StartCpuProfiling(outer);
-  CHECK_EQ(0, profiler->GetProfileCount());
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
 
   v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner");
   profiler->StartCpuProfiling(inner);
-  CHECK_EQ(0, profiler->GetProfileCount());
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
 
   const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(inner);
   CHECK(inner_profile);
-  CHECK_EQ(1, profiler->GetProfileCount());
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
   const_cast<v8::CpuProfile*>(inner_profile)->Delete();
   inner_profile = NULL;
-  CHECK_EQ(0, profiler->GetProfileCount());
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
 
   const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer);
   CHECK(outer_profile);
-  CHECK_EQ(1, profiler->GetProfileCount());
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
   const_cast<v8::CpuProfile*>(outer_profile)->Delete();
   outer_profile = NULL;
-  CHECK_EQ(0, profiler->GetProfileCount());
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
 }
index 54791e2..0cd30ef 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "v8.h"
 #include "profile-generator-inl.h"
+#include "profiler-extension.h"
 #include "cctest.h"
 #include "cpu-profiler.h"
 #include "../include/v8-profiler.h"
@@ -400,7 +401,7 @@ class TestSetup {
 TEST(RecordTickSample) {
   TestSetup test_setup;
   CpuProfilesCollection profiles(CcTest::heap());
-  profiles.StartProfiling("", 1, false);
+  profiles.StartProfiling("", false);
   ProfileGenerator generator(&profiles);
   CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
   CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb");
@@ -466,7 +467,7 @@ static void CheckNodeIds(ProfileNode* node, int* expectedId) {
 TEST(SampleIds) {
   TestSetup test_setup;
   CpuProfilesCollection profiles(CcTest::heap());
-  profiles.StartProfiling("", 1, true);
+  profiles.StartProfiling("", true);
   ProfileGenerator generator(&profiles);
   CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
   CodeEntry* entry2 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb");
@@ -514,7 +515,7 @@ TEST(SampleIds) {
 TEST(NoSamples) {
   TestSetup test_setup;
   CpuProfilesCollection profiles(CcTest::heap());
-  profiles.StartProfiling("", 1, false);
+  profiles.StartProfiling("", false);
   ProfileGenerator generator(&profiles);
   CodeEntry* entry1 = profiles.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
   generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
@@ -536,63 +537,6 @@ TEST(NoSamples) {
 }
 
 
-// --- P r o f i l e r   E x t e n s i o n ---
-
-class ProfilerExtension : public v8::Extension {
- public:
-  ProfilerExtension() : v8::Extension("v8/profiler", kSource) { }
-  virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
-      v8::Isolate* isolate,
-      v8::Handle<v8::String> name);
-  static void StartProfiling(const v8::FunctionCallbackInfo<v8::Value>& args);
-  static void StopProfiling(const v8::FunctionCallbackInfo<v8::Value>& args);
- private:
-  static const char* kSource;
-};
-
-
-const char* ProfilerExtension::kSource =
-    "native function startProfiling();"
-    "native function stopProfiling();";
-
-v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate(
-    v8::Isolate* isolate, v8::Handle<v8::String> name) {
-  if (name->Equals(v8::String::NewFromUtf8(isolate, "startProfiling"))) {
-    return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling);
-  } else if (name->Equals(v8::String::NewFromUtf8(isolate, "stopProfiling"))) {
-    return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling);
-  } else {
-    CHECK(false);
-    return v8::Handle<v8::FunctionTemplate>();
-  }
-}
-
-
-void ProfilerExtension::StartProfiling(
-    const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
-  if (args.Length() > 0)
-    cpu_profiler->StartCpuProfiling(args[0].As<v8::String>());
-  else
-    cpu_profiler->StartCpuProfiling(
-        v8::String::NewFromUtf8(args.GetIsolate(), ""));
-}
-
-
-void ProfilerExtension::StopProfiling(
-    const v8::FunctionCallbackInfo<v8::Value>& args) {
-  v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
-  if (args.Length() > 0)
-    cpu_profiler->StopCpuProfiling(args[0].As<v8::String>());
-  else
-    cpu_profiler->StopCpuProfiling(
-        v8::String::NewFromUtf8(args.GetIsolate(), ""));
-}
-
-
-static ProfilerExtension kProfilerExtension;
-v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension);
-
 static const ProfileNode* PickChild(const ProfileNode* parent,
                                     const char* name) {
   for (int i = 0; i < parent->children()->length(); ++i) {
@@ -661,12 +605,10 @@ TEST(Issue51919) {
   for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) {
     i::Vector<char> title = i::Vector<char>::New(16);
     i::OS::SNPrintF(title, "%d", i);
-    // UID must be > 0.
-    CHECK(collection.StartProfiling(title.start(), i + 1, false));
+    CHECK(collection.StartProfiling(title.start(), false));
     titles[i] = title.start();
   }
-  CHECK(!collection.StartProfiling(
-      "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false));
+  CHECK(!collection.StartProfiling("maximum", false));
   for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i)
     i::DeleteArray(titles[i]);
 }
@@ -694,7 +636,8 @@ TEST(ProfileNodeScriptId) {
   v8::HandleScope hs(env->GetIsolate());
 
   v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
-  CHECK_EQ(0, profiler->GetProfileCount());
+  i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
   v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::NewFromUtf8(
       env->GetIsolate(), "function a() { startProfiling(); }\n"));
   script_a->Run();
@@ -704,8 +647,8 @@ TEST(ProfileNodeScriptId) {
                                                   "b();\n"
                                                   "stopProfiling();\n"));
   script_b->Run();
-  CHECK_EQ(1, profiler->GetProfileCount());
-  const v8::CpuProfile* profile = profiler->GetCpuProfile(0);
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
+  const v8::CpuProfile* profile = ProfilerExtension::last_profile;
   const v8::CpuProfileNode* current = profile->GetTopDownRoot();
   reinterpret_cast<ProfileNode*>(
       const_cast<v8::CpuProfileNode*>(current))->Print(0);
@@ -796,7 +739,8 @@ TEST(BailoutReason) {
   v8::HandleScope hs(env->GetIsolate());
 
   v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
-  CHECK_EQ(0, profiler->GetProfileCount());
+  i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
+  CHECK_EQ(0, iprofiler->GetProfilesCount());
   v8::Handle<v8::Script> script =
       v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
                                                   "function TryCatch() {\n"
@@ -812,8 +756,9 @@ TEST(BailoutReason) {
                                                   "TryFinally();\n"
                                                   "stopProfiling();"));
   script->Run();
-  CHECK_EQ(1, profiler->GetProfileCount());
-  const v8::CpuProfile* profile = profiler->GetCpuProfile(0);
+  CHECK_EQ(1, iprofiler->GetProfilesCount());
+  const v8::CpuProfile* profile = ProfilerExtension::last_profile;
+  CHECK(profile);
   const v8::CpuProfileNode* current = profile->GetTopDownRoot();
   reinterpret_cast<ProfileNode*>(
       const_cast<v8::CpuProfileNode*>(current))->Print(0);