| 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 14 matching lines...) Expand all Loading... |
| 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 #define V8_DISABLE_DEPRECATIONS 1 | 30 #define V8_DISABLE_DEPRECATIONS 1 |
| 31 #include "v8.h" | 31 #include "v8.h" |
| 32 #include "cpu-profiler-inl.h" | 32 #include "cpu-profiler-inl.h" |
| 33 #include "cctest.h" | 33 #include "cctest.h" |
| 34 #include "utils.h" | 34 #include "utils.h" |
| 35 #include "profiler-extension.h" |
| 35 #include "../include/v8-profiler.h" | 36 #include "../include/v8-profiler.h" |
| 36 #undef V8_DISABLE_DEPRECATIONS | 37 #undef V8_DISABLE_DEPRECATIONS |
| 37 | 38 |
| 38 using i::CodeEntry; | 39 using i::CodeEntry; |
| 39 using i::CpuProfile; | 40 using i::CpuProfile; |
| 40 using i::CpuProfiler; | 41 using i::CpuProfiler; |
| 41 using i::CpuProfilesCollection; | 42 using i::CpuProfilesCollection; |
| 42 using i::ProfileGenerator; | 43 using i::ProfileGenerator; |
| 43 using i::ProfileNode; | 44 using i::ProfileNode; |
| 44 using i::ProfilerEventsProcessor; | 45 using i::ProfilerEventsProcessor; |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 GetChild(root, "start"); | 914 GetChild(root, "start"); |
| 914 // TODO(yurys): in CallIC should be changed to report external callback | 915 // TODO(yurys): in CallIC should be changed to report external callback |
| 915 // invocation. | 916 // invocation. |
| 916 // GetChild(startNode, "fooMethod"); | 917 // GetChild(startNode, "fooMethod"); |
| 917 | 918 |
| 918 cpu_profiler->DeleteAllCpuProfiles(); | 919 cpu_profiler->DeleteAllCpuProfiles(); |
| 919 } | 920 } |
| 920 | 921 |
| 921 | 922 |
| 922 static const char* cpu_profiler_sourceURL_source = | 923 static const char* cpu_profiler_sourceURL_source = |
| 923 "function start(timeout) {\n" | 924 "function start(warm_up) {\n" |
| 924 " var start = Date.now();\n" | 925 " if (!warm_up) {\n" |
| 925 " var duration = 0;\n" | 926 " startProfiling();\n" |
| 926 " do {\n" | 927 " stopProfiling();\n" |
| 927 " try {\n" | 928 " }\n" |
| 928 " duration = Date.now() - start;\n" | |
| 929 " } catch(e) { }\n" | |
| 930 " } while (duration < timeout);\n" | |
| 931 " return duration;\n" | |
| 932 "}\n" | 929 "}\n" |
| 933 "//# sourceURL=cpu_profiler_sourceURL_source.js"; | 930 "//# sourceURL=cpu_profiler_sourceURL_source.js"; |
| 934 | 931 |
| 935 | 932 |
| 936 TEST(SourceURLSupportForNewFunctions) { | 933 TEST(SourceURLSupportForNewFunctions) { |
| 937 LocalContext env; | 934 const char* extensions[] = { i::ProfilerExtension::kName }; |
| 935 v8::ExtensionConfiguration config(1, extensions); |
| 936 LocalContext env(&config); |
| 938 v8::HandleScope scope(env->GetIsolate()); | 937 v8::HandleScope scope(env->GetIsolate()); |
| 939 | 938 |
| 940 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | 939 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 940 v8::Local<v8::Object> global = env->Global(); |
| 941 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 941 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 942 env->Global()->Get(v8::String::New("start"))); | 942 global->Get(v8::String::New("start"))); |
| 943 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 943 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 944 int32_t profiling_interval_ms = 200; | 944 CHECK_NE(NULL, cpu_profiler); |
| 945 #if defined(_WIN32) || defined(_WIN64) | 945 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
| 946 // 200ms is not enough on Windows. See | |
| 947 // https://code.google.com/p/v8/issues/detail?id=2628 | |
| 948 profiling_interval_ms = 500; | |
| 949 #endif | |
| 950 | 946 |
| 951 // Cold run. | 947 // Cold run. |
| 952 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 948 v8::Handle<v8::Value> args[] = { v8::Boolean::New(false) }; |
| 953 cpu_profiler->StartCpuProfiling(profile_name); | 949 function->Call(global, ARRAY_SIZE(args), args); |
| 954 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 950 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 955 function->Call(env->Global(), ARRAY_SIZE(args), args); | 951 const v8::CpuProfile* profile = cpu_profiler->GetCpuProfile(0); |
| 956 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 957 CHECK_NE(NULL, profile); | 952 CHECK_NE(NULL, profile); |
| 958 | 953 |
| 959 // Dump collected profile to have a better diagnostic in case of failure. | 954 // Dump collected profile to have a better diagnostic in case of failure. |
| 960 reinterpret_cast<i::CpuProfile*>( | 955 reinterpret_cast<i::CpuProfile*>( |
| 961 const_cast<v8::CpuProfile*>(profile))->Print(); | 956 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 962 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 957 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 963 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 958 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 964 | 959 |
| 965 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | 960 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 966 startNode->GetScriptResourceName()); | 961 startNode->GetScriptResourceName()); |
| 967 | 962 |
| 968 cpu_profiler->DeleteAllCpuProfiles(); | 963 cpu_profiler->DeleteAllCpuProfiles(); |
| 969 } | 964 } |
| 970 | 965 |
| 971 TEST(LogExistingFunctionSourceURLCheck) { | 966 TEST(LogExistingFunctionSourceURLCheck) { |
| 972 LocalContext env; | 967 const char* extensions[] = { i::ProfilerExtension::kName }; |
| 968 v8::ExtensionConfiguration config(1, extensions); |
| 969 LocalContext env(&config); |
| 973 v8::HandleScope scope(env->GetIsolate()); | 970 v8::HandleScope scope(env->GetIsolate()); |
| 974 | 971 |
| 975 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | 972 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 973 v8::Local<v8::Object> global = env->Global(); |
| 976 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 974 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 977 env->Global()->Get(v8::String::New("start"))); | 975 global->Get(v8::String::New("start"))); |
| 978 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 976 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 979 int32_t profiling_interval_ms = 200; | 977 CHECK_NE(NULL, cpu_profiler); |
| 978 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
| 980 | 979 |
| 981 // Warm up. | 980 // Warm up. |
| 982 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 981 v8::Handle<v8::Value> warm_up_args[] = { v8::Boolean::New(true) }; |
| 983 function->Call(env->Global(), ARRAY_SIZE(args), args); | 982 function->Call(global, ARRAY_SIZE(warm_up_args), warm_up_args); |
| 983 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
| 984 | 984 |
| 985 #if defined(_WIN32) || defined(_WIN64) | 985 // Run. |
| 986 // 200ms is not enough on Windows. See | 986 v8::Handle<v8::Value> args[] = { v8::Boolean::New(false) }; |
| 987 // https://code.google.com/p/v8/issues/detail?id=2628 | 987 function->Call(global, ARRAY_SIZE(args), args); |
| 988 profiling_interval_ms = 500; | 988 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 989 #endif | 989 const v8::CpuProfile* profile = cpu_profiler->GetCpuProfile(0); |
| 990 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
| 991 cpu_profiler->StartCpuProfiling(profile_name); | |
| 992 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
| 993 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 994 CHECK_NE(NULL, profile); | 990 CHECK_NE(NULL, profile); |
| 995 | 991 |
| 996 // Dump collected profile to have a better diagnostic in case of failure. | 992 // Dump collected profile to have a better diagnostic in case of failure. |
| 997 reinterpret_cast<i::CpuProfile*>( | 993 reinterpret_cast<i::CpuProfile*>( |
| 998 const_cast<v8::CpuProfile*>(profile))->Print(); | 994 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 999 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 995 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1000 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 996 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 1001 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | 997 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 1002 startNode->GetScriptResourceName()); | 998 startNode->GetScriptResourceName()); |
| 1003 | 999 |
| 1004 cpu_profiler->DeleteAllCpuProfiles(); | 1000 cpu_profiler->DeleteAllCpuProfiles(); |
| 1005 } | 1001 } |
| OLD | NEW |