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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 " instance.foo = o + 1;\n" | 646 " instance.foo = o + 1;\n" |
647 " }\n" | 647 " }\n" |
648 "}\n"; | 648 "}\n"; |
649 | 649 |
650 | 650 |
651 class FooAccessorsData { | 651 class FooAccessorsData { |
652 public: | 652 public: |
653 explicit FooAccessorsData(int min_duration_ms) | 653 explicit FooAccessorsData(int min_duration_ms) |
654 : min_duration_ms_(min_duration_ms), | 654 : min_duration_ms_(min_duration_ms), |
655 getter_duration_(0), | 655 getter_duration_(0), |
656 setter_duration_(0) {} | 656 setter_duration_(0), |
| 657 getter_iterations_(0), |
| 658 setter_iterations_(0) {} |
657 | 659 |
658 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name, | 660 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name, |
659 const v8::AccessorInfo& info) { | 661 const v8::AccessorInfo& info) { |
660 FooAccessorsData* data = fromInfo(info); | 662 FooAccessorsData* data = fromInfo(info); |
661 data->getter_duration_ = data->Wait(); | 663 data->getter_duration_ = data->Wait(&data->getter_iterations_); |
662 return v8::Int32::New(2013); | 664 return v8::Int32::New(2013); |
663 } | 665 } |
664 | 666 |
665 static void Setter(v8::Local<v8::String> name, | 667 static void Setter(v8::Local<v8::String> name, |
666 v8::Local<v8::Value> value, | 668 v8::Local<v8::Value> value, |
667 const v8::AccessorInfo& info) { | 669 const v8::AccessorInfo& info) { |
668 FooAccessorsData* data = fromInfo(info); | 670 FooAccessorsData* data = fromInfo(info); |
669 data->setter_duration_ = data->Wait(); | 671 data->setter_duration_ = data->Wait(&data->setter_iterations_); |
670 } | 672 } |
671 | 673 |
672 void PrintAccessorTime() { | 674 void PrintAccessorTime() { |
673 i::OS::Print("getter: %f ms; setter: %f ms\n", getter_duration_, | 675 i::OS::Print("getter: %f ms (%d); setter: %f ms (%d)\n", getter_duration_, |
674 setter_duration_); | 676 getter_iterations_, setter_duration_, setter_iterations_); |
675 } | 677 } |
676 | 678 |
677 private: | 679 private: |
678 double Wait() { | 680 double Wait(int* iterations) { |
679 double start = i::OS::TimeCurrentMillis(); | 681 double start = i::OS::TimeCurrentMillis(); |
680 double duration = 0; | 682 double duration = 0; |
681 while (duration < min_duration_ms_) { | 683 while (duration < min_duration_ms_) { |
682 duration = i::OS::TimeCurrentMillis() - start; | 684 duration = i::OS::TimeCurrentMillis() - start; |
| 685 ++*iterations; |
683 } | 686 } |
684 return duration; | 687 return duration; |
685 } | 688 } |
686 | 689 |
687 static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) { | 690 static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) { |
688 void* data = v8::External::Cast(*info.Data())->Value(); | 691 void* data = v8::External::Cast(*info.Data())->Value(); |
689 return reinterpret_cast<FooAccessorsData*>(data); | 692 return reinterpret_cast<FooAccessorsData*>(data); |
690 } | 693 } |
691 | 694 |
692 int min_duration_ms_; | 695 int min_duration_ms_; |
693 double getter_duration_; | 696 double getter_duration_; |
694 double setter_duration_; | 697 double setter_duration_; |
| 698 int getter_iterations_; |
| 699 int setter_iterations_; |
695 }; | 700 }; |
696 | 701 |
697 | 702 |
698 // Test that native accessors are properly reported in the CPU profile. | 703 // Test that native accessors are properly reported in the CPU profile. |
699 // This test checks the case when the long-running accessors are called | 704 // This test checks the case when the long-running accessors are called |
700 // only once and the optimizer doesn't have chance to change the invocation | 705 // only once and the optimizer doesn't have chance to change the invocation |
701 // code. | 706 // code. |
702 TEST(NativeAccessorNameInProfile1) { | 707 TEST(NativeAccessorNameInProfile1) { |
703 LocalContext env; | 708 LocalContext env; |
704 v8::HandleScope scope(env->GetIsolate()); | 709 v8::HandleScope scope(env->GetIsolate()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 | 791 |
787 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 792 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
788 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 793 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
789 // TODO(yurys): in LoadIC should be changed to report external callback | 794 // TODO(yurys): in LoadIC should be changed to report external callback |
790 // invocation. See r13768 where it was LoadCallbackProperty was removed. | 795 // invocation. See r13768 where it was LoadCallbackProperty was removed. |
791 // GetChild(startNode, "get foo"); | 796 // GetChild(startNode, "get foo"); |
792 GetChild(startNode, "set foo"); | 797 GetChild(startNode, "set foo"); |
793 | 798 |
794 cpu_profiler->DeleteAllCpuProfiles(); | 799 cpu_profiler->DeleteAllCpuProfiles(); |
795 } | 800 } |
OLD | NEW |