Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Unified Diff: test/cctest/test-cpu-profiler.cc

Issue 18422003: Correctly report callstack when current function is FunctionCall builtin (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-cpu-profiler.cc
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc
index 251a4a529095eb260742d8fa613b679adc301656..f4d9936329981a650ce3fb27caa29b29aadb8a17 100644
--- a/test/cctest/test-cpu-profiler.cc
+++ b/test/cctest/test-cpu-profiler.cc
@@ -1023,3 +1023,80 @@ 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 that if we sampled thread when it was inside FunctionCall buitin then
+// its caller frame will be '(unresolved function)' as we have no reliable way
+// to resolve it.
+//
+// [Top down]:
+// 96 0 (root) [-1] #1
+// 1 1 (garbage collector) [-1] #4
+// 5 0 (unresolved function) [-1] #5
+// 5 5 call [-1] #6
+// 71 70 start [-1] #3
+// 1 1 bar [-1] #7
+// 19 19 (program) [-1] #2
+TEST(FunctionCallSample) {
+ 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(4);
+ names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName);
+ names[1] = v8::String::New(ProfileGenerator::kProgramEntryName);
+ names[2] = v8::String::New("start");
+ names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName);
+ // 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(1);
+ names[0] = v8::String::New("bar");
+ CheckChildrenNames(startNode, names);
+ }
+
+ const v8::CpuProfileNode* unresolvedNode =
+ FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName);
+ if (unresolvedNode) {
+ ScopedVector<v8::Handle<v8::String> > names(1);
+ names[0] = v8::String::New("call");
+ CheckChildrenNames(unresolvedNode, names);
+ }
+
+ cpu_profiler->DeleteAllCpuProfiles();
+}
+
« no previous file with comments | « src/profile-generator-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698