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 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 reinterpret_cast<i::CpuProfile*>( | 907 reinterpret_cast<i::CpuProfile*>( |
908 const_cast<v8::CpuProfile*>(profile))->Print(); | 908 const_cast<v8::CpuProfile*>(profile))->Print(); |
909 | 909 |
910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 910 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
911 GetChild(root, "start"); | 911 GetChild(root, "start"); |
912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 912 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
913 GetChild(startNode, "fooMethod"); | 913 GetChild(startNode, "fooMethod"); |
914 | 914 |
915 cpu_profiler->DeleteAllCpuProfiles(); | 915 cpu_profiler->DeleteAllCpuProfiles(); |
916 } | 916 } |
| 917 |
| 918 |
| 919 static const char* cpu_profiler_sourceURL_source = |
| 920 "function start(timeout) {\n" |
| 921 " var start = Date.now();\n" |
| 922 " var duration = 0;\n" |
| 923 " do {\n" |
| 924 " try {\n" |
| 925 " duration = Date.now() - start;\n" |
| 926 " } catch(e) { }\n" |
| 927 " } while (duration < timeout);\n" |
| 928 " return duration;\n" |
| 929 "}\n" |
| 930 "//# sourceURL=cpu_profiler_sourceURL_source.js"; |
| 931 |
| 932 |
| 933 TEST(SourceURLSupportForNewFunctions) { |
| 934 LocalContext env; |
| 935 v8::HandleScope scope(env->GetIsolate()); |
| 936 |
| 937 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 938 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 939 env->Global()->Get(v8::String::New("start"))); |
| 940 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 941 int32_t profiling_interval_ms = 100; |
| 942 |
| 943 // Cold run. |
| 944 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 945 cpu_profiler->StartCpuProfiling(profile_name); |
| 946 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 947 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 948 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 949 CHECK_NE(NULL, profile); |
| 950 |
| 951 // Dump collected profile to have a better diagnostic in case of failure. |
| 952 reinterpret_cast<i::CpuProfile*>( |
| 953 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 954 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 955 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 956 |
| 957 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 958 startNode->GetScriptResourceName()); |
| 959 |
| 960 cpu_profiler->DeleteAllCpuProfiles(); |
| 961 } |
| 962 |
| 963 TEST(LogExistingFunctionSourceURLCheck) { |
| 964 LocalContext env; |
| 965 v8::HandleScope scope(env->GetIsolate()); |
| 966 |
| 967 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 968 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 969 env->Global()->Get(v8::String::New("start"))); |
| 970 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 971 int32_t profiling_interval_ms = 100; |
| 972 |
| 973 // Warm up. |
| 974 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 975 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 976 |
| 977 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 978 cpu_profiler->StartCpuProfiling(profile_name); |
| 979 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 980 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 981 CHECK_NE(NULL, profile); |
| 982 |
| 983 // Dump collected profile to have a better diagnostic in case of failure. |
| 984 reinterpret_cast<i::CpuProfile*>( |
| 985 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 986 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 987 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 988 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 989 startNode->GetScriptResourceName()); |
| 990 |
| 991 cpu_profiler->DeleteAllCpuProfiles(); |
| 992 } |
OLD | NEW |