Index: test/cctest/test-profile-generator.cc |
diff --git a/test/cctest/test-profile-generator.cc b/test/cctest/test-profile-generator.cc |
index 54791e247a0dfddc354a5581b604c509ed694871..f05ab081125c2d2b16a911c4b5a7dd42910d840d 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" |
@@ -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) { |
@@ -694,7 +638,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 +649,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 +741,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 +758,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); |