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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 CHECK_EQ(1, barNode->GetChildrenCount()); | 1596 CHECK_EQ(1, barNode->GetChildrenCount()); |
1597 const v8::CpuProfileNode* nativeNode2 = | 1597 const v8::CpuProfileNode* nativeNode2 = |
1598 GetChild(env, barNode, "CallJsFunction2"); | 1598 GetChild(env, barNode, "CallJsFunction2"); |
1599 | 1599 |
1600 CHECK_EQ(1, nativeNode2->GetChildrenCount()); | 1600 CHECK_EQ(1, nativeNode2->GetChildrenCount()); |
1601 GetChild(env, nativeNode2, "foo"); | 1601 GetChild(env, nativeNode2, "foo"); |
1602 | 1602 |
1603 profile->Delete(); | 1603 profile->Delete(); |
1604 } | 1604 } |
1605 | 1605 |
| 1606 static const char* js_force_collect_sample_source = |
| 1607 "function start() {\n" |
| 1608 " CallCollectSample();\n" |
| 1609 "}"; |
| 1610 |
| 1611 static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1612 info.GetIsolate()->GetCpuProfiler()->CollectSample(); |
| 1613 } |
| 1614 |
| 1615 TEST(CollectSampleAPI) { |
| 1616 v8::HandleScope scope(CcTest::isolate()); |
| 1617 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| 1618 v8::Context::Scope context_scope(env); |
| 1619 |
| 1620 v8::Local<v8::FunctionTemplate> func_template = |
| 1621 v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample); |
| 1622 v8::Local<v8::Function> func = |
| 1623 func_template->GetFunction(env).ToLocalChecked(); |
| 1624 func->SetName(v8_str("CallCollectSample")); |
| 1625 env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust(); |
| 1626 |
| 1627 CompileRun(js_force_collect_sample_source); |
| 1628 v8::Local<v8::Function> function = GetFunction(env, "start"); |
| 1629 |
| 1630 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); |
| 1631 |
| 1632 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1633 { |
| 1634 ScopedVector<v8::Local<v8::String> > names(3); |
| 1635 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
| 1636 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
| 1637 names[2] = v8_str("start"); |
| 1638 CheckChildrenNames(env, root, names); |
| 1639 } |
| 1640 |
| 1641 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); |
| 1642 CHECK_LE(1, startNode->GetChildrenCount()); |
| 1643 GetChild(env, startNode, "CallCollectSample"); |
| 1644 |
| 1645 profile->Delete(); |
| 1646 } |
1606 | 1647 |
1607 // [Top down]: | 1648 // [Top down]: |
1608 // 6 0 (root) #0 1 | 1649 // 0 (root) #0 1 |
1609 // 3 3 (program) #0 2 | 1650 // 2 (program) #0 2 |
1610 // 3 3 (idle) #0 3 | 1651 // 3 (idle) #0 3 |
1611 TEST(IdleTime) { | 1652 TEST(IdleTime) { |
1612 LocalContext env; | 1653 LocalContext env; |
1613 v8::HandleScope scope(env->GetIsolate()); | 1654 v8::HandleScope scope(env->GetIsolate()); |
1614 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1655 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
1615 | 1656 |
1616 v8::Local<v8::String> profile_name = v8_str("my_profile"); | 1657 v8::Local<v8::String> profile_name = v8_str("my_profile"); |
1617 cpu_profiler->StartProfiling(profile_name); | 1658 cpu_profiler->StartProfiling(profile_name); |
1618 | 1659 |
1619 i::Isolate* isolate = CcTest::i_isolate(); | 1660 i::Isolate* isolate = CcTest::i_isolate(); |
1620 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); | 1661 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); |
1621 processor->AddCurrentStack(isolate); | 1662 processor->AddCurrentStack(isolate, true); |
1622 | 1663 |
1623 cpu_profiler->SetIdle(true); | 1664 cpu_profiler->SetIdle(true); |
1624 | 1665 |
1625 for (int i = 0; i < 3; i++) { | 1666 for (int i = 0; i < 3; i++) { |
1626 processor->AddCurrentStack(isolate); | 1667 processor->AddCurrentStack(isolate, true); |
1627 } | 1668 } |
1628 | 1669 |
1629 cpu_profiler->SetIdle(false); | 1670 cpu_profiler->SetIdle(false); |
1630 processor->AddCurrentStack(isolate); | 1671 processor->AddCurrentStack(isolate, true); |
1631 | |
1632 | 1672 |
1633 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); | 1673 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
1634 CHECK(profile); | 1674 CHECK(profile); |
1635 // Dump collected profile to have a better diagnostic in case of failure. | 1675 // Dump collected profile to have a better diagnostic in case of failure. |
1636 reinterpret_cast<i::CpuProfile*>(profile)->Print(); | 1676 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
1637 | 1677 |
1638 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1678 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1639 ScopedVector<v8::Local<v8::String> > names(3); | 1679 ScopedVector<v8::Local<v8::String> > names(3); |
1640 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); | 1680 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); |
1641 names[1] = v8_str(ProfileGenerator::kProgramEntryName); | 1681 names[1] = v8_str(ProfileGenerator::kProgramEntryName); |
1642 names[2] = v8_str(ProfileGenerator::kIdleEntryName); | 1682 names[2] = v8_str(ProfileGenerator::kIdleEntryName); |
1643 CheckChildrenNames(env.local(), root, names); | 1683 CheckChildrenNames(env.local(), root, names); |
1644 | 1684 |
1645 const v8::CpuProfileNode* programNode = | 1685 const v8::CpuProfileNode* programNode = |
1646 GetChild(env.local(), root, ProfileGenerator::kProgramEntryName); | 1686 GetChild(env.local(), root, ProfileGenerator::kProgramEntryName); |
1647 CHECK_EQ(0, programNode->GetChildrenCount()); | 1687 CHECK_EQ(0, programNode->GetChildrenCount()); |
1648 CHECK_GE(programNode->GetHitCount(), 3u); | 1688 CHECK_GE(programNode->GetHitCount(), 2u); |
1649 | 1689 |
1650 const v8::CpuProfileNode* idleNode = | 1690 const v8::CpuProfileNode* idleNode = |
1651 GetChild(env.local(), root, ProfileGenerator::kIdleEntryName); | 1691 GetChild(env.local(), root, ProfileGenerator::kIdleEntryName); |
1652 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1692 CHECK_EQ(0, idleNode->GetChildrenCount()); |
1653 CHECK_GE(idleNode->GetHitCount(), 3u); | 1693 CHECK_GE(idleNode->GetHitCount(), 3u); |
1654 | 1694 |
1655 profile->Delete(); | 1695 profile->Delete(); |
1656 } | 1696 } |
1657 | 1697 |
1658 | 1698 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 iprofile->Print(); | 2108 iprofile->Print(); |
2069 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); | 2109 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); |
2070 | 2110 |
2071 const char* branch[] = {"", "test"}; | 2111 const char* branch[] = {"", "test"}; |
2072 const ProfileNode* itest_node = | 2112 const ProfileNode* itest_node = |
2073 GetSimpleBranch(env, profile, branch, arraysize(branch)); | 2113 GetSimpleBranch(env, profile, branch, arraysize(branch)); |
2074 CHECK_EQ(0U, itest_node->deopt_infos().size()); | 2114 CHECK_EQ(0U, itest_node->deopt_infos().size()); |
2075 | 2115 |
2076 iprofiler->DeleteProfile(iprofile); | 2116 iprofiler->DeleteProfile(iprofile); |
2077 } | 2117 } |
OLD | NEW |