Index: test/cctest/test-cpu-profiler.cc |
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc |
index 6703ada05d3a5242a6d88118bfee5bb7f4d28011..604f01e53cec3d735521ac71fa4642d25e822053 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<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()); |
} |