Simplify cpu-profiler test code with help of wrappers.

BTW: a few fixes for string comparison

BUG=none
LOG=n

Review URL: https://codereview.chromium.org/892953004

Cr-Commit-Position: refs/heads/master@{#26495}
This commit is contained in:
loislo 2015-02-06 08:50:56 -08:00 committed by Commit bot
parent 5c56665059
commit fb73392bfd

View File

@ -49,6 +49,12 @@ using i::SmartPointer;
using i::Vector;
// Helper methods
static v8::Local<v8::Function> GetFunction(v8::Context* env, const char* name) {
return v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str(name)));
}
TEST(StartStop) {
i::Isolate* isolate = CcTest::i_isolate();
CpuProfilesCollection profiles(isolate->heap());
@ -114,9 +120,9 @@ i::Code* CreateCode(LocalContext* env) {
"}\n"
"%s();\n", name_start, counter, name_start, name_start);
CompileRun(script.start());
i::Handle<i::JSFunction> fun = v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(
(*env)->Global()->Get(v8_str(name_start))));
i::Handle<i::JSFunction> fun =
v8::Utils::OpenHandle(*GetFunction(**env, name_start));
return fun->code();
}
@ -165,7 +171,7 @@ TEST(CodeEvents) {
// Check the state of profile generator.
CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address());
CHECK(aaa);
CHECK_EQ(aaa_str, aaa->name());
CHECK_EQ(0, strcmp(aaa_str, aaa->name()));
CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address());
CHECK(comment);
@ -353,7 +359,7 @@ TEST(DeleteCpuProfile) {
i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler);
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1");
v8::Local<v8::String> name1 = v8_str("1");
cpu_profiler->StartProfiling(name1);
v8::CpuProfile* p1 = cpu_profiler->StopProfiling(name1);
CHECK(p1);
@ -362,13 +368,13 @@ TEST(DeleteCpuProfile) {
p1->Delete();
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2");
v8::Local<v8::String> name2 = v8_str("2");
cpu_profiler->StartProfiling(name2);
v8::CpuProfile* p2 = cpu_profiler->StopProfiling(name2);
CHECK(p2);
CHECK_EQ(1, iprofiler->GetProfilesCount());
CHECK(FindCpuProfile(cpu_profiler, p2));
v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3");
v8::Local<v8::String> name3 = v8_str("3");
cpu_profiler->StartProfiling(name3);
v8::CpuProfile* p3 = cpu_profiler->StopProfiling(name3);
CHECK(p3);
@ -390,8 +396,7 @@ TEST(ProfileStartEndTime) {
v8::HandleScope scope(env->GetIsolate());
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name =
v8::String::NewFromUtf8(env->GetIsolate(), "test");
v8::Local<v8::String> profile_name = v8_str("test");
cpu_profiler->StartProfiling(profile_name);
const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
CHECK(profile->GetStartTime() <= profile->GetEndTime());
@ -403,8 +408,7 @@ static v8::CpuProfile* RunProfiler(
v8::Handle<v8::Value> argv[], int argc,
unsigned min_js_samples, bool collect_samples = false) {
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name =
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
v8::Local<v8::String> profile_name = v8_str("my_profile");
cpu_profiler->StartProfiling(profile_name, collect_samples);
@ -454,7 +458,7 @@ static const v8::CpuProfileNode* FindChild(v8::Isolate* isolate,
const v8::CpuProfileNode* node,
const char* name) {
int count = node->GetChildrenCount();
v8::Handle<v8::String> nameHandle = v8::String::NewFromUtf8(isolate, name);
v8::Handle<v8::String> nameHandle = v8_str(name);
for (int i = 0; i < count; i++) {
const v8::CpuProfileNode* child = node->GetChild(i);
if (nameHandle->Equals(child->GetFunctionName())) return child;
@ -542,10 +546,8 @@ TEST(CollectCpuProfile) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
cpu_profiler_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(cpu_profiler_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t profiling_interval_ms = 200;
v8::Handle<v8::Value> args[] = {
@ -558,11 +560,9 @@ TEST(CollectCpuProfile) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
const v8::CpuProfileNode* startNode =
@ -619,11 +619,8 @@ TEST(HotDeoptNoFrameEntry) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Script::Compile(v8::String::NewFromUtf8(
env->GetIsolate(),
hot_deopt_no_frame_entry_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(hot_deopt_no_frame_entry_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t profiling_interval_ms = 200;
v8::Handle<v8::Value> args[] = {
@ -636,11 +633,9 @@ TEST(HotDeoptNoFrameEntry) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
const v8::CpuProfileNode* startNode =
@ -657,10 +652,8 @@ TEST(CollectCpuProfileSamples) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
cpu_profiler_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(cpu_profiler_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t profiling_interval_ms = 200;
v8::Handle<v8::Value> args[] = {
@ -709,10 +702,8 @@ TEST(SampleWhenFrameIsNotSetup) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Script::Compile(v8::String::NewFromUtf8(
env->GetIsolate(), cpu_profiler_test_source2))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(cpu_profiler_test_source2);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t repeat_count = 100;
#if defined(USE_SIMULATOR)
@ -728,11 +719,9 @@ TEST(SampleWhenFrameIsNotSetup) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
const v8::CpuProfileNode* startNode =
@ -826,19 +815,14 @@ TEST(NativeAccessorUninitializedIC) {
TestApiCallbacks accessors(100);
v8::Local<v8::External> data =
v8::External::New(isolate, &accessors);
instance_template->SetAccessor(
v8::String::NewFromUtf8(isolate, "foo"),
&TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data);
instance_template->SetAccessor(v8_str("foo"), &TestApiCallbacks::Getter,
&TestApiCallbacks::Setter, data);
v8::Local<v8::Function> func = func_template->GetFunction();
v8::Local<v8::Object> instance = func->NewInstance();
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
instance);
env->Global()->Set(v8_str("instance"), instance);
v8::Script::Compile(
v8::String::NewFromUtf8(isolate, native_accessor_test_source))
->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
CompileRun(native_accessor_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t repeat_count = 1;
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
@ -871,19 +855,14 @@ TEST(NativeAccessorMonomorphicIC) {
TestApiCallbacks accessors(1);
v8::Local<v8::External> data =
v8::External::New(isolate, &accessors);
instance_template->SetAccessor(
v8::String::NewFromUtf8(isolate, "foo"),
&TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data);
instance_template->SetAccessor(v8_str("foo"), &TestApiCallbacks::Getter,
&TestApiCallbacks::Setter, data);
v8::Local<v8::Function> func = func_template->GetFunction();
v8::Local<v8::Object> instance = func->NewInstance();
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
instance);
env->Global()->Set(v8_str("instance"), instance);
v8::Script::Compile(
v8::String::NewFromUtf8(isolate, native_accessor_test_source))
->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
CompileRun(native_accessor_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
{
// Make sure accessors ICs are in monomorphic state before starting
@ -930,26 +909,22 @@ TEST(NativeMethodUninitializedIC) {
v8::Local<v8::FunctionTemplate> func_template =
v8::FunctionTemplate::New(isolate);
func_template->SetClassName(
v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor"));
func_template->SetClassName(v8_str("Test_InstanceCostructor"));
v8::Local<v8::ObjectTemplate> proto_template =
func_template->PrototypeTemplate();
v8::Local<v8::Signature> signature =
v8::Signature::New(isolate, func_template);
proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"),
v8::FunctionTemplate::New(isolate,
&TestApiCallbacks::Callback,
data, signature, 0));
proto_template->Set(
v8_str("fooMethod"),
v8::FunctionTemplate::New(isolate, &TestApiCallbacks::Callback, data,
signature, 0));
v8::Local<v8::Function> func = func_template->GetFunction();
v8::Local<v8::Object> instance = func->NewInstance();
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
instance);
env->Global()->Set(v8_str("instance"), instance);
v8::Script::Compile(v8::String::NewFromUtf8(
isolate, native_method_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
CompileRun(native_method_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t repeat_count = 1;
v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) };
@ -976,26 +951,22 @@ TEST(NativeMethodMonomorphicIC) {
v8::Local<v8::FunctionTemplate> func_template =
v8::FunctionTemplate::New(isolate);
func_template->SetClassName(
v8::String::NewFromUtf8(isolate, "Test_InstanceCostructor"));
func_template->SetClassName(v8_str("Test_InstanceCostructor"));
v8::Local<v8::ObjectTemplate> proto_template =
func_template->PrototypeTemplate();
v8::Local<v8::Signature> signature =
v8::Signature::New(isolate, func_template);
proto_template->Set(v8::String::NewFromUtf8(isolate, "fooMethod"),
v8::FunctionTemplate::New(isolate,
&TestApiCallbacks::Callback,
data, signature, 0));
proto_template->Set(
v8_str("fooMethod"),
v8::FunctionTemplate::New(isolate, &TestApiCallbacks::Callback, data,
signature, 0));
v8::Local<v8::Function> func = func_template->GetFunction();
v8::Local<v8::Object> instance = func->NewInstance();
env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"),
instance);
env->Global()->Set(v8_str("instance"), instance);
v8::Script::Compile(v8::String::NewFromUtf8(
isolate, native_method_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(isolate, "start")));
CompileRun(native_method_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
{
// Make sure method ICs are in monomorphic state before starting
// profiling.
@ -1038,21 +1009,16 @@ TEST(BoundFunctionCall) {
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);
v8::Script::Compile(
v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source))
->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(bound_function_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
// Don't allow |foo| node to be at the top level.
CheckChildrenNames(root, names);
@ -1090,8 +1056,8 @@ TEST(TickLines) {
CompileRun(script.start());
i::Handle<i::JSFunction> func = v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast((*env)->Global()->Get(v8_str(func_name))));
i::Handle<i::JSFunction> func =
v8::Utils::OpenHandle(*GetFunction(*env, func_name));
CHECK(func->shared());
CHECK(func->shared()->code());
i::Code* code = NULL;
@ -1131,7 +1097,7 @@ TEST(TickLines) {
// Check the state of profile generator.
CodeEntry* func_entry = generator.code_map()->FindEntry(code_address);
CHECK(func_entry);
CHECK_EQ(func_name, func_entry->name());
CHECK_EQ(0, strcmp(func_name, func_entry->name()));
const i::JITLineInfoTable* line_info = func_entry->line_info();
CHECK(line_info);
CHECK(!line_info->empty());
@ -1190,13 +1156,12 @@ TEST(FunctionCallSample) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
// Collect garbage that might have be generated while installing extensions.
// Collect garbage that might have be generated while installing
// extensions.
CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags);
v8::Script::Compile(v8::String::NewFromUtf8(
env->GetIsolate(), call_function_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(call_function_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t duration_ms = 100;
v8::Handle<v8::Value> args[] = {
@ -1208,13 +1173,10 @@ TEST(FunctionCallSample) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{
ScopedVector<v8::Handle<v8::String> > names(4);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[3] = v8::String::NewFromUtf8(
env->GetIsolate(), i::ProfileGenerator::kUnresolvedFunctionName);
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
names[3] = v8_str(i::ProfileGenerator::kUnresolvedFunctionName);
// Don't allow |bar| and |call| nodes to be at the top level.
CheckChildrenNames(root, names);
}
@ -1228,8 +1190,8 @@ TEST(FunctionCallSample) {
CHECK(is_gc_stress_testing || startNode);
if (startNode) {
ScopedVector<v8::Handle<v8::String> > names(2);
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "bar");
names[1] = v8::String::NewFromUtf8(env->GetIsolate(), "call");
names[0] = v8_str("bar");
names[1] = v8_str("call");
CheckChildrenNames(startNode, names);
}
@ -1237,7 +1199,7 @@ TEST(FunctionCallSample) {
env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName);
if (unresolvedNode) {
ScopedVector<v8::Handle<v8::String> > names(1);
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call");
names[0] = v8_str("call");
CheckChildrenNames(unresolvedNode, names);
}
@ -1245,19 +1207,20 @@ TEST(FunctionCallSample) {
}
static const char* function_apply_test_source = "function bar(iterations) {\n"
"}\n"
"function test() {\n"
" bar.apply(this, [10 * 1000]);\n"
"}\n"
"function start(duration) {\n"
" var start = Date.now();\n"
" while (Date.now() - start < duration) {\n"
" try {\n"
" test();\n"
" } catch(e) {}\n"
" }\n"
"}";
static const char* function_apply_test_source =
"function bar(iterations) {\n"
"}\n"
"function test() {\n"
" bar.apply(this, [10 * 1000]);\n"
"}\n"
"function start(duration) {\n"
" var start = Date.now();\n"
" while (Date.now() - start < duration) {\n"
" try {\n"
" test();\n"
" } catch(e) {}\n"
" }\n"
"}";
// [Top down]:
@ -1274,11 +1237,8 @@ TEST(FunctionApplySample) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::Script::Compile(
v8::String::NewFromUtf8(env->GetIsolate(), function_apply_test_source))
->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(function_apply_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
int32_t duration_ms = 100;
v8::Handle<v8::Value> args[] = {
@ -1291,11 +1251,9 @@ TEST(FunctionApplySample) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
// Don't allow |test|, |bar| and |apply| nodes to be at the top level.
CheckChildrenNames(root, names);
}
@ -1305,9 +1263,8 @@ TEST(FunctionApplySample) {
if (startNode) {
{
ScopedVector<v8::Handle<v8::String> > names(2);
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "test");
names[1] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kUnresolvedFunctionName);
names[0] = v8_str("test");
names[1] = v8_str(ProfileGenerator::kUnresolvedFunctionName);
CheckChildrenNames(startNode, names);
}
@ -1315,11 +1272,11 @@ TEST(FunctionApplySample) {
FindChild(env->GetIsolate(), startNode, "test");
if (testNode) {
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "bar");
names[1] = v8::String::NewFromUtf8(env->GetIsolate(), "apply");
names[0] = v8_str("bar");
names[1] = v8_str("apply");
// apply calls "get length" before invoking the function itself
// and we may get hit into it.
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "get length");
names[2] = v8_str("get length");
CheckChildrenNames(testNode, names);
}
@ -1327,7 +1284,7 @@ TEST(FunctionApplySample) {
FindChild(env->GetIsolate(), startNode,
ProfileGenerator::kUnresolvedFunctionName)) {
ScopedVector<v8::Handle<v8::String> > names(1);
names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply");
names[0] = v8_str("apply");
CheckChildrenNames(unresolvedNode, names);
GetChild(env->GetIsolate(), unresolvedNode, "apply");
}
@ -1365,14 +1322,11 @@ TEST(CpuProfileDeepStack) {
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);
v8::Script::Compile(v8::String::NewFromUtf8(
env->GetIsolate(), cpu_profiler_deep_stack_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(cpu_profiler_deep_stack_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name =
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
v8::Local<v8::String> profile_name = v8_str("my_profile");
function->Call(env->Global(), 0, NULL);
v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
CHECK(profile);
@ -1382,11 +1336,9 @@ TEST(CpuProfileDeepStack) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
}
@ -1438,25 +1390,20 @@ TEST(JsNativeJsSample) {
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
env->GetIsolate(), CallJsFunction);
v8::Local<v8::Function> func = func_template->GetFunction();
func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
env->Global()->Set(
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
func->SetName(v8_str("CallJsFunction"));
env->Global()->Set(v8_str("CallJsFunction"), func);
v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
js_native_js_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(js_native_js_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
{
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
}
@ -1507,25 +1454,19 @@ TEST(JsNativeJsRuntimeJsSample) {
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
env->GetIsolate(), CallJsFunction);
v8::Local<v8::Function> func = func_template->GetFunction();
func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
env->Global()->Set(
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
func->SetName(v8_str("CallJsFunction"));
env->Global()->Set(v8_str("CallJsFunction"), func);
v8::Script::Compile(
v8::String::NewFromUtf8(env->GetIsolate(),
js_native_js_runtime_js_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(js_native_js_runtime_js_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
const v8::CpuProfileNode* startNode =
@ -1587,31 +1528,24 @@ TEST(JsNative1JsNative2JsSample) {
v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
env->GetIsolate(), CallJsFunction);
v8::Local<v8::Function> func1 = func_template->GetFunction();
func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"));
env->Global()->Set(
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1);
func1->SetName(v8_str("CallJsFunction1"));
env->Global()->Set(v8_str("CallJsFunction1"), func1);
v8::Local<v8::Function> func2 = v8::FunctionTemplate::New(
env->GetIsolate(), CallJsFunction2)->GetFunction();
func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"));
env->Global()->Set(
v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2);
func2->SetName(v8_str("CallJsFunction2"));
env->Global()->Set(v8_str("CallJsFunction2"), func2);
v8::Script::Compile(
v8::String::NewFromUtf8(env->GetIsolate(),
js_native1_js_native2_js_test_source))->Run();
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
CompileRun(js_native1_js_native2_js_test_source);
v8::Local<v8::Function> function = GetFunction(*env, "start");
v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str("start");
CheckChildrenNames(root, names);
const v8::CpuProfileNode* startNode =
@ -1644,8 +1578,7 @@ TEST(IdleTime) {
v8::HandleScope scope(env->GetIsolate());
v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
v8::Local<v8::String> profile_name =
v8::String::NewFromUtf8(env->GetIsolate(), "my_profile");
v8::Local<v8::String> profile_name = v8_str("my_profile");
cpu_profiler->StartProfiling(profile_name);
i::Isolate* isolate = CcTest::i_isolate();
@ -1669,12 +1602,9 @@ TEST(IdleTime) {
const v8::CpuProfileNode* root = profile->GetTopDownRoot();
ScopedVector<v8::Handle<v8::String> > names(3);
names[0] = v8::String::NewFromUtf8(
env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kProgramEntryName);
names[2] = v8::String::NewFromUtf8(env->GetIsolate(),
ProfileGenerator::kIdleEntryName);
names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
names[1] = v8_str(ProfileGenerator::kProgramEntryName);
names[2] = v8_str(ProfileGenerator::kIdleEntryName);
CheckChildrenNames(root, names);
const v8::CpuProfileNode* programNode =
@ -1695,10 +1625,8 @@ static void CheckFunctionDetails(v8::Isolate* isolate,
const v8::CpuProfileNode* node,
const char* name, const char* script_name,
int script_id, int line, int column) {
CHECK(
v8::String::NewFromUtf8(isolate, name)->Equals(node->GetFunctionName()));
CHECK(v8::String::NewFromUtf8(isolate, script_name)
->Equals(node->GetScriptResourceName()));
CHECK(v8_str(name)->Equals(node->GetFunctionName()));
CHECK(v8_str(script_name)->Equals(node->GetScriptResourceName()));
CHECK_EQ(script_id, node->GetScriptId());
CHECK_EQ(line, node->GetLineNumber());
CHECK_EQ(column, node->GetColumnNumber());
@ -1751,17 +1679,16 @@ TEST(DontStopOnFinishedProfileDelete) {
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
v8::Context::Scope context_scope(env);
v8::Isolate* isolate = env->GetIsolate();
v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer");
v8::Handle<v8::String> outer = v8_str("outer");
profiler->StartProfiling(outer);
CHECK_EQ(0, iprofiler->GetProfilesCount());
v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner");
v8::Handle<v8::String> inner = v8_str("inner");
profiler->StartProfiling(inner);
CHECK_EQ(0, iprofiler->GetProfilesCount());