| 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 " for (var i = 0; i < count; i++) {\n" | 644 " for (var i = 0; i < count; i++) {\n" |
| 645 " var o = instance.foo;\n" | 645 " var o = instance.foo;\n" |
| 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), |
| 656 setter_duration_(0) {} |
| 655 | 657 |
| 656 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name, | 658 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> name, |
| 657 const v8::AccessorInfo& info) { | 659 const v8::AccessorInfo& info) { |
| 658 FooAccessorsData* data = fromInfo(info); | 660 FooAccessorsData* data = fromInfo(info); |
| 659 data->Wait(); | 661 data->getter_duration_ = data->Wait(); |
| 660 return v8::Int32::New(2013); | 662 return v8::Int32::New(2013); |
| 661 } | 663 } |
| 662 | 664 |
| 663 static void Setter(v8::Local<v8::String> name, | 665 static void Setter(v8::Local<v8::String> name, |
| 664 v8::Local<v8::Value> value, | 666 v8::Local<v8::Value> value, |
| 665 const v8::AccessorInfo& info) { | 667 const v8::AccessorInfo& info) { |
| 666 FooAccessorsData* data = fromInfo(info); | 668 FooAccessorsData* data = fromInfo(info); |
| 667 data->Wait(); | 669 data->setter_duration_ = data->Wait(); |
| 670 } |
| 671 |
| 672 void PrintAccessorTime() { |
| 673 i::OS::Print("getter: %f ms; setter: %f ms\n", getter_duration_, |
| 674 setter_duration_); |
| 668 } | 675 } |
| 669 | 676 |
| 670 private: | 677 private: |
| 671 void Wait() { | 678 double Wait() { |
| 672 double start = i::OS::TimeCurrentMillis(); | 679 double start = i::OS::TimeCurrentMillis(); |
| 673 for (double duration = 0; duration < min_duration_ms_; ) { | 680 double duration = 0; |
| 681 while (duration < min_duration_ms_) { |
| 674 duration = i::OS::TimeCurrentMillis() - start; | 682 duration = i::OS::TimeCurrentMillis() - start; |
| 675 } | 683 } |
| 684 return duration; |
| 676 } | 685 } |
| 677 | 686 |
| 678 static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) { | 687 static FooAccessorsData* fromInfo(const v8::AccessorInfo& info) { |
| 679 void* data = v8::External::Cast(*info.Data())->Value(); | 688 void* data = v8::External::Cast(*info.Data())->Value(); |
| 680 return reinterpret_cast<FooAccessorsData*>(data); | 689 return reinterpret_cast<FooAccessorsData*>(data); |
| 681 } | 690 } |
| 682 | 691 |
| 683 int min_duration_ms_; | 692 int min_duration_ms_; |
| 693 double getter_duration_; |
| 694 double setter_duration_; |
| 684 }; | 695 }; |
| 685 | 696 |
| 686 | 697 |
| 687 // Test that native accessors are properly reported in the CPU profile. | 698 // Test that native accessors are properly reported in the CPU profile. |
| 688 // This test checks the case when the long-running accessors are called | 699 // 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 | 700 // only once and the optimizer doesn't have chance to change the invocation |
| 690 // code. | 701 // code. |
| 691 TEST(NativeAccessorNameInProfile1) { | 702 TEST(NativeAccessorNameInProfile1) { |
| 692 LocalContext env; | 703 LocalContext env; |
| 693 v8::HandleScope scope(env->GetIsolate()); | 704 v8::HandleScope scope(env->GetIsolate()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 716 cpu_profiler->StartCpuProfiling(profile_name); | 727 cpu_profiler->StartCpuProfiling(profile_name); |
| 717 int32_t repeat_count = 1; | 728 int32_t repeat_count = 1; |
| 718 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 729 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 719 function->Call(env->Global(), ARRAY_SIZE(args), args); | 730 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 720 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 731 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 721 | 732 |
| 722 CHECK_NE(NULL, profile); | 733 CHECK_NE(NULL, profile); |
| 723 // Dump collected profile to have a better diagnostic in case of failure. | 734 // Dump collected profile to have a better diagnostic in case of failure. |
| 724 reinterpret_cast<i::CpuProfile*>( | 735 reinterpret_cast<i::CpuProfile*>( |
| 725 const_cast<v8::CpuProfile*>(profile))->Print(); | 736 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 737 accessors.PrintAccessorTime(); |
| 726 | 738 |
| 727 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 739 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 728 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 740 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 729 GetChild(startNode, "get foo"); | 741 GetChild(startNode, "get foo"); |
| 730 GetChild(startNode, "set foo"); | 742 GetChild(startNode, "set foo"); |
| 731 | 743 |
| 732 cpu_profiler->DeleteAllCpuProfiles(); | 744 cpu_profiler->DeleteAllCpuProfiles(); |
| 733 } | 745 } |
| 734 | 746 |
| 735 | 747 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 | 786 |
| 775 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 787 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 776 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 788 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 777 // TODO(yurys): in LoadIC should be changed to report external callback | 789 // TODO(yurys): in LoadIC should be changed to report external callback |
| 778 // invocation. See r13768 where it was LoadCallbackProperty was removed. | 790 // invocation. See r13768 where it was LoadCallbackProperty was removed. |
| 779 // GetChild(startNode, "get foo"); | 791 // GetChild(startNode, "get foo"); |
| 780 GetChild(startNode, "set foo"); | 792 GetChild(startNode, "set foo"); |
| 781 | 793 |
| 782 cpu_profiler->DeleteAllCpuProfiles(); | 794 cpu_profiler->DeleteAllCpuProfiles(); |
| 783 } | 795 } |
| OLD | NEW |