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 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 993 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
994 names[2] = v8::String::New("start"); | 994 names[2] = v8::String::New("start"); |
995 // Don't allow |foo| node to be at the top level. | 995 // Don't allow |foo| node to be at the top level. |
996 CheckChildrenNames(root, names); | 996 CheckChildrenNames(root, names); |
997 | 997 |
998 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 998 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
999 GetChild(startNode, "foo"); | 999 GetChild(startNode, "foo"); |
1000 | 1000 |
1001 cpu_profiler->DeleteAllCpuProfiles(); | 1001 cpu_profiler->DeleteAllCpuProfiles(); |
1002 } | 1002 } |
| 1003 |
| 1004 |
| 1005 static const char* call_function_test_source = "function bar(iterations) {\n" |
| 1006 "}\n" |
| 1007 "function start(duration) {\n" |
| 1008 " var start = Date.now();\n" |
| 1009 " while (Date.now() - start < duration) {\n" |
| 1010 " try {\n" |
| 1011 " bar.call(this, 10 * 1000);\n" |
| 1012 " } catch(e) {}\n" |
| 1013 " }\n" |
| 1014 "}"; |
| 1015 |
| 1016 |
| 1017 TEST(CallFunction) { |
| 1018 LocalContext env; |
| 1019 v8::HandleScope scope(env->GetIsolate()); |
| 1020 |
| 1021 v8::Script::Compile(v8::String::New(call_function_test_source))->Run(); |
| 1022 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1023 env->Global()->Get(v8::String::New("start"))); |
| 1024 |
| 1025 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1026 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 1027 |
| 1028 cpu_profiler->StartCpuProfiling(profile_name); |
| 1029 int32_t duration_ms = 100; |
| 1030 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1031 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 1032 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 1033 |
| 1034 CHECK_NE(NULL, profile); |
| 1035 // Dump collected profile to have a better diagnostic in case of failure. |
| 1036 reinterpret_cast<i::CpuProfile*>( |
| 1037 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 1038 |
| 1039 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1040 { |
| 1041 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1042 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 1043 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 1044 names[2] = v8::String::New("start"); |
| 1045 // Don't allow |bar| and |call| nodes to be at the top level. |
| 1046 CheckChildrenNames(root, names); |
| 1047 } |
| 1048 |
| 1049 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 1050 { |
| 1051 ScopedVector<v8::Handle<v8::String> > names(2); |
| 1052 names[0] = v8::String::New("bar"); |
| 1053 names[1] = v8::String::New("call"); |
| 1054 CheckChildrenNames(startNode, names); |
| 1055 } |
| 1056 |
| 1057 cpu_profiler->DeleteAllCpuProfiles(); |
| 1058 } |
| 1059 |
OLD | NEW |