Chromium Code Reviews| Index: test/cctest/test-cpu-profiler.cc |
| diff --git a/test/cctest/test-cpu-profiler.cc b/test/cctest/test-cpu-profiler.cc |
| index 361c879af39935f40b845e57d6cc3d3ab0948f18..3f5f987387397c21ad215beeb4dabdb0af46e77e 100644 |
| --- a/test/cctest/test-cpu-profiler.cc |
| +++ b/test/cctest/test-cpu-profiler.cc |
| @@ -1510,6 +1510,70 @@ TEST(JsNativeJsRuntimeJsSampleMultiple) { |
| profile->Delete(); |
| } |
| +void CheckChildIsRare(const v8::Local<v8::Context>& context, |
| + const v8::CpuProfileNode* node, const char* name) { |
| + const v8::CpuProfileNode* child = FindChild(context, node, name); |
| + CHECK(!child || child->GetHitCount() < 10u); |
| +} |
| + |
| +static const char* inlining_test_source = |
| + "%NeverOptimizeFunction(action);\n" |
| + "%NeverOptimizeFunction(start);\n" |
| + "%OptimizeFunctionOnNextCall(level1);\n" |
| + "%OptimizeFunctionOnNextCall(level2);\n" |
| + "%OptimizeFunctionOnNextCall(level3);\n" |
| + "function action(n) {\n" |
| + " var s = 0;\n" |
| + " for (var i = 0; i < n; ++i) s += i*i*i;\n" |
| + " return s;\n" |
| + "}\n" |
| + "function level3() { return action(1000); }\n" |
| + "function level2() { return level3() * 2; }\n" |
| + "function level1() { return level2(); }\n" |
| + "function start() {\n" |
| + " startProfiling('my_profile');\n" |
| + " var startTime = Date.now();\n" |
| + " do {\n" |
| + " level1();\n" |
| + " } while (Date.now() - startTime < 200);\n" |
| + "}"; |
| + |
| +// The test check multiple entrances/exits between JS and native code. |
| +// |
| +// [Top down]: |
| +// (root) #0 1 |
| +// start #16 3 |
| +// level1 #0 4 |
| +// level2 #16 5 |
| +// level3 #16 6 |
| +// action #16 7 |
| +// (program) #0 2 |
| +TEST(Inlining) { |
|
titzer
2016/02/26 21:24:01
Is there a way to make this test non-flaky? It cur
alph
2016/02/26 22:12:10
It does not. It was supposed to check that there's
titzer
2016/02/26 23:46:52
It's still inherently flaky. Why can't you test th
alph
2016/02/27 08:24:02
looks like I managed to make the test deterministi
|
| + i::FLAG_allow_natives_syntax = true; |
| + v8::HandleScope scope(CcTest::isolate()); |
| + v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| + v8::Context::Scope context_scope(env); |
| + |
| + CompileRun(inlining_test_source); |
| + v8::Local<v8::Function> function = GetFunction(env, "start"); |
| + v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); |
| + |
| + const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| + const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| + const v8::CpuProfileNode* level1_node = GetChild(env, start_node, "level1"); |
| + const v8::CpuProfileNode* level2_node = GetChild(env, level1_node, "level2"); |
| + const v8::CpuProfileNode* level3_node = GetChild(env, level2_node, "level3"); |
| + GetChild(env, level3_node, "action"); |
| + CheckChildIsRare(env, start_node, "level2"); |
| + CheckChildIsRare(env, start_node, "level3"); |
| + CheckChildIsRare(env, start_node, "action"); |
| + CheckChildIsRare(env, level1_node, "level3"); |
| + CheckChildIsRare(env, level1_node, "action"); |
| + CheckChildIsRare(env, level2_node, "action"); |
| + |
| + profile->Delete(); |
| +} |
| + |
| // [Top down]: |
| // 0 (root) #0 1 |
| // 2 (program) #0 2 |