Revision: 18337
Author: [email protected]
Date: Wed Dec 18 08:59:09 2013 UTC
Log: 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
[email protected]
Review URL: https://codereview.chromium.org/117353002
http://code.google.com/p/v8/source/detail?r=18337
Added:
/branches/bleeding_edge/test/cctest/profiler-extension.cc
/branches/bleeding_edge/test/cctest/profiler-extension.h
Modified:
/branches/bleeding_edge/include/v8-profiler.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/cpu-profiler.cc
/branches/bleeding_edge/src/cpu-profiler.h
/branches/bleeding_edge/src/profile-generator.cc
/branches/bleeding_edge/src/profile-generator.h
/branches/bleeding_edge/test/cctest/cctest.gyp
/branches/bleeding_edge/test/cctest/test-api.cc
/branches/bleeding_edge/test/cctest/test-cpu-profiler.cc
/branches/bleeding_edge/test/cctest/test-profile-generator.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/cctest/profiler-extension.cc Wed Dec 18
08:59:09 2013 UTC
@@ -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);
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/cctest/profiler-extension.h Wed Dec 18
08:59:09 2013 UTC
@@ -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;
+};
=======================================
--- /branches/bleeding_edge/include/v8-profiler.h Wed Dec 18 08:17:03 2013
UTC
+++ /branches/bleeding_edge/include/v8-profiler.h Wed Dec 18 08:59:09 2013
UTC
@@ -96,9 +96,6 @@
*/
class V8_EXPORT CpuProfile {
public:
- /** Returns CPU profile UID (assigned by the profiler.) */
- unsigned GetUid() const;
-
/** Returns CPU profile title. */
Handle<String> GetTitle() const;
@@ -150,15 +147,6 @@
*/
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
@@ -178,13 +166,6 @@
*/
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.
*/
=======================================
--- /branches/bleeding_edge/src/api.cc Wed Dec 18 08:17:03 2013 UTC
+++ /branches/bleeding_edge/src/api.cc Wed Dec 18 08:59:09 2013 UTC
@@ -6961,11 +6961,6 @@
ASSERT(profiler != NULL);
profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
}
-
-
-unsigned CpuProfile::GetUid() const {
- return reinterpret_cast<const i::CpuProfile*>(this)->uid();
-}
Handle<String> CpuProfile::GetTitle() const {
@@ -7003,11 +6998,6 @@
int CpuProfile::GetSamplesCount() const {
return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
}
-
-
-int CpuProfiler::GetProfileCount() {
- return reinterpret_cast<i::CpuProfiler*>(this)->GetProfilesCount();
-}
void CpuProfiler::SetSamplingInterval(int us) {
@@ -7015,12 +7005,6 @@
return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
i::TimeDelta::FromMicroseconds(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) {
@@ -7034,11 +7018,6 @@
reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
*Utils::OpenHandle(*title)));
}
-
-
-void CpuProfiler::DeleteAllCpuProfiles() {
- reinterpret_cast<i::CpuProfiler*>(this)->DeleteAllProfiles();
-}
void CpuProfiler::SetIdle(bool is_idle) {
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.cc Wed Dec 11 14:39:18 2013 UTC
+++ /branches/bleeding_edge/src/cpu-profiler.cc Wed Dec 18 08:59:09 2013 UTC
@@ -380,7 +380,6 @@
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 @@
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::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_);
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.h Thu Oct 10 13:15:47 2013 UTC
+++ /branches/bleeding_edge/src/cpu-profiler.h Wed Dec 18 08:59:09 2013 UTC
@@ -268,7 +268,6 @@
Isolate* isolate_;
TimeDelta sampling_interval_;
CpuProfilesCollection* profiles_;
- unsigned next_profile_uid_;
ProfileGenerator* generator_;
ProfilerEventsProcessor* processor_;
bool saved_is_logging_;
=======================================
--- /branches/bleeding_edge/src/profile-generator.cc Fri Oct 18 08:56:14
2013 UTC
+++ /branches/bleeding_edge/src/profile-generator.cc Wed Dec 18 08:59:09
2013 UTC
@@ -352,9 +352,8 @@
}
-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 @@
}
-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 @@
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 @@
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;
}
=======================================
--- /branches/bleeding_edge/src/profile-generator.h Fri Oct 18 08:56:14
2013 UTC
+++ /branches/bleeding_edge/src/profile-generator.h Wed Dec 18 08:59:09
2013 UTC
@@ -196,14 +196,13 @@
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 @@
private:
const char* title_;
- unsigned uid_;
bool record_samples_;
Time start_time_;
Time end_time_;
@@ -281,7 +279,7 @@
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) {
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.gyp Fri Nov 22 12:43:17 2013
UTC
+++ /branches/bleeding_edge/test/cctest/cctest.gyp Wed Dec 18 08:59:09 2013
UTC
@@ -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',
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Wed Dec 11 13:51:48
2013 UTC
+++ /branches/bleeding_edge/test/cctest/test-api.cc Wed Dec 18 08:59:09
2013 UTC
@@ -94,7 +94,7 @@
cpu_profiler->StartCpuProfiling(profile_name);
(*test)();
- cpu_profiler->DeleteAllCpuProfiles();
+ reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles();
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Wed Dec 11
14:39:18 2013 UTC
+++ /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Wed Dec 18
08:59:09 2013 UTC
@@ -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 @@
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 @@
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 @@
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 @@
}
-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 @@
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 @@
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 @@
}
}
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- cpu_profiler->DeleteAllCpuProfiles();
+ const_cast<v8::CpuProfile*>(profile)->Delete();
}
@@ -759,8 +751,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
CheckChildrenNames(unresolvedNode, names);
}
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- cpu_profiler->DeleteAllCpuProfiles();
+ const_cast<v8::CpuProfile*>(profile)->Delete();
}
@@ -1137,8 +1123,7 @@
}
}
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- cpu_profiler->DeleteAllCpuProfiles();
+ const_cast<v8::CpuProfile*>(profile)->Delete();
}
@@ -1226,8 +1211,7 @@
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 @@
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 @@
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 @@
CHECK_EQ(0, idleNode->GetChildrenCount());
CHECK_GE(idleNode->GetHitCount(), 3);
- cpu_profiler->DeleteAllCpuProfiles();
+ const_cast<v8::CpuProfile*>(profile)->Delete();
}
@@ -1489,8 +1471,6 @@
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 @@
"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 @@
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());
}
=======================================
--- /branches/bleeding_edge/test/cctest/test-profile-generator.cc Thu Nov
28 08:21:26 2013 UTC
+++ /branches/bleeding_edge/test/cctest/test-profile-generator.cc Wed Dec
18 08:59:09 2013 UTC
@@ -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 @@
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 @@
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(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 @@
}
-// --- 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 @@
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 @@
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 @@
"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 @@
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 @@
"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);
--
--
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.