Chromium Code Reviews| 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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 920 |
| 921 | 921 |
| 922 static const char* cpu_profiler_sourceURL_source = | 922 static const char* cpu_profiler_sourceURL_source = |
| 923 "function start(timeout) {\n" | 923 "function start(warm_up) {\n" |
| 924 " var start = Date.now();\n" | 924 " if (!warm_up) {\n" |
| 925 " var duration = 0;\n" | 925 " startProfiling();\n" |
| 926 " do {\n" | 926 " stopProfiling();\n" |
| 927 " try {\n" | 927 " }\n" |
| 928 " duration = Date.now() - start;\n" | |
| 929 " } catch(e) { }\n" | |
| 930 " } while (duration < timeout);\n" | |
| 931 " return duration;\n" | |
| 932 "}\n" | 928 "}\n" |
| 933 "//# sourceURL=cpu_profiler_sourceURL_source.js"; | 929 "//# sourceURL=cpu_profiler_sourceURL_source.js"; |
| 934 | 930 |
| 935 | 931 |
| 936 TEST(SourceURLSupportForNewFunctions) { | 932 TEST(SourceURLSupportForNewFunctions) { |
| 937 LocalContext env; | 933 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 938 v8::HandleScope scope(env->GetIsolate()); | 934 v8::HandleScope scope(isolate); |
| 935 const char* extensions[] = { "v8/profiler" }; | |
| 936 v8::ExtensionConfiguration config(1, extensions); | |
| 937 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); | |
|
yurys
2013/06/13 09:11:35
Can you continue using LocalContext for consistenc
loislo
2013/06/13 10:01:42
Done.
| |
| 938 context->Enter(); | |
| 939 | 939 |
| 940 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | 940 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 941 v8::Local<v8::Object> global = context->Global(); | |
| 941 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 942 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 942 env->Global()->Get(v8::String::New("start"))); | 943 global->Get(v8::String::New("start"))); |
| 943 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 944 v8::CpuProfiler* cpu_profiler = isolate->GetCpuProfiler(); |
| 944 int32_t profiling_interval_ms = 100; | 945 CHECK_NE(NULL, cpu_profiler); |
| 946 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
| 945 | 947 |
| 946 // Cold run. | 948 // Cold run. |
| 947 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 949 v8::Handle<v8::Value> args[] = { v8::Boolean::New(false) }; |
| 948 cpu_profiler->StartCpuProfiling(profile_name); | 950 function->Call(global, ARRAY_SIZE(args), args); |
| 949 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 951 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 950 function->Call(env->Global(), ARRAY_SIZE(args), args); | 952 const v8::CpuProfile* profile = cpu_profiler->GetCpuProfile(0); |
| 951 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | |
| 952 CHECK_NE(NULL, profile); | 953 CHECK_NE(NULL, profile); |
| 953 | 954 |
| 954 // Dump collected profile to have a better diagnostic in case of failure. | 955 // Dump collected profile to have a better diagnostic in case of failure. |
| 955 reinterpret_cast<i::CpuProfile*>( | 956 reinterpret_cast<i::CpuProfile*>( |
| 956 const_cast<v8::CpuProfile*>(profile))->Print(); | 957 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 957 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 958 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 958 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 959 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 959 | 960 |
| 960 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | 961 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 961 startNode->GetScriptResourceName()); | 962 startNode->GetScriptResourceName()); |
| 962 | 963 |
| 963 cpu_profiler->DeleteAllCpuProfiles(); | 964 cpu_profiler->DeleteAllCpuProfiles(); |
| 964 } | 965 } |
| 965 | 966 |
| 966 TEST(LogExistingFunctionSourceURLCheck) { | 967 TEST(LogExistingFunctionSourceURLCheck) { |
| 967 LocalContext env; | 968 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 968 v8::HandleScope scope(env->GetIsolate()); | 969 v8::HandleScope scope(isolate); |
| 970 const char* extensions[] = { "v8/profiler" }; | |
| 971 v8::ExtensionConfiguration config(1, extensions); | |
| 972 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); | |
|
yurys
2013/06/13 09:11:35
Ditto.
loislo
2013/06/13 10:01:42
Done.
| |
| 973 context->Enter(); | |
| 969 | 974 |
| 970 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); | 975 v8::Script::Compile(v8::String::New(cpu_profiler_sourceURL_source))->Run(); |
| 976 v8::Local<v8::Object> global = context->Global(); | |
| 971 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 977 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 972 env->Global()->Get(v8::String::New("start"))); | 978 global->Get(v8::String::New("start"))); |
| 973 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 979 v8::CpuProfiler* cpu_profiler = isolate->GetCpuProfiler(); |
| 974 int32_t profiling_interval_ms = 100; | 980 CHECK_NE(NULL, cpu_profiler); |
| 981 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
| 975 | 982 |
| 976 // Warm up. | 983 // Warm up. |
| 977 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 984 v8::Handle<v8::Value> warm_up_args[] = { v8::Boolean::New(true) }; |
| 978 function->Call(env->Global(), ARRAY_SIZE(args), args); | 985 function->Call(global, ARRAY_SIZE(warm_up_args), warm_up_args); |
| 986 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
| 979 | 987 |
| 980 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 988 // Run. |
| 981 cpu_profiler->StartCpuProfiling(profile_name); | 989 v8::Handle<v8::Value> args[] = { v8::Boolean::New(false) }; |
| 982 function->Call(env->Global(), ARRAY_SIZE(args), args); | 990 function->Call(global, ARRAY_SIZE(args), args); |
| 983 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 991 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 992 const v8::CpuProfile* profile = cpu_profiler->GetCpuProfile(0); | |
| 984 CHECK_NE(NULL, profile); | 993 CHECK_NE(NULL, profile); |
| 985 | 994 |
| 986 // Dump collected profile to have a better diagnostic in case of failure. | 995 // Dump collected profile to have a better diagnostic in case of failure. |
| 987 reinterpret_cast<i::CpuProfile*>( | 996 reinterpret_cast<i::CpuProfile*>( |
| 988 const_cast<v8::CpuProfile*>(profile))->Print(); | 997 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 989 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 998 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 990 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 999 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 991 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), | 1000 CHECK_EQ(v8::String::New("cpu_profiler_sourceURL_source.js"), |
| 992 startNode->GetScriptResourceName()); | 1001 startNode->GetScriptResourceName()); |
| 993 | 1002 |
| 994 cpu_profiler->DeleteAllCpuProfiles(); | 1003 cpu_profiler->DeleteAllCpuProfiles(); |
| 995 } | 1004 } |
| OLD | NEW |