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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 CheckSimpleBranch(env.local(), foo_node, bar_branch, arraysize(bar_branch)); | 614 CheckSimpleBranch(env.local(), foo_node, bar_branch, arraysize(bar_branch)); |
615 const char* baz_branch[] = {"baz", "delay", "loop"}; | 615 const char* baz_branch[] = {"baz", "delay", "loop"}; |
616 CheckSimpleBranch(env.local(), foo_node, baz_branch, arraysize(baz_branch)); | 616 CheckSimpleBranch(env.local(), foo_node, baz_branch, arraysize(baz_branch)); |
617 const char* delay_branch[] = {"delay", "loop"}; | 617 const char* delay_branch[] = {"delay", "loop"}; |
618 CheckSimpleBranch(env.local(), foo_node, delay_branch, | 618 CheckSimpleBranch(env.local(), foo_node, delay_branch, |
619 arraysize(delay_branch)); | 619 arraysize(delay_branch)); |
620 | 620 |
621 profile->Delete(); | 621 profile->Delete(); |
622 } | 622 } |
623 | 623 |
624 static const char* cpu_profiler_toplevel_source = | |
625 "for (var i = 0; i < 1E5; i++) {" | |
626 " var s = 0;" | |
627 " for (var j = 0; j < 1E2; j++) s += i;" | |
628 "}"; | |
629 | |
630 TEST(CollectOptimizedToplevelProfile) { | |
631 LocalContext env; | |
632 v8::HandleScope scope(env->GetIsolate()); | |
633 | |
634 v8::CpuProfiler* profiler = v8::CpuProfiler::New(env->GetIsolate()); | |
635 v8::Local<v8::String> profile_name = v8_str("my_profile"); | |
636 | |
637 profiler->SetSamplingInterval(100); | |
638 profiler->StartProfiling(profile_name, true); | |
639 v8::internal::CpuProfiler* iprofiler = | |
640 reinterpret_cast<v8::internal::CpuProfiler*>(profiler); | |
641 v8::sampler::Sampler* sampler = iprofiler->processor()->sampler(); | |
642 sampler->StartCountingSamples(); | |
643 | |
644 CompileRun(cpu_profiler_toplevel_source); | |
645 | |
646 v8::CpuProfile* profile = profiler->StopProfiling(profile_name); | |
647 reinterpret_cast<i::CpuProfile*>(profile)->Print(); | |
648 | |
649 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | |
650 v8::Local<v8::String> empty = v8::String::Empty(env->GetIsolate()); | |
651 unsigned toplevel_hitcount = 0; | |
652 unsigned unaccounted_hitcount = 0; | |
653 for (int i = 0; i < root->GetChildrenCount(); i++) { | |
654 const v8::CpuProfileNode* child = root->GetChild(i); | |
655 if (empty->Equals(env.local(), child->GetFunctionName()).FromJust()) { | |
656 toplevel_hitcount += child->GetHitCount(); | |
657 } else { | |
658 unaccounted_hitcount += child->GetHitCount(); | |
659 } | |
660 } | |
661 // Check that we are getting more ticks from the toplevel function than | |
662 // unaccounted ticks. | |
663 DCHECK(toplevel_hitcount > unaccounted_hitcount); | |
664 | |
665 profile->Delete(); | |
666 profiler->Dispose(); | |
667 } | |
668 | |
669 static const char* hot_deopt_no_frame_entry_test_source = | 624 static const char* hot_deopt_no_frame_entry_test_source = |
670 "%NeverOptimizeFunction(foo);\n" | 625 "%NeverOptimizeFunction(foo);\n" |
671 "%NeverOptimizeFunction(start);\n" | 626 "%NeverOptimizeFunction(start);\n" |
672 "function foo(a, b) {\n" | 627 "function foo(a, b) {\n" |
673 " return a + b;\n" | 628 " return a + b;\n" |
674 "}\n" | 629 "}\n" |
675 "function start(timeout) {\n" | 630 "function start(timeout) {\n" |
676 " var start = Date.now();\n" | 631 " var start = Date.now();\n" |
677 " do {\n" | 632 " do {\n" |
678 " for (var i = 1; i < 1000; ++i) foo(1, i);\n" | 633 " for (var i = 1; i < 1000; ++i) foo(1, i);\n" |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2228 printf("Profile JSON: %s\n", profile_json.c_str()); | 2183 printf("Profile JSON: %s\n", profile_json.c_str()); |
2229 std::string code = profile_checker + profile_json + ")"; | 2184 std::string code = profile_checker + profile_json + ")"; |
2230 v8::Local<v8::Value> result = | 2185 v8::Local<v8::Value> result = |
2231 CompileRunChecked(CcTest::isolate(), code.c_str()); | 2186 CompileRunChecked(CcTest::isolate(), code.c_str()); |
2232 v8::String::Utf8Value value(result); | 2187 v8::String::Utf8Value value(result); |
2233 printf("Check result: %*s\n", value.length(), *value); | 2188 printf("Check result: %*s\n", value.length(), *value); |
2234 CHECK_EQ(0, value.length()); | 2189 CHECK_EQ(0, value.length()); |
2235 | 2190 |
2236 i::V8::SetPlatformForTesting(old_platform); | 2191 i::V8::SetPlatformForTesting(old_platform); |
2237 } | 2192 } |
OLD | NEW |