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

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

Issue 117353002: Delete several deprecated methods on v8::CpuProfiler (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years 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
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 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 // 27 //
28 // Tests of profiles generator and utilities. 28 // Tests of profiles generator and utilities.
29 29
30 #include "v8.h" 30 #include "v8.h"
31 #include "profile-generator-inl.h" 31 #include "profile-generator-inl.h"
32 #include "profiler-extension.h"
32 #include "cctest.h" 33 #include "cctest.h"
33 #include "cpu-profiler.h" 34 #include "cpu-profiler.h"
34 #include "../include/v8-profiler.h" 35 #include "../include/v8-profiler.h"
35 36
36 using i::CodeEntry; 37 using i::CodeEntry;
37 using i::CodeMap; 38 using i::CodeMap;
38 using i::CpuProfile; 39 using i::CpuProfile;
39 using i::CpuProfiler; 40 using i::CpuProfiler;
40 using i::CpuProfilesCollection; 41 using i::CpuProfilesCollection;
41 using i::ProfileNode; 42 using i::ProfileNode;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 530
530 CpuProfile* profile = profiles.StopProfiling(""); 531 CpuProfile* profile = profiles.StopProfiling("");
531 int nodeId = 1; 532 int nodeId = 1;
532 CheckNodeIds(profile->top_down()->root(), &nodeId); 533 CheckNodeIds(profile->top_down()->root(), &nodeId);
533 CHECK_EQ(3, nodeId - 1); 534 CHECK_EQ(3, nodeId - 1);
534 535
535 CHECK_EQ(0, profile->samples_count()); 536 CHECK_EQ(0, profile->samples_count());
536 } 537 }
537 538
538 539
539 // --- P r o f i l e r E x t e n s i o n ---
540
541 class ProfilerExtension : public v8::Extension {
542 public:
543 ProfilerExtension() : v8::Extension("v8/profiler", kSource) { }
544 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
545 v8::Isolate* isolate,
546 v8::Handle<v8::String> name);
547 static void StartProfiling(const v8::FunctionCallbackInfo<v8::Value>& args);
548 static void StopProfiling(const v8::FunctionCallbackInfo<v8::Value>& args);
549 private:
550 static const char* kSource;
551 };
552
553
554 const char* ProfilerExtension::kSource =
555 "native function startProfiling();"
556 "native function stopProfiling();";
557
558 v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunctionTemplate(
559 v8::Isolate* isolate, v8::Handle<v8::String> name) {
560 if (name->Equals(v8::String::NewFromUtf8(isolate, "startProfiling"))) {
561 return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling);
562 } else if (name->Equals(v8::String::NewFromUtf8(isolate, "stopProfiling"))) {
563 return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling);
564 } else {
565 CHECK(false);
566 return v8::Handle<v8::FunctionTemplate>();
567 }
568 }
569
570
571 void ProfilerExtension::StartProfiling(
572 const v8::FunctionCallbackInfo<v8::Value>& args) {
573 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
574 if (args.Length() > 0)
575 cpu_profiler->StartCpuProfiling(args[0].As<v8::String>());
576 else
577 cpu_profiler->StartCpuProfiling(
578 v8::String::NewFromUtf8(args.GetIsolate(), ""));
579 }
580
581
582 void ProfilerExtension::StopProfiling(
583 const v8::FunctionCallbackInfo<v8::Value>& args) {
584 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
585 if (args.Length() > 0)
586 cpu_profiler->StopCpuProfiling(args[0].As<v8::String>());
587 else
588 cpu_profiler->StopCpuProfiling(
589 v8::String::NewFromUtf8(args.GetIsolate(), ""));
590 }
591
592
593 static ProfilerExtension kProfilerExtension;
594 v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension);
595
596 static const ProfileNode* PickChild(const ProfileNode* parent, 540 static const ProfileNode* PickChild(const ProfileNode* parent,
597 const char* name) { 541 const char* name) {
598 for (int i = 0; i < parent->children()->length(); ++i) { 542 for (int i = 0; i < parent->children()->length(); ++i) {
599 const ProfileNode* child = parent->children()->at(i); 543 const ProfileNode* child = parent->children()->at(i);
600 if (strcmp(child->entry()->name(), name) == 0) return child; 544 if (strcmp(child->entry()->name(), name) == 0) return child;
601 } 545 }
602 return NULL; 546 return NULL;
603 } 547 }
604 548
605 549
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 // This test does not pass with inlining enabled since inlined functions 631 // This test does not pass with inlining enabled since inlined functions
688 // don't appear in the stack trace. 632 // don't appear in the stack trace.
689 i::FLAG_use_inlining = false; 633 i::FLAG_use_inlining = false;
690 634
691 const char* extensions[] = { "v8/profiler" }; 635 const char* extensions[] = { "v8/profiler" };
692 v8::ExtensionConfiguration config(1, extensions); 636 v8::ExtensionConfiguration config(1, extensions);
693 LocalContext env(&config); 637 LocalContext env(&config);
694 v8::HandleScope hs(env->GetIsolate()); 638 v8::HandleScope hs(env->GetIsolate());
695 639
696 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); 640 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
697 CHECK_EQ(0, profiler->GetProfileCount()); 641 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
642 CHECK_EQ(0, iprofiler->GetProfilesCount());
698 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::NewFromUtf8( 643 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::NewFromUtf8(
699 env->GetIsolate(), "function a() { startProfiling(); }\n")); 644 env->GetIsolate(), "function a() { startProfiling(); }\n"));
700 script_a->Run(); 645 script_a->Run();
701 v8::Handle<v8::Script> script_b = 646 v8::Handle<v8::Script> script_b =
702 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), 647 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
703 "function b() { a(); }\n" 648 "function b() { a(); }\n"
704 "b();\n" 649 "b();\n"
705 "stopProfiling();\n")); 650 "stopProfiling();\n"));
706 script_b->Run(); 651 script_b->Run();
707 CHECK_EQ(1, profiler->GetProfileCount()); 652 CHECK_EQ(1, iprofiler->GetProfilesCount());
708 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); 653 const v8::CpuProfile* profile = ProfilerExtension::last_profile;
709 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 654 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
710 reinterpret_cast<ProfileNode*>( 655 reinterpret_cast<ProfileNode*>(
711 const_cast<v8::CpuProfileNode*>(current))->Print(0); 656 const_cast<v8::CpuProfileNode*>(current))->Print(0);
712 // The tree should look like this: 657 // The tree should look like this:
713 // (root) 658 // (root)
714 // (anonymous function) 659 // (anonymous function)
715 // b 660 // b
716 // a 661 // a
717 // There can also be: 662 // There can also be:
718 // startProfiling 663 // startProfiling
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 734
790 735
791 736
792 TEST(BailoutReason) { 737 TEST(BailoutReason) {
793 const char* extensions[] = { "v8/profiler" }; 738 const char* extensions[] = { "v8/profiler" };
794 v8::ExtensionConfiguration config(1, extensions); 739 v8::ExtensionConfiguration config(1, extensions);
795 LocalContext env(&config); 740 LocalContext env(&config);
796 v8::HandleScope hs(env->GetIsolate()); 741 v8::HandleScope hs(env->GetIsolate());
797 742
798 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); 743 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
799 CHECK_EQ(0, profiler->GetProfileCount()); 744 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
745 CHECK_EQ(0, iprofiler->GetProfilesCount());
800 v8::Handle<v8::Script> script = 746 v8::Handle<v8::Script> script =
801 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), 747 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
802 "function TryCatch() {\n" 748 "function TryCatch() {\n"
803 " try {\n" 749 " try {\n"
804 " startProfiling();\n" 750 " startProfiling();\n"
805 " } catch (e) { };\n" 751 " } catch (e) { };\n"
806 "}\n" 752 "}\n"
807 "function TryFinally() {\n" 753 "function TryFinally() {\n"
808 " try {\n" 754 " try {\n"
809 " TryCatch();\n" 755 " TryCatch();\n"
810 " } finally { };\n" 756 " } finally { };\n"
811 "}\n" 757 "}\n"
812 "TryFinally();\n" 758 "TryFinally();\n"
813 "stopProfiling();")); 759 "stopProfiling();"));
814 script->Run(); 760 script->Run();
815 CHECK_EQ(1, profiler->GetProfileCount()); 761 CHECK_EQ(1, iprofiler->GetProfilesCount());
816 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); 762 const v8::CpuProfile* profile = ProfilerExtension::last_profile;
763 CHECK(profile);
817 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); 764 const v8::CpuProfileNode* current = profile->GetTopDownRoot();
818 reinterpret_cast<ProfileNode*>( 765 reinterpret_cast<ProfileNode*>(
819 const_cast<v8::CpuProfileNode*>(current))->Print(0); 766 const_cast<v8::CpuProfileNode*>(current))->Print(0);
820 // The tree should look like this: 767 // The tree should look like this:
821 // (root) 768 // (root)
822 // (anonymous function) 769 // (anonymous function)
823 // kTryFinally 770 // kTryFinally
824 // kTryCatch 771 // kTryCatch
825 current = PickChild(current, i::ProfileGenerator::kAnonymousFunctionName); 772 current = PickChild(current, i::ProfileGenerator::kAnonymousFunctionName);
826 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 773 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
827 774
828 current = PickChild(current, "TryFinally"); 775 current = PickChild(current, "TryFinally");
829 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 776 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
830 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason())); 777 CHECK(!strcmp("TryFinallyStatement", current->GetBailoutReason()));
831 778
832 current = PickChild(current, "TryCatch"); 779 current = PickChild(current, "TryCatch");
833 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current)); 780 CHECK_NE(NULL, const_cast<v8::CpuProfileNode*>(current));
834 CHECK(!strcmp("TryCatchStatement", current->GetBailoutReason())); 781 CHECK(!strcmp("TryCatchStatement", current->GetBailoutReason()));
835 } 782 }
OLDNEW
« test/cctest/test-cpu-profiler.cc ('K') | « test/cctest/test-cpu-profiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698