Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 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 "cctest.h" | 32 #include "cctest.h" |
| 33 #include "../include/v8-profiler.h" | 33 #include "../include/v8-profiler.h" |
| 34 #include "profiler-extension.h" | |
|
yurys
2013/06/13 09:11:35
Should be before #include "../include/v8-profiler.
loislo
2013/06/13 10:01:42
Done.
| |
| 34 | 35 |
| 35 using i::CodeEntry; | 36 using i::CodeEntry; |
| 36 using i::CodeMap; | 37 using i::CodeMap; |
| 37 using i::CpuProfile; | 38 using i::CpuProfile; |
| 38 using i::CpuProfiler; | 39 using i::CpuProfiler; |
| 39 using i::CpuProfilesCollection; | 40 using i::CpuProfilesCollection; |
| 40 using i::ProfileNode; | 41 using i::ProfileNode; |
| 41 using i::ProfileTree; | 42 using i::ProfileTree; |
| 42 using i::ProfileGenerator; | 43 using i::ProfileGenerator; |
| 43 using i::SampleRateCalculator; | 44 using i::SampleRateCalculator; |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 CpuProfile* profile = | 791 CpuProfile* profile = |
| 791 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); | 792 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); |
| 792 int nodeId = 1; | 793 int nodeId = 1; |
| 793 CheckNodeIds(profile->top_down()->root(), &nodeId); | 794 CheckNodeIds(profile->top_down()->root(), &nodeId); |
| 794 CHECK_EQ(3, nodeId - 1); | 795 CHECK_EQ(3, nodeId - 1); |
| 795 | 796 |
| 796 CHECK_EQ(0, profile->samples_count()); | 797 CHECK_EQ(0, profile->samples_count()); |
| 797 } | 798 } |
| 798 | 799 |
| 799 | 800 |
| 800 // --- P r o f i l e r E x t e n s i o n --- | |
| 801 | |
| 802 class ProfilerExtension : public v8::Extension { | |
| 803 public: | |
| 804 ProfilerExtension() : v8::Extension("v8/profiler", kSource) { } | |
| 805 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | |
| 806 v8::Handle<v8::String> name); | |
| 807 static v8::Handle<v8::Value> StartProfiling(const v8::Arguments& args); | |
| 808 static v8::Handle<v8::Value> StopProfiling(const v8::Arguments& args); | |
| 809 private: | |
| 810 static const char* kSource; | |
| 811 }; | |
| 812 | |
| 813 | |
| 814 const char* ProfilerExtension::kSource = | |
| 815 "native function startProfiling();" | |
| 816 "native function stopProfiling();"; | |
| 817 | |
| 818 v8::Handle<v8::FunctionTemplate> ProfilerExtension::GetNativeFunction( | |
| 819 v8::Handle<v8::String> name) { | |
| 820 if (name->Equals(v8::String::New("startProfiling"))) { | |
| 821 return v8::FunctionTemplate::New(ProfilerExtension::StartProfiling); | |
| 822 } else if (name->Equals(v8::String::New("stopProfiling"))) { | |
| 823 return v8::FunctionTemplate::New(ProfilerExtension::StopProfiling); | |
| 824 } else { | |
| 825 CHECK(false); | |
| 826 return v8::Handle<v8::FunctionTemplate>(); | |
| 827 } | |
| 828 } | |
| 829 | |
| 830 | |
| 831 v8::Handle<v8::Value> ProfilerExtension::StartProfiling( | |
| 832 const v8::Arguments& args) { | |
| 833 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); | |
| 834 if (args.Length() > 0) | |
| 835 cpu_profiler->StartCpuProfiling(args[0].As<v8::String>()); | |
| 836 else | |
| 837 cpu_profiler->StartCpuProfiling(v8::String::New("")); | |
| 838 return v8::Undefined(); | |
| 839 } | |
| 840 | |
| 841 | |
| 842 v8::Handle<v8::Value> ProfilerExtension::StopProfiling( | |
| 843 const v8::Arguments& args) { | |
| 844 v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler(); | |
| 845 if (args.Length() > 0) | |
| 846 cpu_profiler->StopCpuProfiling(args[0].As<v8::String>()); | |
| 847 else | |
| 848 cpu_profiler->StopCpuProfiling(v8::String::New("")); | |
| 849 return v8::Undefined(); | |
| 850 } | |
| 851 | |
| 852 | |
| 853 static ProfilerExtension kProfilerExtension; | |
| 854 v8::DeclareExtension kProfilerExtensionDeclaration(&kProfilerExtension); | |
| 855 | |
| 856 static const ProfileNode* PickChild(const ProfileNode* parent, | 801 static const ProfileNode* PickChild(const ProfileNode* parent, |
| 857 const char* name) { | 802 const char* name) { |
| 858 for (int i = 0; i < parent->children()->length(); ++i) { | 803 for (int i = 0; i < parent->children()->length(); ++i) { |
| 859 const ProfileNode* child = parent->children()->at(i); | 804 const ProfileNode* child = parent->children()->at(i); |
| 860 if (strcmp(child->entry()->name(), name) == 0) return child; | 805 if (strcmp(child->entry()->name(), name) == 0) return child; |
| 861 } | 806 } |
| 862 return NULL; | 807 return NULL; |
| 863 } | 808 } |
| 864 | 809 |
| 865 | 810 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 i::OS::SNPrintF(title, "%d", i); | 868 i::OS::SNPrintF(title, "%d", i); |
| 924 // UID must be > 0. | 869 // UID must be > 0. |
| 925 CHECK(collection.StartProfiling(title.start(), i + 1, false)); | 870 CHECK(collection.StartProfiling(title.start(), i + 1, false)); |
| 926 titles[i] = title.start(); | 871 titles[i] = title.start(); |
| 927 } | 872 } |
| 928 CHECK(!collection.StartProfiling( | 873 CHECK(!collection.StartProfiling( |
| 929 "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false)); | 874 "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false)); |
| 930 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) | 875 for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) |
| 931 i::DeleteArray(titles[i]); | 876 i::DeleteArray(titles[i]); |
| 932 } | 877 } |
| OLD | NEW |