From 19b6b7ada8a3310e3061af113de3e3ac7eed6084 Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Wed, 18 Dec 2013 08:59:09 +0000 Subject: [PATCH] Delete several deprecated methods on v8::CpuProfiler 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 --- include/v8-profiler.h | 19 ------ src/api.cc | 21 ------ src/cpu-profiler.cc | 4 +- src/cpu-profiler.h | 1 - src/profile-generator.cc | 10 ++- src/profile-generator.h | 6 +- test/cctest/cctest.gyp | 1 + test/cctest/profiler-extension.cc | 72 ++++++++++++++++++++ test/cctest/profiler-extension.h | 43 ++++++++++++ test/cctest/test-api.cc | 2 +- test/cctest/test-cpu-profiler.cc | 120 ++++++++++++++-------------------- test/cctest/test-profile-generator.cc | 85 +++++------------------- 12 files changed, 189 insertions(+), 195 deletions(-) create mode 100644 test/cctest/profiler-extension.cc create mode 100644 test/cctest/profiler-extension.h diff --git a/include/v8-profiler.h b/include/v8-profiler.h index d933af6..e88f472 100644 --- a/include/v8-profiler.h +++ b/include/v8-profiler.h @@ -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 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 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); diff --git a/src/api.cc b/src/api.cc index 3572265..c470f84 100644 --- a/src/api.cc +++ b/src/api.cc @@ -6963,11 +6963,6 @@ void CpuProfile::Delete() { } -unsigned CpuProfile::GetUid() const { - return reinterpret_cast(this)->uid(); -} - - Handle CpuProfile::GetTitle() const { i::Isolate* isolate = i::Isolate::Current(); const i::CpuProfile* profile = reinterpret_cast(this); @@ -7005,11 +7000,6 @@ int CpuProfile::GetSamplesCount() const { } -int CpuProfiler::GetProfileCount() { - return reinterpret_cast(this)->GetProfilesCount(); -} - - void CpuProfiler::SetSamplingInterval(int us) { ASSERT(us >= 0); return reinterpret_cast(this)->set_sampling_interval( @@ -7017,12 +7007,6 @@ void CpuProfiler::SetSamplingInterval(int us) { } -const CpuProfile* CpuProfiler::GetCpuProfile(int index) { - return reinterpret_cast( - reinterpret_cast(this)->GetProfile(index)); -} - - void CpuProfiler::StartCpuProfiling(Handle title, bool record_samples) { reinterpret_cast(this)->StartProfiling( *Utils::OpenHandle(*title), record_samples); @@ -7036,11 +7020,6 @@ const CpuProfile* CpuProfiler::StopCpuProfiling(Handle title) { } -void CpuProfiler::DeleteAllCpuProfiles() { - reinterpret_cast(this)->DeleteAllProfiles(); -} - - void CpuProfiler::SetIdle(bool is_idle) { i::Isolate* isolate = reinterpret_cast(this)->isolate(); i::StateTag state = isolate->current_vm_state(); diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc index ef39341..c36850c 100644 --- a/src/cpu-profiler.cc +++ b/src/cpu-profiler.cc @@ -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_); diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h index fcb9a67..53f00ff 100644 --- a/src/cpu-profiler.h +++ b/src/cpu-profiler.h @@ -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_; diff --git a/src/profile-generator.cc b/src/profile-generator.cc index acf54da..30783c6 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -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; } diff --git a/src/profile-generator.h b/src/profile-generator.h index 6e4758b..81980bf 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -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& 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* profiles() { return &finished_profiles_; } const char* GetName(Name* name) { diff --git a/test/cctest/cctest.gyp b/test/cctest/cctest.gyp index 2017d61..af1183f 100644 --- a/test/cctest/cctest.gyp +++ b/test/cctest/cctest.gyp @@ -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 index 0000000..7b0b099 --- /dev/null +++ b/test/cctest/profiler-extension.cc @@ -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 ProfilerExtension::GetNativeFunctionTemplate( + v8::Isolate* isolate, v8::Handle 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(); + } +} + + +void ProfilerExtension::StartProfiling( + const v8::FunctionCallbackInfo& args) { + last_profile = NULL; + v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); + cpu_profiler->StartCpuProfiling((args.Length() > 0) + ? args[0].As() + : v8::String::Empty(args.GetIsolate())); +} + + +void ProfilerExtension::StopProfiling( + const v8::FunctionCallbackInfo& args) { + v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); + last_profile = cpu_profiler->StopCpuProfiling((args.Length() > 0) + ? args[0].As() + : 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 index 0000000..5d36f4f --- /dev/null +++ b/test/cctest/profiler-extension.h @@ -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 GetNativeFunctionTemplate( + v8::Isolate* isolate, + v8::Handle name); + static void StartProfiling(const v8::FunctionCallbackInfo& args); + static void StopProfiling(const v8::FunctionCallbackInfo& args); + static const v8::CpuProfile* last_profile; + private: + static const char* kSource; +}; diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 91f3736..bb85bd9 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -94,7 +94,7 @@ void RunWithProfiler(void (*test)()) { cpu_profiler->StartCpuProfiling(profile_name); (*test)(); - cpu_profiler->DeleteAllCpuProfiles(); + reinterpret_cast(cpu_profiler)->DeleteAllProfiles(); } diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index 6703ada..604f01e 100644 --- a/test/cctest/test-cpu-profiler.cc +++ b/test/cctest/test-cpu-profiler.cc @@ -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 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 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 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(v8profiler); + const i::CpuProfile* profile = + reinterpret_cast(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(cpu_profiler); - CHECK_EQ(0, cpu_profiler->GetProfileCount()); + CHECK_EQ(0, iprofiler->GetProfilesCount()); v8::Local 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(p1)->Delete(); - CHECK_EQ(0, cpu_profiler->GetProfileCount()); - CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); + CHECK_EQ(0, iprofiler->GetProfilesCount()); v8::Local 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(uid1), static_cast(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 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(uid1), static_cast(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(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(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(profile)->Delete(); } @@ -657,8 +650,7 @@ TEST(SampleWhenFrameIsNotSetup) { } } - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); - cpu_profiler->DeleteAllCpuProfiles(); + const_cast(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(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(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(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(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(profile)->Delete(); } @@ -1049,8 +1036,7 @@ TEST(FunctionCallSample) { CheckChildrenNames(unresolvedNode, names); } - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); - cpu_profiler->DeleteAllCpuProfiles(); + const_cast(profile)->Delete(); } @@ -1137,8 +1123,7 @@ TEST(FunctionApplySample) { } } - v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); - cpu_profiler->DeleteAllCpuProfiles(); + const_cast(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(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(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(profile)->Delete(); } @@ -1465,7 +1447,7 @@ TEST(IdleTime) { CHECK_EQ(0, idleNode->GetChildrenCount()); CHECK_GE(idleNode->GetHitCount(), 3); - cpu_profiler->DeleteAllCpuProfiles(); + const_cast(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 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( const_cast(current))->Print(0); @@ -1543,27 +1522,28 @@ TEST(DontStopOnFinishedProfileDelete) { v8::HandleScope handleScope(isolate); v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); + i::CpuProfiler* iprofiler = reinterpret_cast(profiler); - CHECK_EQ(0, profiler->GetProfileCount()); + CHECK_EQ(0, iprofiler->GetProfilesCount()); v8::Handle outer = v8::String::NewFromUtf8(isolate, "outer"); profiler->StartCpuProfiling(outer); - CHECK_EQ(0, profiler->GetProfileCount()); + CHECK_EQ(0, iprofiler->GetProfilesCount()); v8::Handle 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(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(outer_profile)->Delete(); outer_profile = NULL; - CHECK_EQ(0, profiler->GetProfileCount()); + CHECK_EQ(0, iprofiler->GetProfilesCount()); } diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc index 54791e2..0cd30ef 100644 --- a/test/cctest/test-profile-generator.cc +++ b/test/cctest/test-profile-generator.cc @@ -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 GetNativeFunctionTemplate( - v8::Isolate* isolate, - v8::Handle name); - static void StartProfiling(const v8::FunctionCallbackInfo& args); - static void StopProfiling(const v8::FunctionCallbackInfo& args); - private: - static const char* kSource; -}; - - -const char* ProfilerExtension::kSource = - "native function startProfiling();" - "native function stopProfiling();"; - -v8::Handle ProfilerExtension::GetNativeFunctionTemplate( - v8::Isolate* isolate, v8::Handle 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(); - } -} - - -void ProfilerExtension::StartProfiling( - const v8::FunctionCallbackInfo& args) { - v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); - if (args.Length() > 0) - cpu_profiler->StartCpuProfiling(args[0].As()); - else - cpu_profiler->StartCpuProfiling( - v8::String::NewFromUtf8(args.GetIsolate(), "")); -} - - -void ProfilerExtension::StopProfiling( - const v8::FunctionCallbackInfo& args) { - v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); - if (args.Length() > 0) - cpu_profiler->StopCpuProfiling(args[0].As()); - 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 title = i::Vector::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(profiler); + CHECK_EQ(0, iprofiler->GetProfilesCount()); v8::Handle 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( const_cast(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(profiler); + CHECK_EQ(0, iprofiler->GetProfilesCount()); v8::Handle 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( const_cast(current))->Print(0); -- 2.7.4