Index: test/cctest/test-cpu-profiler.cc |
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc |
index 6075fe16064be77c2b9ab36e2f84c58d462d7e3a..ac675c3d5fe4513140926eab59ac11ec090d6cc1 100644 |
--- a/test/cctest/test-cpu-profiler.cc |
+++ b/test/cctest/test-cpu-profiler.cc |
@@ -1000,3 +1000,60 @@ TEST(BoundFunctionCall) { |
cpu_profiler->DeleteAllCpuProfiles(); |
} |
+ |
+ |
+static const char* call_function_test_source = "function bar(iterations) {\n" |
+"}\n" |
+"function start(duration) {\n" |
+" var start = Date.now();\n" |
+" while (Date.now() - start < duration) {\n" |
+" try {\n" |
+" bar.call(this, 10 * 1000);\n" |
+" } catch(e) {}\n" |
+" }\n" |
+"}"; |
+ |
+ |
+TEST(CallFunction) { |
+ LocalContext env; |
+ v8::HandleScope scope(env->GetIsolate()); |
+ |
+ v8::Script::Compile(v8::String::New(call_function_test_source))->Run(); |
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
+ env->Global()->Get(v8::String::New("start"))); |
+ |
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
+ v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
+ |
+ cpu_profiler->StartCpuProfiling(profile_name); |
+ int32_t duration_ms = 100; |
+ v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
+ function->Call(env->Global(), ARRAY_SIZE(args), args); |
+ const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
+ |
+ CHECK_NE(NULL, profile); |
+ // Dump collected profile to have a better diagnostic in case of failure. |
+ reinterpret_cast<i::CpuProfile*>( |
+ const_cast<v8::CpuProfile*>(profile))->Print(); |
+ |
+ const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
+ { |
+ ScopedVector<v8::Handle<v8::String> > names(3); |
+ names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
+ names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
+ names[2] = v8::String::New("start"); |
+ // Don't allow |bar| and |call| nodes to be at the top level. |
+ CheckChildrenNames(root, names); |
+ } |
+ |
+ const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
+ { |
+ ScopedVector<v8::Handle<v8::String> > names(2); |
+ names[0] = v8::String::New("bar"); |
+ names[1] = v8::String::New("call"); |
+ CheckChildrenNames(startNode, names); |
+ } |
+ |
+ cpu_profiler->DeleteAllCpuProfiles(); |
+} |
+ |