OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1497 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1498 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); | 1498 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
1499 const v8::CpuProfileNode* native_node = | 1499 const v8::CpuProfileNode* native_node = |
1500 GetChild(env, start_node, "CallJsFunction"); | 1500 GetChild(env, start_node, "CallJsFunction"); |
1501 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar"); | 1501 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar"); |
1502 GetChild(env, bar_node, "foo"); | 1502 GetChild(env, bar_node, "foo"); |
1503 | 1503 |
1504 profile->Delete(); | 1504 profile->Delete(); |
1505 } | 1505 } |
1506 | 1506 |
| 1507 static const char* inlining_test_source = |
| 1508 "%NeverOptimizeFunction(action);\n" |
| 1509 "%NeverOptimizeFunction(start);\n" |
| 1510 "%OptimizeFunctionOnNextCall(level1);\n" |
| 1511 "%OptimizeFunctionOnNextCall(level2);\n" |
| 1512 "%OptimizeFunctionOnNextCall(level3);\n" |
| 1513 "var finish = false;\n" |
| 1514 "function action(n) {\n" |
| 1515 " var s = 0;\n" |
| 1516 " for (var i = 0; i < n; ++i) s += i*i*i;\n" |
| 1517 " if (finish)\n" |
| 1518 " startProfiling('my_profile');\n" |
| 1519 " return s;\n" |
| 1520 "}\n" |
| 1521 "function level3() { return action(100); }\n" |
| 1522 "function level2() { return level3() * 2; }\n" |
| 1523 "function level1() { return level2(); }\n" |
| 1524 "function start() {\n" |
| 1525 " var n = 100;\n" |
| 1526 " while (--n)\n" |
| 1527 " level1();\n" |
| 1528 " finish = true;\n" |
| 1529 " level1();\n" |
| 1530 "}"; |
| 1531 |
| 1532 // The test check multiple entrances/exits between JS and native code. |
| 1533 // |
| 1534 // [Top down]: |
| 1535 // (root) #0 1 |
| 1536 // start #16 3 |
| 1537 // level1 #0 4 |
| 1538 // level2 #16 5 |
| 1539 // level3 #16 6 |
| 1540 // action #16 7 |
| 1541 // (program) #0 2 |
| 1542 TEST(Inlining) { |
| 1543 i::FLAG_allow_natives_syntax = true; |
| 1544 v8::HandleScope scope(CcTest::isolate()); |
| 1545 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| 1546 v8::Context::Scope context_scope(env); |
| 1547 |
| 1548 CompileRun(inlining_test_source); |
| 1549 v8::Local<v8::Function> function = GetFunction(env, "start"); |
| 1550 |
| 1551 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1552 v8::Local<v8::String> profile_name = v8_str("my_profile"); |
| 1553 function->Call(env, env->Global(), 0, NULL).ToLocalChecked(); |
| 1554 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| 1555 CHECK(profile); |
| 1556 // Dump collected profile to have a better diagnostic in case of failure. |
| 1557 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
| 1558 |
| 1559 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1560 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); |
| 1561 const v8::CpuProfileNode* level1_node = GetChild(env, start_node, "level1"); |
| 1562 const v8::CpuProfileNode* level2_node = GetChild(env, level1_node, "level2"); |
| 1563 const v8::CpuProfileNode* level3_node = GetChild(env, level2_node, "level3"); |
| 1564 GetChild(env, level3_node, "action"); |
| 1565 |
| 1566 profile->Delete(); |
| 1567 } |
| 1568 |
1507 // [Top down]: | 1569 // [Top down]: |
1508 // 0 (root) #0 1 | 1570 // 0 (root) #0 1 |
1509 // 2 (program) #0 2 | 1571 // 2 (program) #0 2 |
1510 // 3 (idle) #0 3 | 1572 // 3 (idle) #0 3 |
1511 TEST(IdleTime) { | 1573 TEST(IdleTime) { |
1512 LocalContext env; | 1574 LocalContext env; |
1513 v8::HandleScope scope(env->GetIsolate()); | 1575 v8::HandleScope scope(env->GetIsolate()); |
1514 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1576 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
1515 | 1577 |
1516 v8::Local<v8::String> profile_name = v8_str("my_profile"); | 1578 v8::Local<v8::String> profile_name = v8_str("my_profile"); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 iprofile->Print(); | 2024 iprofile->Print(); |
1963 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); | 2025 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); |
1964 | 2026 |
1965 const char* branch[] = {"", "test"}; | 2027 const char* branch[] = {"", "test"}; |
1966 const ProfileNode* itest_node = | 2028 const ProfileNode* itest_node = |
1967 GetSimpleBranch(env, profile, branch, arraysize(branch)); | 2029 GetSimpleBranch(env, profile, branch, arraysize(branch)); |
1968 CHECK_EQ(0U, itest_node->deopt_infos().size()); | 2030 CHECK_EQ(0U, itest_node->deopt_infos().size()); |
1969 | 2031 |
1970 iprofiler->DeleteProfile(iprofile); | 2032 iprofiler->DeleteProfile(iprofile); |
1971 } | 2033 } |
OLD | NEW |