| 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 const v8::CpuProfileNode* child = node->GetChild(i); | 468 const v8::CpuProfileNode* child = node->GetChild(i); |
| 469 if (nameHandle->Equals(child->GetFunctionName())) return child; | 469 if (nameHandle->Equals(child->GetFunctionName())) return child; |
| 470 } | 470 } |
| 471 return NULL; | 471 return NULL; |
| 472 } | 472 } |
| 473 | 473 |
| 474 | 474 |
| 475 static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node, | 475 static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node, |
| 476 const char* name) { | 476 const char* name) { |
| 477 const v8::CpuProfileNode* result = FindChild(node, name); | 477 const v8::CpuProfileNode* result = FindChild(node, name); |
| 478 CHECK(result); | 478 if (!result) { |
| 479 char buffer[100]; |
| 480 i::OS::SNPrintF(Vector<char>(buffer, ARRAY_SIZE(buffer)), |
| 481 "Failed to GetChild: %s", name); |
| 482 FATAL(buffer); |
| 483 } |
| 479 return result; | 484 return result; |
| 480 } | 485 } |
| 481 | 486 |
| 482 | 487 |
| 483 static void CheckSimpleBranch(const v8::CpuProfileNode* node, | 488 static void CheckSimpleBranch(const v8::CpuProfileNode* node, |
| 484 const char* names[], int length) { | 489 const char* names[], int length) { |
| 485 for (int i = 0; i < length; i++) { | 490 for (int i = 0; i < length; i++) { |
| 486 const char* name = names[i]; | 491 const char* name = names[i]; |
| 487 node = GetChild(node, name); | 492 node = GetChild(node, name); |
| 488 int expectedChildrenCount = (i == length - 1) ? 0 : 1; | 493 int expectedChildrenCount = (i == length - 1) ? 0 : 1; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 | 588 |
| 584 static const char* cpu_profiler_test_source2 = "function loop() {}\n" | 589 static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
| 585 "function delay() { loop(); }\n" | 590 "function delay() { loop(); }\n" |
| 586 "function start(count) {\n" | 591 "function start(count) {\n" |
| 587 " var k = 0;\n" | 592 " var k = 0;\n" |
| 588 " do {\n" | 593 " do {\n" |
| 589 " delay();\n" | 594 " delay();\n" |
| 590 " } while (++k < count*100*1000);\n" | 595 " } while (++k < count*100*1000);\n" |
| 591 "}\n"; | 596 "}\n"; |
| 592 | 597 |
| 593 // Check that the profile tree doesn't contain unexpecte traces: | 598 // Check that the profile tree doesn't contain unexpected traces: |
| 594 // - 'loop' can be called only by 'delay' | 599 // - 'loop' can be called only by 'delay' |
| 595 // - 'delay' may be called only by 'start' | 600 // - 'delay' may be called only by 'start' |
| 596 // The profile will look like the following: | 601 // The profile will look like the following: |
| 597 // | 602 // |
| 598 // [Top down]: | 603 // [Top down]: |
| 599 // 135 0 (root) [-1] #1 | 604 // 135 0 (root) [-1] #1 |
| 600 // 121 72 start [-1] #3 | 605 // 121 72 start [-1] #3 |
| 601 // 49 33 delay [-1] #4 | 606 // 49 33 delay [-1] #4 |
| 602 // 16 16 loop [-1] #5 | 607 // 16 16 loop [-1] #5 |
| 603 // 14 14 (program) [-1] #2 | 608 // 14 14 (program) [-1] #2 |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 CheckChildrenNames(unresolvedNode, names); | 1079 CheckChildrenNames(unresolvedNode, names); |
| 1075 GetChild(unresolvedNode, "apply"); | 1080 GetChild(unresolvedNode, "apply"); |
| 1076 } | 1081 } |
| 1077 } | 1082 } |
| 1078 | 1083 |
| 1079 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1084 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1080 cpu_profiler->DeleteAllCpuProfiles(); | 1085 cpu_profiler->DeleteAllCpuProfiles(); |
| 1081 } | 1086 } |
| 1082 | 1087 |
| 1083 | 1088 |
| 1084 static const char* js_native_js_test_source = "function foo(iterations) {\n" | 1089 static const char* js_native_js_test_source = |
| 1090 "var is_profiling = false;\n" |
| 1091 "function foo(iterations) {\n" |
| 1092 " if (!is_profiling) {\n" |
| 1093 " is_profiling = true;\n" |
| 1094 " startProfiling('my_profile');\n" |
| 1095 " }\n" |
| 1085 " var r = 0;\n" | 1096 " var r = 0;\n" |
| 1086 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 1097 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 1087 " return r;\n" | 1098 " return r;\n" |
| 1088 "}\n" | 1099 "}\n" |
| 1089 "function bar(iterations) {\n" | 1100 "function bar(iterations) {\n" |
| 1090 " try { foo(iterations); } catch(e) {}\n" | 1101 " try { foo(iterations); } catch(e) {}\n" |
| 1091 "}\n" | 1102 "}\n" |
| 1092 "function start(duration) {\n" | 1103 "function start(duration) {\n" |
| 1093 " var start = Date.now();\n" | 1104 " var start = Date.now();\n" |
| 1094 " while (Date.now() - start < duration) {\n" | 1105 " while (Date.now() - start < duration) {\n" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1106 | 1117 |
| 1107 | 1118 |
| 1108 // [Top down]: | 1119 // [Top down]: |
| 1109 // 58 0 (root) #0 1 | 1120 // 58 0 (root) #0 1 |
| 1110 // 2 2 (program) #0 2 | 1121 // 2 2 (program) #0 2 |
| 1111 // 56 1 start #16 3 | 1122 // 56 1 start #16 3 |
| 1112 // 55 0 CallJsFunction #0 4 | 1123 // 55 0 CallJsFunction #0 4 |
| 1113 // 55 1 bar #16 5 | 1124 // 55 1 bar #16 5 |
| 1114 // 54 54 foo #16 6 | 1125 // 54 54 foo #16 6 |
| 1115 TEST(JsNativeJsSample) { | 1126 TEST(JsNativeJsSample) { |
| 1116 LocalContext env; | 1127 const char* extensions[] = { "v8/profiler" }; |
| 1128 v8::ExtensionConfiguration config(1, extensions); |
| 1129 LocalContext env(&config); |
| 1117 v8::HandleScope scope(env->GetIsolate()); | 1130 v8::HandleScope scope(env->GetIsolate()); |
| 1118 | 1131 |
| 1119 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1132 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1120 CallJsFunction); | 1133 CallJsFunction); |
| 1121 v8::Local<v8::Function> func = func_template->GetFunction(); | 1134 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 1122 func->SetName(v8::String::New("CallJsFunction")); | 1135 func->SetName(v8::String::New("CallJsFunction")); |
| 1123 env->Global()->Set(v8::String::New("CallJsFunction"), func); | 1136 env->Global()->Set(v8::String::New("CallJsFunction"), func); |
| 1124 | 1137 |
| 1125 v8::Script::Compile(v8::String::New(js_native_js_test_source))->Run(); | 1138 v8::Script::Compile(v8::String::New(js_native_js_test_source))->Run(); |
| 1126 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1139 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1127 env->Global()->Get(v8::String::New("start"))); | 1140 env->Global()->Get(v8::String::New("start"))); |
| 1128 | 1141 |
| 1129 int32_t duration_ms = 20; | 1142 int32_t duration_ms = 20; |
| 1130 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1143 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1131 const v8::CpuProfile* profile = | 1144 const v8::CpuProfile* profile = |
| 1132 RunProfiler(env, function, args, ARRAY_SIZE(args), 50); | 1145 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
| 1133 | 1146 |
| 1134 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1147 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1135 { | 1148 { |
| 1136 ScopedVector<v8::Handle<v8::String> > names(3); | 1149 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1137 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1150 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 1138 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1151 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 1139 names[2] = v8::String::New("start"); | 1152 names[2] = v8::String::New("start"); |
| 1140 CheckChildrenNames(root, names); | 1153 CheckChildrenNames(root, names); |
| 1141 } | 1154 } |
| 1142 | 1155 |
| 1143 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1156 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 1144 CHECK_EQ(1, startNode->GetChildrenCount()); | 1157 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 1145 const v8::CpuProfileNode* nativeFunctionNode = | 1158 const v8::CpuProfileNode* nativeFunctionNode = |
| 1146 GetChild(startNode, "CallJsFunction"); | 1159 GetChild(startNode, "CallJsFunction"); |
| 1147 | 1160 |
| 1148 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1161 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
| 1149 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar"); | 1162 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar"); |
| 1150 | 1163 |
| 1151 CHECK_EQ(1, barNode->GetChildrenCount()); | 1164 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1152 GetChild(barNode, "foo"); | 1165 GetChild(barNode, "foo"); |
| 1153 | 1166 |
| 1154 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1167 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1155 cpu_profiler->DeleteAllCpuProfiles(); | 1168 cpu_profiler->DeleteAllCpuProfiles(); |
| 1156 } | 1169 } |
| 1157 | 1170 |
| 1158 | 1171 |
| 1159 static const char* js_native_js_runtime_js_test_source = | 1172 static const char* js_native_js_runtime_js_test_source = |
| 1173 "var is_profiling = false;\n" |
| 1160 "function foo(iterations) {\n" | 1174 "function foo(iterations) {\n" |
| 1175 " if (!is_profiling) {\n" |
| 1176 " is_profiling = true;\n" |
| 1177 " startProfiling('my_profile');\n" |
| 1178 " }\n" |
| 1161 " var r = 0;\n" | 1179 " var r = 0;\n" |
| 1162 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 1180 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 1163 " return r;\n" | 1181 " return r;\n" |
| 1164 "}\n" | 1182 "}\n" |
| 1165 "var bound = foo.bind(this);\n" | 1183 "var bound = foo.bind(this);\n" |
| 1166 "function bar(iterations) {\n" | 1184 "function bar(iterations) {\n" |
| 1167 " try { bound(iterations); } catch(e) {}\n" | 1185 " try { bound(iterations); } catch(e) {}\n" |
| 1168 "}\n" | 1186 "}\n" |
| 1169 "function start(duration) {\n" | 1187 "function start(duration) {\n" |
| 1170 " var start = Date.now();\n" | 1188 " var start = Date.now();\n" |
| 1171 " while (Date.now() - start < duration) {\n" | 1189 " while (Date.now() - start < duration) {\n" |
| 1172 " try {\n" | 1190 " try {\n" |
| 1173 " CallJsFunction(bar, 10 * 1000);\n" | 1191 " CallJsFunction(bar, 10 * 1000);\n" |
| 1174 " } catch(e) {}\n" | 1192 " } catch(e) {}\n" |
| 1175 " }\n" | 1193 " }\n" |
| 1176 "}"; | 1194 "}"; |
| 1177 | 1195 |
| 1178 | 1196 |
| 1179 // [Top down]: | 1197 // [Top down]: |
| 1180 // 57 0 (root) #0 1 | 1198 // 57 0 (root) #0 1 |
| 1181 // 55 1 start #16 3 | 1199 // 55 1 start #16 3 |
| 1182 // 54 0 CallJsFunction #0 4 | 1200 // 54 0 CallJsFunction #0 4 |
| 1183 // 54 3 bar #16 5 | 1201 // 54 3 bar #16 5 |
| 1184 // 51 51 foo #16 6 | 1202 // 51 51 foo #16 6 |
| 1185 // 2 2 (program) #0 2 | 1203 // 2 2 (program) #0 2 |
| 1186 TEST(JsNativeJsRuntimeJsSample) { | 1204 TEST(JsNativeJsRuntimeJsSample) { |
| 1187 LocalContext env; | 1205 const char* extensions[] = { "v8/profiler" }; |
| 1206 v8::ExtensionConfiguration config(1, extensions); |
| 1207 LocalContext env(&config); |
| 1188 v8::HandleScope scope(env->GetIsolate()); | 1208 v8::HandleScope scope(env->GetIsolate()); |
| 1189 | 1209 |
| 1190 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1210 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1191 CallJsFunction); | 1211 CallJsFunction); |
| 1192 v8::Local<v8::Function> func = func_template->GetFunction(); | 1212 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 1193 func->SetName(v8::String::New("CallJsFunction")); | 1213 func->SetName(v8::String::New("CallJsFunction")); |
| 1194 env->Global()->Set(v8::String::New("CallJsFunction"), func); | 1214 env->Global()->Set(v8::String::New("CallJsFunction"), func); |
| 1195 | 1215 |
| 1196 v8::Script::Compile(v8::String::New(js_native_js_runtime_js_test_source))-> | 1216 v8::Script::Compile(v8::String::New(js_native_js_runtime_js_test_source))-> |
| 1197 Run(); | 1217 Run(); |
| 1198 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1218 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1199 env->Global()->Get(v8::String::New("start"))); | 1219 env->Global()->Get(v8::String::New("start"))); |
| 1200 | 1220 |
| 1201 int32_t duration_ms = 20; | 1221 int32_t duration_ms = 20; |
| 1202 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1222 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1203 const v8::CpuProfile* profile = | 1223 const v8::CpuProfile* profile = |
| 1204 RunProfiler(env, function, args, ARRAY_SIZE(args), 50); | 1224 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
| 1205 | 1225 |
| 1206 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1226 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1207 ScopedVector<v8::Handle<v8::String> > names(3); | 1227 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1208 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1228 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 1209 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1229 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 1210 names[2] = v8::String::New("start"); | 1230 names[2] = v8::String::New("start"); |
| 1211 CheckChildrenNames(root, names); | 1231 CheckChildrenNames(root, names); |
| 1212 | 1232 |
| 1213 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1233 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 1214 CHECK_EQ(1, startNode->GetChildrenCount()); | 1234 CHECK_EQ(1, startNode->GetChildrenCount()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1225 cpu_profiler->DeleteAllCpuProfiles(); | 1245 cpu_profiler->DeleteAllCpuProfiles(); |
| 1226 } | 1246 } |
| 1227 | 1247 |
| 1228 | 1248 |
| 1229 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1249 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1230 CallJsFunction(info); | 1250 CallJsFunction(info); |
| 1231 } | 1251 } |
| 1232 | 1252 |
| 1233 | 1253 |
| 1234 static const char* js_native1_js_native2_js_test_source = | 1254 static const char* js_native1_js_native2_js_test_source = |
| 1255 "var is_profiling = false;\n" |
| 1235 "function foo(iterations) {\n" | 1256 "function foo(iterations) {\n" |
| 1257 " if (!is_profiling) {\n" |
| 1258 " is_profiling = true;\n" |
| 1259 " startProfiling('my_profile');\n" |
| 1260 " }\n" |
| 1236 " var r = 0;\n" | 1261 " var r = 0;\n" |
| 1237 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 1262 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 1238 " return r;\n" | 1263 " return r;\n" |
| 1239 "}\n" | 1264 "}\n" |
| 1240 "function bar(iterations) {\n" | 1265 "function bar(iterations) {\n" |
| 1241 " CallJsFunction2(foo, iterations);\n" | 1266 " CallJsFunction2(foo, iterations);\n" |
| 1242 "}\n" | 1267 "}\n" |
| 1243 "function start(duration) {\n" | 1268 "function start(duration) {\n" |
| 1244 " var start = Date.now();\n" | 1269 " var start = Date.now();\n" |
| 1245 " while (Date.now() - start < duration) {\n" | 1270 " while (Date.now() - start < duration) {\n" |
| 1246 " try {\n" | 1271 " try {\n" |
| 1247 " CallJsFunction1(bar, 10 * 1000);\n" | 1272 " CallJsFunction1(bar, 10 * 1000);\n" |
| 1248 " } catch(e) {}\n" | 1273 " } catch(e) {}\n" |
| 1249 " }\n" | 1274 " }\n" |
| 1250 "}"; | 1275 "}"; |
| 1251 | 1276 |
| 1252 | 1277 |
| 1253 // [Top down]: | 1278 // [Top down]: |
| 1254 // 57 0 (root) #0 1 | 1279 // 57 0 (root) #0 1 |
| 1255 // 55 1 start #16 3 | 1280 // 55 1 start #16 3 |
| 1256 // 54 0 CallJsFunction1 #0 4 | 1281 // 54 0 CallJsFunction1 #0 4 |
| 1257 // 54 0 bar #16 5 | 1282 // 54 0 bar #16 5 |
| 1258 // 54 0 CallJsFunction2 #0 6 | 1283 // 54 0 CallJsFunction2 #0 6 |
| 1259 // 54 54 foo #16 7 | 1284 // 54 54 foo #16 7 |
| 1260 // 2 2 (program) #0 2 | 1285 // 2 2 (program) #0 2 |
| 1261 TEST(JsNative1JsNative2JsSample) { | 1286 TEST(JsNative1JsNative2JsSample) { |
| 1262 LocalContext env; | 1287 const char* extensions[] = { "v8/profiler" }; |
| 1288 v8::ExtensionConfiguration config(1, extensions); |
| 1289 LocalContext env(&config); |
| 1263 v8::HandleScope scope(env->GetIsolate()); | 1290 v8::HandleScope scope(env->GetIsolate()); |
| 1264 | 1291 |
| 1265 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1292 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1266 CallJsFunction); | 1293 CallJsFunction); |
| 1267 v8::Local<v8::Function> func1 = func_template->GetFunction(); | 1294 v8::Local<v8::Function> func1 = func_template->GetFunction(); |
| 1268 func1->SetName(v8::String::New("CallJsFunction1")); | 1295 func1->SetName(v8::String::New("CallJsFunction1")); |
| 1269 env->Global()->Set(v8::String::New("CallJsFunction1"), func1); | 1296 env->Global()->Set(v8::String::New("CallJsFunction1"), func1); |
| 1270 | 1297 |
| 1271 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( | 1298 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( |
| 1272 CallJsFunction2)->GetFunction(); | 1299 CallJsFunction2)->GetFunction(); |
| 1273 func2->SetName(v8::String::New("CallJsFunction2")); | 1300 func2->SetName(v8::String::New("CallJsFunction2")); |
| 1274 env->Global()->Set(v8::String::New("CallJsFunction2"), func2); | 1301 env->Global()->Set(v8::String::New("CallJsFunction2"), func2); |
| 1275 | 1302 |
| 1276 v8::Script::Compile(v8::String::New(js_native1_js_native2_js_test_source))-> | 1303 v8::Script::Compile(v8::String::New(js_native1_js_native2_js_test_source))-> |
| 1277 Run(); | 1304 Run(); |
| 1278 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1305 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1279 env->Global()->Get(v8::String::New("start"))); | 1306 env->Global()->Get(v8::String::New("start"))); |
| 1280 | 1307 |
| 1281 int32_t duration_ms = 20; | 1308 int32_t duration_ms = 20; |
| 1282 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1309 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1283 const v8::CpuProfile* profile = | 1310 const v8::CpuProfile* profile = |
| 1284 RunProfiler(env, function, args, ARRAY_SIZE(args), 50); | 1311 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
| 1285 | 1312 |
| 1286 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1313 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1287 ScopedVector<v8::Handle<v8::String> > names(3); | 1314 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1288 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1315 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 1289 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1316 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 1290 names[2] = v8::String::New("start"); | 1317 names[2] = v8::String::New("start"); |
| 1291 CheckChildrenNames(root, names); | 1318 CheckChildrenNames(root, names); |
| 1292 | 1319 |
| 1293 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1320 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
| 1294 CHECK_EQ(1, startNode->GetChildrenCount()); | 1321 CHECK_EQ(1, startNode->GetChildrenCount()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 CHECK_EQ(0, programNode->GetChildrenCount()); | 1380 CHECK_EQ(0, programNode->GetChildrenCount()); |
| 1354 CHECK_GE(programNode->GetHitCount(), 3); | 1381 CHECK_GE(programNode->GetHitCount(), 3); |
| 1355 | 1382 |
| 1356 const v8::CpuProfileNode* idleNode = | 1383 const v8::CpuProfileNode* idleNode = |
| 1357 GetChild(root, ProfileGenerator::kIdleEntryName); | 1384 GetChild(root, ProfileGenerator::kIdleEntryName); |
| 1358 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1385 CHECK_EQ(0, idleNode->GetChildrenCount()); |
| 1359 CHECK_GE(idleNode->GetHitCount(), 3); | 1386 CHECK_GE(idleNode->GetHitCount(), 3); |
| 1360 | 1387 |
| 1361 cpu_profiler->DeleteAllCpuProfiles(); | 1388 cpu_profiler->DeleteAllCpuProfiles(); |
| 1362 } | 1389 } |
| 1390 |
| 1391 |
| 1392 static void CheckFunctionDetails(const v8::CpuProfileNode* node, |
| 1393 const char* name, const char* script_name, int script_id, |
| 1394 int line, int column) { |
| 1395 CHECK_EQ(v8::String::New(name), node->GetFunctionName()); |
| 1396 CHECK_EQ(v8::String::New(script_name), node->GetScriptResourceName()); |
| 1397 CHECK_EQ(script_id, node->GetScriptId()); |
| 1398 CHECK_EQ(line, node->GetLineNumber()); |
| 1399 CHECK_EQ(column, node->GetColumnNumber()); |
| 1400 } |
| 1401 |
| 1402 |
| 1403 TEST(FunctionDetails) { |
| 1404 const char* extensions[] = { "v8/profiler" }; |
| 1405 v8::ExtensionConfiguration config(1, extensions); |
| 1406 LocalContext env(&config); |
| 1407 v8::HandleScope handleScope(env->GetIsolate()); |
| 1408 |
| 1409 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1410 CHECK_EQ(0, profiler->GetProfileCount()); |
| 1411 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::New( |
| 1412 " function foo\n() { try { bar(); } catch(e) {} }\n" |
| 1413 " function bar() { startProfiling(); }\n"), v8::String::New("script_a")); |
| 1414 script_a->Run(); |
| 1415 v8::Handle<v8::Script> script_b = v8::Script::Compile(v8::String::New( |
| 1416 "\n\n function baz() { try { foo(); } catch(e) {} }\n" |
| 1417 "\n\nbaz();\n" |
| 1418 "stopProfiling();\n"), v8::String::New("script_b")); |
| 1419 script_b->Run(); |
| 1420 CHECK_EQ(1, profiler->GetProfileCount()); |
| 1421 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); |
| 1422 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
| 1423 reinterpret_cast<ProfileNode*>( |
| 1424 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
| 1425 // The tree should look like this: |
| 1426 // 0 (root) 0 #1 |
| 1427 // 0 (anonymous function) 19 #2 no reason script_b:1 |
| 1428 // 0 baz 19 #3 TryCatchStatement script_b:3 |
| 1429 // 0 foo 18 #4 TryCatchStatement script_a:2 |
| 1430 // 1 bar 18 #5 no reason script_a:3 |
| 1431 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1432 const v8::CpuProfileNode* script = GetChild(root, |
| 1433 ProfileGenerator::kAnonymousFunctionName); |
| 1434 CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName, |
| 1435 "script_b", script_b->GetId(), 1, 1); |
| 1436 const v8::CpuProfileNode* baz = GetChild(script, "baz"); |
| 1437 CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16); |
| 1438 const v8::CpuProfileNode* foo = GetChild(baz, "foo"); |
| 1439 CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1); |
| 1440 const v8::CpuProfileNode* bar = GetChild(foo, "bar"); |
| 1441 CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14); |
| 1442 } |
| OLD | NEW |