| 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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 function->Call(env->Global(), ARRAY_SIZE(args), args); | 795 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 796 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 796 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 797 | 797 |
| 798 CHECK_NE(NULL, profile); | 798 CHECK_NE(NULL, profile); |
| 799 // Dump collected profile to have a better diagnostic in case of failure. | 799 // Dump collected profile to have a better diagnostic in case of failure. |
| 800 reinterpret_cast<i::CpuProfile*>( | 800 reinterpret_cast<i::CpuProfile*>( |
| 801 const_cast<v8::CpuProfile*>(profile))->Print(); | 801 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 802 | 802 |
| 803 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 803 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 804 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 804 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 805 // TODO(yurys): in LoadIC should be changed to report external callback | 805 GetChild(startNode, "get foo"); |
| 806 // invocation. See r13768 where it was LoadCallbackProperty was removed. | |
| 807 // GetChild(startNode, "get foo"); | |
| 808 GetChild(startNode, "set foo"); | 806 GetChild(startNode, "set foo"); |
| 809 | 807 |
| 810 cpu_profiler->DeleteAllCpuProfiles(); | 808 cpu_profiler->DeleteAllCpuProfiles(); |
| 811 } | 809 } |
| 812 | 810 |
| 813 | 811 |
| 814 static const char* native_method_test_source = "function start(count) {\n" | 812 static const char* native_method_test_source = "function start(count) {\n" |
| 815 " for (var i = 0; i < count; i++) {\n" | 813 " for (var i = 0; i < count; i++) {\n" |
| 816 " instance.fooMethod();\n" | 814 " instance.fooMethod();\n" |
| 817 " }\n" | 815 " }\n" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 function->Call(env->Global(), ARRAY_SIZE(args), args); | 902 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 905 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 903 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 906 | 904 |
| 907 CHECK_NE(NULL, profile); | 905 CHECK_NE(NULL, profile); |
| 908 // Dump collected profile to have a better diagnostic in case of failure. | 906 // Dump collected profile to have a better diagnostic in case of failure. |
| 909 reinterpret_cast<i::CpuProfile*>( | 907 reinterpret_cast<i::CpuProfile*>( |
| 910 const_cast<v8::CpuProfile*>(profile))->Print(); | 908 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 911 | 909 |
| 912 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 913 GetChild(root, "start"); | 911 GetChild(root, "start"); |
| 914 // TODO(yurys): in CallIC should be changed to report external callback | 912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 915 // invocation. | 913 GetChild(startNode, "fooMethod"); |
| 916 // GetChild(startNode, "fooMethod"); | |
| 917 | 914 |
| 918 cpu_profiler->DeleteAllCpuProfiles(); | 915 cpu_profiler->DeleteAllCpuProfiles(); |
| 919 } | 916 } |
| 920 | |
| 921 | |
| 922 static const char* cpu_profiler_sourceURL_source = | |
| 923 "function start(timeout) {\n" | |
| 924 " var start = Date.now();\n" | |
| 925 " var duration = 0;\n" | |
| 926 " do {\n" | |
| 927 " try {\n" | |
| 928 " duration = Date.now() - start;\n" | |
| 929 " } catch(e) { }\n" | |
| 930 " } while (duration < timeout);\n" | |
| 931 " return duration;\n" | |
| 932 "}\n" | |
| 933 "//# sourceURL=cpu_profiler_sourceURL_source.js"; | |
| 934 | |
| 935 | |
| 936 TEST(SourceURLSupportForNewFunctions) { | |
| 937 LocalContext env; | |
| 938 v8::HandleScope scope(env->GetIsolate()); | |
| 939 | |
| 940 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | |
| 941 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | |
| 942 env->Global()->Get(v8::String::New("start"))); | |
| 943 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 944 int32_t profiling_interval_ms = 100; | |
| 945 | |
| 946 // Cold run. | |
| 947 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 948 cpu_profiler->StartCpuProfiling(profile_name); | |
| 949 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | |
| 950 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
| 951 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 952 CHECK_NE(NULL, profile); | |
| 953 | |
| 954 // Dump collected profile to have a better diagnostic in case of failure. | |
| 955 reinterpret_cast<i::CpuProfile*>( | |
| 956 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 957 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | |
| 958 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | |
| 959 | |
| 960 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | |
| 961 startNode->GetScriptResourceName()); | |
| 962 | |
| 963 cpu_profiler->DeleteAllCpuProfiles(); | |
| 964 } | |
| 965 | |
| 966 TEST(LogExistingFunctionSourceURLCheck) { | |
| 967 LocalContext env; | |
| 968 v8::HandleScope scope(env->GetIsolate()); | |
| 969 | |
| 970 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | |
| 971 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | |
| 972 env->Global()->Get(v8::String::New("start"))); | |
| 973 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 974 int32_t profiling_interval_ms = 100; | |
| 975 | |
| 976 // Warm up. | |
| 977 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | |
| 978 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
| 979 | |
| 980 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 981 cpu_profiler->StartCpuProfiling(profile_name); | |
| 982 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
| 983 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 984 CHECK_NE(NULL, profile); | |
| 985 | |
| 986 // Dump collected profile to have a better diagnostic in case of failure. | |
| 987 reinterpret_cast<i::CpuProfile*>( | |
| 988 const_cast<v8::CpuProfile*>(profile))->Print(); | |
| 989 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | |
| 990 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | |
| 991 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | |
| 992 startNode->GetScriptResourceName()); | |
| 993 | |
| 994 cpu_profiler->DeleteAllCpuProfiles(); | |
| 995 } | |
| OLD | NEW |