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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 792 |
793 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 793 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
794 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 794 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
795 // TODO(yurys): in LoadIC should be changed to report external callback | 795 // TODO(yurys): in LoadIC should be changed to report external callback |
796 // invocation. See r13768 where it was LoadCallbackProperty was removed. | 796 // invocation. See r13768 where it was LoadCallbackProperty was removed. |
797 // GetChild(startNode, "get foo"); | 797 // GetChild(startNode, "get foo"); |
798 GetChild(startNode, "set foo"); | 798 GetChild(startNode, "set foo"); |
799 | 799 |
800 cpu_profiler->DeleteAllCpuProfiles(); | 800 cpu_profiler->DeleteAllCpuProfiles(); |
801 } | 801 } |
| 802 |
| 803 |
| 804 static const char* cpu_profiler_sourceURL_source = |
| 805 "function start(timeout) {\n" |
| 806 " var start = Date.now();\n" |
| 807 " var duration = 0;\n" |
| 808 " do {\n" |
| 809 " try {\n" |
| 810 " duration = Date.now() - start;\n" |
| 811 " } catch(e) { }\n" |
| 812 " } while (duration < timeout);\n" |
| 813 " return duration;\n" |
| 814 "}\n" |
| 815 "//# sourceURL=cpu_profiler_sourceURL_source.js"; |
| 816 |
| 817 |
| 818 TEST(SourceURLSupportForNewFunctions) { |
| 819 LocalContext env; |
| 820 v8::HandleScope scope(env->GetIsolate()); |
| 821 |
| 822 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 823 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 824 env->Global()->Get(v8::String::New("start"))); |
| 825 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 826 int32_t profiling_interval_ms = 100; |
| 827 |
| 828 // Cold run. |
| 829 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 830 cpu_profiler->StartCpuProfiling(profile_name); |
| 831 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 832 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 833 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 834 CHECK_NE(NULL, profile); |
| 835 |
| 836 // Dump collected profile to have a better diagnostic in case of failure. |
| 837 reinterpret_cast<i::CpuProfile*>( |
| 838 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 839 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 840 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 841 |
| 842 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 843 startNode->GetScriptResourceName()); |
| 844 |
| 845 cpu_profiler->DeleteAllCpuProfiles(); |
| 846 } |
| 847 |
| 848 TEST(LogExistingFunctionSourceURLCheck) { |
| 849 LocalContext env; |
| 850 v8::HandleScope scope(env->GetIsolate()); |
| 851 |
| 852 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 853 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 854 env->Global()->Get(v8::String::New("start"))); |
| 855 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 856 int32_t profiling_interval_ms = 100; |
| 857 |
| 858 // Warm up. |
| 859 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 860 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 861 |
| 862 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 863 cpu_profiler->StartCpuProfiling(profile_name); |
| 864 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 865 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 866 CHECK_NE(NULL, profile); |
| 867 |
| 868 // Dump collected profile to have a better diagnostic in case of failure. |
| 869 reinterpret_cast<i::CpuProfile*>( |
| 870 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 871 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 872 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 873 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 874 startNode->GetScriptResourceName()); |
| 875 |
| 876 cpu_profiler->DeleteAllCpuProfiles(); |
| 877 } |
OLD | NEW |