Index: test/cctest/test-cpu-profiler.cc |
diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc |
index 77b5bd877c7e8d6a688eed341ca18965e6f90163..6e5e23b4845f57561e42f3b45e24d4990b5751e3 100644 |
--- a/test/cctest/test-cpu-profiler.cc |
+++ b/test/cctest/test-cpu-profiler.cc |
@@ -283,7 +283,7 @@ TEST(Issue1398) { |
sample->pc = code->address(); |
sample->tos = 0; |
sample->frames_count = i::TickSample::kMaxFramesCount; |
- for (int i = 0; i < sample->frames_count; ++i) { |
+ for (unsigned i = 0; i < sample->frames_count; ++i) { |
sample->stack[i] = code->address(); |
} |
processor->FinishTickSample(); |
@@ -1248,6 +1248,72 @@ TEST(FunctionApplySample) { |
} |
+static const char* cpu_profiler_deep_stack_test_source = |
+"function foo(n) {\n" |
+" if (n)\n" |
+" foo(n - 1);\n" |
+" else\n" |
+" startProfiling('my_profile');\n" |
+"}\n" |
+"function start() {\n" |
+" foo(250);\n" |
+"}\n"; |
+ |
+ |
+// Check a deep stack |
+// |
+// [Top down]: |
+// 0 (root) 0 #1 |
+// 2 (program) 0 #2 |
+// 0 start 21 #3 no reason |
+// 0 foo 21 #4 no reason |
+// 0 foo 21 #5 no reason |
+// .... |
+// 0 foo 21 #253 no reason |
+// 1 startProfiling 0 #254 |
+TEST(CpuProfileDeepStack) { |
+ v8::HandleScope scope(CcTest::isolate()); |
+ 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"))); |
+ |
+ v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
+ v8::Local<v8::String> profile_name = |
+ v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
+ function->Call(env->Global(), 0, NULL); |
+ v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
+ CHECK_NE(NULL, profile); |
+ // Dump collected profile to have a better diagnostic in case of failure. |
+ reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
+ |
+ 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"); |
+ CheckChildrenNames(root, names); |
+ } |
+ |
+ const v8::CpuProfileNode* node = |
+ GetChild(env->GetIsolate(), root, "start"); |
+ for (int i = 0; i < 250; ++i) { |
+ node = GetChild(env->GetIsolate(), node, "foo"); |
+ } |
+ // TODO(alph): |
+ // In theory there must be one more 'foo' and a 'startProfiling' nodes, |
+ // but due to unstable top frame extraction these might be missing. |
+ |
+ profile->Delete(); |
+} |
+ |
+ |
static const char* js_native_js_test_source = |
"var is_profiling = false;\n" |
"function foo(iterations) {\n" |