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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 const_cast<v8::CpuProfile*>(profile))->Print(); | 910 const_cast<v8::CpuProfile*>(profile))->Print(); |
911 | 911 |
912 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 912 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
913 GetChild(root, "start"); | 913 GetChild(root, "start"); |
914 // TODO(yurys): in CallIC should be changed to report external callback | 914 // TODO(yurys): in CallIC should be changed to report external callback |
915 // invocation. | 915 // invocation. |
916 // GetChild(startNode, "fooMethod"); | 916 // GetChild(startNode, "fooMethod"); |
917 | 917 |
918 cpu_profiler->DeleteAllCpuProfiles(); | 918 cpu_profiler->DeleteAllCpuProfiles(); |
919 } | 919 } |
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 = 200; | |
945 #if defined(_WIN32) || defined(_WIN64) | |
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 | |
951 // Cold run. | |
952 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | |
953 cpu_profiler->StartCpuProfiling(profile_name); | |
954 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | |
955 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
956 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
957 CHECK_NE(NULL, profile); | |
958 | |
959 // Dump collected profile to have a better diagnostic in case of failure. | |
960 reinterpret_cast<i::CpuProfile*>( | |
961 const_cast<v8::CpuProfile*>(profile))->Print(); | |
962 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | |
963 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | |
964 | |
965 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | |
966 startNode->GetScriptResourceName()); | |
967 | |
968 cpu_profiler->DeleteAllCpuProfiles(); | |
969 } | |
970 | |
971 TEST(LogExistingFunctionSourceURLCheck) { | |
972 LocalContext env; | |
973 v8::HandleScope scope(env->GetIsolate()); | |
974 | |
975 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | |
976 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | |
977 env->Global()->Get(v8::String::New("start"))); | |
978 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
979 int32_t profiling_interval_ms = 200; | |
980 | |
981 // Warm up. | |
982 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | |
983 function->Call(env->Global(), ARRAY_SIZE(args), args); | |
984 | |
985 #if defined(_WIN32) || defined(_WIN64) | |
986 // 200ms is not enough on Windows. See | |
987 // https://code.google.com/p/v8/issues/detail?id=2628 | |
988 profiling_interval_ms = 500; | |
989 #endif | |
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); | |
995 | |
996 // Dump collected profile to have a better diagnostic in case of failure. | |
997 reinterpret_cast<i::CpuProfile*>( | |
998 const_cast<v8::CpuProfile*>(profile))->Print(); | |
999 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | |
1000 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | |
1001 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | |
1002 startNode->GetScriptResourceName()); | |
1003 | |
1004 cpu_profiler->DeleteAllCpuProfiles(); | |
1005 } | |
OLD | NEW |