From 9974d932b29bdb97b777a97a77e94d2ad38300eb Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Tue, 28 May 2013 08:00:16 +0000 Subject: [PATCH] Deprecate profiler methods that accept security origin Now that the only known client console.profiles was removed from Blink: https://src.chromium.org/viewvc/blink?revision=151136&view=revision https://src.chromium.org/viewvc/blink?revision=151196&view=revision this method can be deprecated and all the code that supports filtering CPU profiles based on security origins can be later removed. Drive-by fix: in line with CpuProfiler changes deprecated HeapProfiler::FindHeapSnapshot to reduce v8 API surface. FindHeapSnapshot may well be implemented based on existing GetSnapshotCount/GetSnapshot and it is only used in the tests. BUG=None R=jkummerow@chromium.org, loislo@chromium.org Review URL: https://codereview.chromium.org/16114002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14833 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8-profiler.h | 24 +++++++++++++++--------- src/api.cc | 14 ++++++++++++++ test/cctest/test-cpu-profiler.cc | 37 ++++++++++++++++++++++++++----------- test/cctest/test-heap-profiler.cc | 27 ++++++++++++++++++++------- 4 files changed, 75 insertions(+), 27 deletions(-) diff --git a/include/v8-profiler.h b/include/v8-profiler.h index bc50b6f..d740df3 100644 --- a/include/v8-profiler.h +++ b/include/v8-profiler.h @@ -184,19 +184,21 @@ class V8EXPORT CpuProfiler { V8_DEPRECATED(static const CpuProfile* GetProfile( int index, Handle security_token = Handle())); - /** Returns a profile by index. */ - const CpuProfile* GetCpuProfile( + /** Deprecated. Use GetCpuProfile with single parameter. */ + V8_DEPRECATED(const CpuProfile* GetCpuProfile( int index, - Handle security_token = Handle()); + Handle security_token)); + /** Returns a profile by index. */ + const CpuProfile* GetCpuProfile(int index); /** Deprecated. Use FindProfile instead. */ V8_DEPRECATED(static const CpuProfile* FindProfile( unsigned uid, Handle security_token = Handle())); /** Returns a profile by uid. */ - const CpuProfile* FindCpuProfile( + V8_DEPRECATED(const CpuProfile* FindCpuProfile( unsigned uid, - Handle security_token = Handle()); + Handle security_token = Handle())); /** Deprecated. Use StartCpuProfiling instead. */ V8_DEPRECATED(static void StartProfiling(Handle title, @@ -219,12 +221,16 @@ class V8EXPORT CpuProfiler { Handle title, Handle security_token = Handle())); /** + * Deprecated. Use StopCpuProfiling with one parameter instead. + */ + V8_DEPRECATED(const CpuProfile* StopCpuProfiling( + Handle title, + Handle security_token)); + /** * Stops collecting CPU profile with a given title and returns it. * If the title given is empty, finishes the last profile started. */ - const CpuProfile* StopCpuProfiling( - Handle title, - Handle security_token = Handle()); + const CpuProfile* StopCpuProfiling(Handle title); /** Deprecated. Use DeleteAllCpuProfiles instead. */ V8_DEPRECATED(static void DeleteAllProfiles()); @@ -438,7 +444,7 @@ class V8EXPORT HeapProfiler { /** Deprecated. Use FindHeapSnapshot instead. */ V8_DEPRECATED(static const HeapSnapshot* FindSnapshot(unsigned uid)); /** Returns a profile by uid. */ - const HeapSnapshot* FindHeapSnapshot(unsigned uid); + V8_DEPRECATED(const HeapSnapshot* FindHeapSnapshot(unsigned uid)); /** Deprecated. Use GetObjectId instead. */ V8_DEPRECATED(static SnapshotObjectId GetSnapshotObjectId( diff --git a/src/api.cc b/src/api.cc index b2ded30..a5ef054 100644 --- a/src/api.cc +++ b/src/api.cc @@ -7243,6 +7243,12 @@ const CpuProfile* CpuProfiler::GetCpuProfile(int index, } +const CpuProfile* CpuProfiler::GetCpuProfile(int index) { + return reinterpret_cast( + reinterpret_cast(this)->GetProfile(NULL, index)); +} + + const CpuProfile* CpuProfiler::FindProfile(unsigned uid, Handle security_token) { i::Isolate* isolate = i::Isolate::Current(); @@ -7302,6 +7308,14 @@ const CpuProfile* CpuProfiler::StopCpuProfiling(Handle title, } +const CpuProfile* CpuProfiler::StopCpuProfiling(Handle title) { + return reinterpret_cast( + reinterpret_cast(this)->StopProfiling( + NULL, + *Utils::OpenHandle(*title))); +} + + void CpuProfiler::DeleteAllProfiles() { i::Isolate* isolate = i::Isolate::Current(); IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles"); diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc index be745c8..3eebf96 100644 --- a/test/cctest/test-cpu-profiler.cc +++ b/test/cctest/test-cpu-profiler.cc @@ -31,11 +31,13 @@ #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT +#define V8_DISABLE_DEPRECATIONS 1 #include "v8.h" #include "cpu-profiler-inl.h" #include "cctest.h" #include "utils.h" #include "../include/v8-profiler.h" +#undef V8_DISABLE_DEPRECATIONS using i::CodeEntry; using i::CpuProfile; @@ -297,6 +299,19 @@ TEST(DeleteAllCpuProfiles) { } +static const v8::CpuProfile* FindCpuProfile(v8::CpuProfiler* profiler, + unsigned uid) { + int length = profiler->GetProfileCount(); + for (int i = 0; i < length; i++) { + const v8::CpuProfile* profile = profiler->GetCpuProfile(i); + if (profile->GetUid() == uid) { + return profile; + } + } + return NULL; +} + + TEST(DeleteCpuProfile) { LocalContext env; v8::HandleScope scope(env->GetIsolate()); @@ -309,10 +324,10 @@ TEST(DeleteCpuProfile) { CHECK_NE(NULL, p1); CHECK_EQ(1, cpu_profiler->GetProfileCount()); unsigned uid1 = p1->GetUid(); - CHECK_EQ(p1, cpu_profiler->FindCpuProfile(uid1)); + CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1)); const_cast(p1)->Delete(); CHECK_EQ(0, cpu_profiler->GetProfileCount()); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); v8::Local name2 = v8::String::New("2"); cpu_profiler->StartCpuProfiling(name2); @@ -321,8 +336,8 @@ TEST(DeleteCpuProfile) { CHECK_EQ(1, cpu_profiler->GetProfileCount()); unsigned uid2 = p2->GetUid(); CHECK_NE(static_cast(uid1), static_cast(uid2)); - CHECK_EQ(p2, cpu_profiler->FindCpuProfile(uid2)); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1)); + CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); v8::Local name3 = v8::String::New("3"); cpu_profiler->StartCpuProfiling(name3); const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); @@ -330,17 +345,17 @@ TEST(DeleteCpuProfile) { CHECK_EQ(2, cpu_profiler->GetProfileCount()); unsigned uid3 = p3->GetUid(); CHECK_NE(static_cast(uid1), static_cast(uid3)); - CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3)); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1)); + CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); const_cast(p2)->Delete(); CHECK_EQ(1, cpu_profiler->GetProfileCount()); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2)); - CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); + CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); const_cast(p3)->Delete(); CHECK_EQ(0, cpu_profiler->GetProfileCount()); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid3)); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2)); - CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); + CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); } diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 595a206..9b53879 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -1285,6 +1285,19 @@ TEST(DeleteAllHeapSnapshots) { } +static const v8::HeapSnapshot* FindHeapSnapshot(v8::HeapProfiler* profiler, + unsigned uid) { + int length = profiler->GetSnapshotCount(); + for (int i = 0; i < length; i++) { + const v8::HeapSnapshot* snapshot = profiler->GetHeapSnapshot(i); + if (snapshot->GetUid() == uid) { + return snapshot; + } + } + return NULL; +} + + TEST(DeleteHeapSnapshot) { LocalContext env; v8::HandleScope scope(env->GetIsolate()); @@ -1296,10 +1309,10 @@ TEST(DeleteHeapSnapshot) { CHECK_NE(NULL, s1); CHECK_EQ(1, heap_profiler->GetSnapshotCount()); unsigned uid1 = s1->GetUid(); - CHECK_EQ(s1, heap_profiler->FindHeapSnapshot(uid1)); + CHECK_EQ(s1, FindHeapSnapshot(heap_profiler, uid1)); const_cast(s1)->Delete(); CHECK_EQ(0, heap_profiler->GetSnapshotCount()); - CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid1)); + CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid1)); const v8::HeapSnapshot* s2 = heap_profiler->TakeHeapSnapshot(v8_str("2")); @@ -1307,21 +1320,21 @@ TEST(DeleteHeapSnapshot) { CHECK_EQ(1, heap_profiler->GetSnapshotCount()); unsigned uid2 = s2->GetUid(); CHECK_NE(static_cast(uid1), static_cast(uid2)); - CHECK_EQ(s2, heap_profiler->FindHeapSnapshot(uid2)); + CHECK_EQ(s2, FindHeapSnapshot(heap_profiler, uid2)); const v8::HeapSnapshot* s3 = heap_profiler->TakeHeapSnapshot(v8_str("3")); CHECK_NE(NULL, s3); CHECK_EQ(2, heap_profiler->GetSnapshotCount()); unsigned uid3 = s3->GetUid(); CHECK_NE(static_cast(uid1), static_cast(uid3)); - CHECK_EQ(s3, heap_profiler->FindHeapSnapshot(uid3)); + CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3)); const_cast(s2)->Delete(); CHECK_EQ(1, heap_profiler->GetSnapshotCount()); - CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid2)); - CHECK_EQ(s3, heap_profiler->FindHeapSnapshot(uid3)); + CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid2)); + CHECK_EQ(s3, FindHeapSnapshot(heap_profiler, uid3)); const_cast(s3)->Delete(); CHECK_EQ(0, heap_profiler->GetSnapshotCount()); - CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid3)); + CHECK_EQ(NULL, FindHeapSnapshot(heap_profiler, uid3)); } -- 2.7.4