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

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 15995017: CPU profiler should support names of accessors set via v8::Object::SetAccessor (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 | « src/objects.cc ('k') | no next file » | 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 CHECK_EQ(1, startNode->GetChildrenCount()); 631 CHECK_EQ(1, startNode->GetChildrenCount());
632 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); 632 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay");
633 if (delayNode->GetChildrenCount() > 0) { 633 if (delayNode->GetChildrenCount() > 0) {
634 CHECK_EQ(1, delayNode->GetChildrenCount()); 634 CHECK_EQ(1, delayNode->GetChildrenCount());
635 GetChild(delayNode, "loop"); 635 GetChild(delayNode, "loop");
636 } 636 }
637 } 637 }
638 638
639 cpu_profiler->DeleteAllCpuProfiles(); 639 cpu_profiler->DeleteAllCpuProfiles();
640 } 640 }
641
642
643 static const char* native_accessor_test_source = "function start(count) {\n"
644 " for (var i = 0; i < count; i++) {\n"
645 " var o = instance.foo;\n"
646 " instance.foo = o + 1;\n"
647 " }\n"
648 "}\n";
649
650
651 class FooAccessorsData {
652 public:
653 explicit FooAccessorsData(int min_duration_ms)
654 : min_duration_ms_(min_duration_ms) {}
655
656 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name,
657 const v8::AccessorInfo& info) {
658 FooAccessorsData* data = fromInfo(info);
659 data->Wait();
660 return v8::Int32::New(2013);
661 }
662
663 static void Setter(v8::Local<v8::String> name,
664 v8::Local<v8::Value> value,
665 const v8::AccessorInfo& info) {
666 FooAccessorsData* data = fromInfo(info);
667 data->Wait();
668 }
669
670 private:
671 void Wait() {
672 double start = i::OS::TimeCurrentMillis();
673 for (double duration = 0; duration < min_duration_ms_; ) {
674 duration = i::OS::TimeCurrentMillis() - start;
675 }
676 }
677
678 static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) {
679 void* data = v8::External::Cast(*info.Data())->Value();
680 return reinterpret_cast<FooAccessorsData*>(data);
681 }
682
683 int min_duration_ms_;
684 };
685
686
687 // Test that native accessors are properly reported in the CPU profile.
688 // This test checks the case when the long-running accessors are called
689 // only once and the optimizer doesn't have chance to change the invocation
690 // code.
691 TEST(NativeAccessorNameInProfile1) {
692 LocalContext env;
693 v8::HandleScope scope(env->GetIsolate());
694
695
696 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
697 v8::Local<v8::ObjectTemplate> instance_template =
698 func_template->InstanceTemplate();
699
700 FooAccessorsData accessors(100);
701 v8::Local<v8::External> data = v8::External::New(&accessors);
702 instance_template->SetAccessor(
703 v8::String::New("foo"), &FooAccessorsData::Getter,
704 &FooAccessorsData::Setter, data);
705 v8::Local<v8::Function> func = func_template->GetFunction();
706 v8::Local<v8::Object> instance = func->NewInstance();
707 env->Global()->Set(v8::String::New("instance"), instance);
708
709 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run();
710 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
711 env->Global()->Get(v8::String::New("start")));
712
713 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
714 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
715
716 cpu_profiler->StartCpuProfiling(profile_name);
717 int32_t repeat_count = 1;
718 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
719 function->Call(env->Global(), ARRAY_SIZE(args), args);
720 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
721
722 CHECK_NE(NULL, profile);
723 // Dump collected profile to have a better diagnostic in case of failure.
724 reinterpret_cast<i::CpuProfile*>(
725 const_cast<v8::CpuProfile*>(profile))->Print();
726
727 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
728 const v8::CpuProfileNode* startNode = GetChild(root, "start");
729 GetChild(startNode, "get foo");
730 GetChild(startNode, "set foo");
731
732 cpu_profiler->DeleteAllCpuProfiles();
733 }
734
735
736 // Test that native accessors are properly reported in the CPU profile.
737 // This test makes sure that the accessors are called enough times to become
738 // hot and to trigger optimizations.
739 TEST(NativeAccessorNameInProfile2) {
740 LocalContext env;
741 v8::HandleScope scope(env->GetIsolate());
742
743
744 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
745 v8::Local<v8::ObjectTemplate> instance_template =
746 func_template->InstanceTemplate();
747
748 FooAccessorsData accessors(1);
749 v8::Local<v8::External> data = v8::External::New(&accessors);
750 instance_template->SetAccessor(
751 v8::String::New("foo"), &FooAccessorsData::Getter,
752 &FooAccessorsData::Setter, data);
753 v8::Local<v8::Function> func = func_template->GetFunction();
754 v8::Local<v8::Object> instance = func->NewInstance();
755 env->Global()->Set(v8::String::New("instance"), instance);
756
757 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run();
758 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
759 env->Global()->Get(v8::String::New("start")));
760
761 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
762 v8::Local<v8::String> profile_name = v8::String::New("my_profile");
763
764 cpu_profiler->StartCpuProfiling(profile_name);
765 int32_t repeat_count = 100;
766 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) };
767 function->Call(env->Global(), ARRAY_SIZE(args), args);
768 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name);
769
770 CHECK_NE(NULL, profile);
771 // Dump collected profile to have a better diagnostic in case of failure.
772 reinterpret_cast<i::CpuProfile*>(
773 const_cast<v8::CpuProfile*>(profile))->Print();
774
775 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
776 const v8::CpuProfileNode* startNode = GetChild(root, "start");
777 // TODO(yurys): in LoadIC should be changed to report external callback
778 // invocation. See r13768 where it was LoadCallbackProperty was removed.
779 // GetChild(startNode, "get foo");
780 GetChild(startNode, "set foo");
781
782 cpu_profiler->DeleteAllCpuProfiles();
783 }
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698