Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1093)

Side by Side Diff: test/cctest/test-profile-generator.cc

Issue 130213009: Various extension-related cleanup and simplifications. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Whitespace Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-log-stack-tracer.cc ('k') | test/cctest/trace-extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 545 }
546 return NULL; 546 return NULL;
547 } 547 }
548 548
549 549
550 TEST(RecordStackTraceAtStartProfiling) { 550 TEST(RecordStackTraceAtStartProfiling) {
551 // This test does not pass with inlining enabled since inlined functions 551 // This test does not pass with inlining enabled since inlined functions
552 // don't appear in the stack trace. 552 // don't appear in the stack trace.
553 i::FLAG_use_inlining = false; 553 i::FLAG_use_inlining = false;
554 554
555 v8::Isolate* isolate = CcTest::isolate(); 555 v8::HandleScope scope(CcTest::isolate());
556 v8::HandleScope scope(isolate); 556 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
557 const char* extensions[] = { "v8/profiler" }; 557 v8::Context::Scope context_scope(env);
558 v8::ExtensionConfiguration config(1, extensions);
559 v8::Local<v8::Context> context = v8::Context::New(isolate, &config);
560 context->Enter();
561 558
562 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); 559 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler();
563 CHECK_EQ(0, profiler->GetProfilesCount()); 560 CHECK_EQ(0, profiler->GetProfilesCount());
564 CompileRun( 561 CompileRun(
565 "function c() { startProfiling(); }\n" 562 "function c() { startProfiling(); }\n"
566 "function b() { c(); }\n" 563 "function b() { c(); }\n"
567 "function a() { b(); }\n" 564 "function a() { b(); }\n"
568 "a();\n" 565 "a();\n"
569 "stopProfiling();"); 566 "stopProfiling();");
570 CHECK_EQ(1, profiler->GetProfilesCount()); 567 CHECK_EQ(1, profiler->GetProfilesCount());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 620 }
624 return NULL; 621 return NULL;
625 } 622 }
626 623
627 624
628 TEST(ProfileNodeScriptId) { 625 TEST(ProfileNodeScriptId) {
629 // This test does not pass with inlining enabled since inlined functions 626 // This test does not pass with inlining enabled since inlined functions
630 // don't appear in the stack trace. 627 // don't appear in the stack trace.
631 i::FLAG_use_inlining = false; 628 i::FLAG_use_inlining = false;
632 629
633 const char* extensions[] = { "v8/profiler" }; 630 v8::HandleScope scope(CcTest::isolate());
634 v8::ExtensionConfiguration config(1, extensions); 631 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
635 LocalContext env(&config); 632 v8::Context::Scope context_scope(env);
636 v8::HandleScope hs(env->GetIsolate());
637 633
638 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); 634 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
639 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 635 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
640 CHECK_EQ(0, iprofiler->GetProfilesCount()); 636 CHECK_EQ(0, iprofiler->GetProfilesCount());
641 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::NewFromUtf8( 637 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::NewFromUtf8(
642 env->GetIsolate(), "function a() { startProfiling(); }\n")); 638 env->GetIsolate(), "function a() { startProfiling(); }\n"));
643 script_a->Run(); 639 script_a->Run();
644 v8::Handle<v8::Script> script_b = 640 v8::Handle<v8::Script> script_b =
645 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), 641 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
646 "function b() { a(); }\n" 642 "function b() { a(); }\n"
647 "b();\n" 643 "b();\n"
648 "stopProfiling();\n")); 644 "stopProfiling();\n"));
649 script_b->Run(); 645 script_b->Run();
650 CHECK_EQ(1, iprofiler->GetProfilesCount()); 646 CHECK_EQ(1, iprofiler->GetProfilesCount());
651 const v8::CpuProfile* profile = ProfilerExtension::last_profile; 647 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
652 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 648 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
653 reinterpret_cast<ProfileNode*>( 649 reinterpret_cast<ProfileNode*>(
654 const_cast<v8::CpuProfileNode*>(current))->Print(0); 650 const_cast<v8::CpuProfileNode*>(current))->Print(0);
655 // The tree should look like this: 651 // The tree should look like this:
656 // (root) 652 // (root)
657 // (anonymous function) 653 // (anonymous function)
658 // b 654 // b
659 // a 655 // a
660 // There can also be: 656 // There can also be:
661 // startProfiling 657 // startProfiling
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line")); 722 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_forth_line"));
727 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line")); 723 CHECK_EQ(2, GetFunctionLineNumber(&env, "bar_at_the_second_line"));
728 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line")); 724 CHECK_EQ(0, GetFunctionLineNumber(&env, "lazy_func_at_6th_line"));
729 725
730 profiler->StopProfiling("LineNumber"); 726 profiler->StopProfiling("LineNumber");
731 } 727 }
732 728
733 729
734 730
735 TEST(BailoutReason) { 731 TEST(BailoutReason) {
736 const char* extensions[] = { "v8/profiler" }; 732 v8::HandleScope scope(CcTest::isolate());
737 v8::ExtensionConfiguration config(1, extensions); 733 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
738 LocalContext env(&config); 734 v8::Context::Scope context_scope(env);
739 v8::HandleScope hs(env->GetIsolate());
740 735
741 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); 736 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
742 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 737 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
743 CHECK_EQ(0, iprofiler->GetProfilesCount()); 738 CHECK_EQ(0, iprofiler->GetProfilesCount());
744 v8::Handle<v8::Script> script = 739 v8::Handle<v8::Script> script =
745 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), 740 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
746 "function TryCatch() {\n" 741 "function TryCatch() {\n"
747 " try {\n" 742 " try {\n"
748 " startProfiling();\n" 743 " startProfiling();\n"
749 " } catch (e) { };\n" 744 " } catch (e) { };\n"
750 "}\n" 745 "}\n"
751 "function TryFinally() {\n" 746 "function TryFinally() {\n"
752 " try {\n" 747 " try {\n"
753 " TryCatch();\n" 748 " TryCatch();\n"
754 " } finally { };\n" 749 " } finally { };\n"
755 "}\n" 750 "}\n"
756 "TryFinally();\n" 751 "TryFinally();\n"
757 "stopProfiling();")); 752 "stopProfiling();"));
758 script->Run(); 753 script->Run();
759 CHECK_EQ(1, iprofiler->GetProfilesCount()); 754 CHECK_EQ(1, iprofiler->GetProfilesCount());
760 const v8::CpuProfile* profile = ProfilerExtension::last_profile; 755 const v8::CpuProfile* profile = i::ProfilerExtension::last_profile;
761 CHECK(profile); 756 CHECK(profile);
762 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 757 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
763 reinterpret_cast<ProfileNode*>( 758 reinterpret_cast<ProfileNode*>(
764 const_cast<v8::CpuProfileNode*>(current))->Print(0); 759 const_cast<v8::CpuProfileNode*>(current))->Print(0);
765 // The tree should look like this: 760 // The tree should look like this:
766 // (root) 761 // (root)
767 // (anonymous function) 762 // (anonymous function)
768 // kTryFinally 763 // kTryFinally
769 // kTryCatch 764 // kTryCatch
770 current = PickChild(current, i::ProfileGenerator::kAnonymousFunctionName); 765 current = PickChild(current, i::ProfileGenerator::kAnonymousFunctionName);
771 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 766 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
772 767
773 current = PickChild(current, "TryFinally"); 768 current = PickChild(current, "TryFinally");
774 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 769 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
775 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason())); 770 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason()));
776 771
777 current = PickChild(current, "TryCatch"); 772 current = PickChild(current, "TryCatch");
778 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 773 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
779 CHECK(!strcmp("TryCatchStatement", current->GetBailoutReason())); 774 CHECK(!strcmp("TryCatchStatement", current->GetBailoutReason()));
780 } 775 }
OLDNEW
« no previous file with comments | « test/cctest/test-log-stack-tracer.cc ('k') | test/cctest/trace-extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698