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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 v8::String::NewFromUtf8(env->GetIsolate(), "test"); | 394 v8::String::NewFromUtf8(env->GetIsolate(), "test"); |
| 395 cpu_profiler->StartProfiling(profile_name); | 395 cpu_profiler->StartProfiling(profile_name); |
| 396 const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); | 396 const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| 397 CHECK(profile->GetStartTime() <= profile->GetEndTime()); | 397 CHECK(profile->GetStartTime() <= profile->GetEndTime()); |
| 398 } | 398 } |
| 399 | 399 |
| 400 | 400 |
| 401 static v8::CpuProfile* RunProfiler( | 401 static v8::CpuProfile* RunProfiler( |
| 402 v8::Handle<v8::Context> env, v8::Handle<v8::Function> function, | 402 v8::Handle<v8::Context> env, v8::Handle<v8::Function> function, |
| 403 v8::Handle<v8::Value> argv[], int argc, | 403 v8::Handle<v8::Value> argv[], int argc, |
| 404 unsigned min_js_samples, bool collect_samples = false) { | 404 unsigned min_js_samples, bool start_profile = true, |
|
yurys
2014/05/27 14:38:19
You can return true from CpuProfilesCollection::St
alph
2014/05/27 14:46:55
Done.
| |
| 405 bool collect_samples = false) { | |
| 405 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 406 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 406 v8::Local<v8::String> profile_name = | 407 v8::Local<v8::String> profile_name = |
| 407 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); | 408 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
| 408 | 409 |
| 409 cpu_profiler->StartProfiling(profile_name, collect_samples); | 410 if (start_profile) { |
| 411 cpu_profiler->StartProfiling(profile_name, collect_samples); | |
| 412 } | |
| 410 | 413 |
| 411 i::Sampler* sampler = | 414 i::Sampler* sampler = |
| 412 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); | 415 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); |
| 413 sampler->StartCountingSamples(); | 416 sampler->StartCountingSamples(); |
| 414 do { | 417 do { |
| 415 function->Call(env->Global(), argc, argv); | 418 function->Call(env->Global(), argc, argv); |
| 416 } while (sampler->js_and_external_sample_count() < min_js_samples); | 419 } while (sampler->js_and_external_sample_count() < min_js_samples); |
| 417 | 420 |
| 418 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); | 421 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
| 419 | 422 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 | 662 |
| 660 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 663 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
| 661 cpu_profiler_test_source))->Run(); | 664 cpu_profiler_test_source))->Run(); |
| 662 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 665 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 663 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 666 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 664 | 667 |
| 665 int32_t profiling_interval_ms = 200; | 668 int32_t profiling_interval_ms = 200; |
| 666 v8::Handle<v8::Value> args[] = { | 669 v8::Handle<v8::Value> args[] = { |
| 667 v8::Integer::New(env->GetIsolate(), profiling_interval_ms) | 670 v8::Integer::New(env->GetIsolate(), profiling_interval_ms) |
| 668 }; | 671 }; |
| 669 v8::CpuProfile* profile = | 672 v8::CpuProfile* profile = RunProfiler( |
| 670 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200, true); | 673 env.local(), function, args, ARRAY_SIZE(args), 200, true, true); |
| 671 | 674 |
| 672 CHECK_LE(200, profile->GetSamplesCount()); | 675 CHECK_LE(200, profile->GetSamplesCount()); |
| 673 uint64_t end_time = profile->GetEndTime(); | 676 uint64_t end_time = profile->GetEndTime(); |
| 674 uint64_t current_time = profile->GetStartTime(); | 677 uint64_t current_time = profile->GetStartTime(); |
| 675 CHECK_LE(current_time, end_time); | 678 CHECK_LE(current_time, end_time); |
| 676 for (int i = 0; i < profile->GetSamplesCount(); i++) { | 679 for (int i = 0; i < profile->GetSamplesCount(); i++) { |
| 677 CHECK_NE(NULL, profile->GetSample(i)); | 680 CHECK_NE(NULL, profile->GetSample(i)); |
| 678 uint64_t timestamp = profile->GetSampleTimestamp(i); | 681 uint64_t timestamp = profile->GetSampleTimestamp(i); |
| 679 CHECK_LE(current_time, timestamp); | 682 CHECK_LE(current_time, timestamp); |
| 680 CHECK_LE(timestamp, end_time); | 683 CHECK_LE(timestamp, end_time); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1019 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1017 GetChild(isolate, root, "start"); | 1020 GetChild(isolate, root, "start"); |
| 1018 const v8::CpuProfileNode* startNode = | 1021 const v8::CpuProfileNode* startNode = |
| 1019 GetChild(isolate, root, "start"); | 1022 GetChild(isolate, root, "start"); |
| 1020 GetChild(isolate, startNode, "fooMethod"); | 1023 GetChild(isolate, startNode, "fooMethod"); |
| 1021 | 1024 |
| 1022 profile->Delete(); | 1025 profile->Delete(); |
| 1023 } | 1026 } |
| 1024 | 1027 |
| 1025 | 1028 |
| 1026 static const char* bound_function_test_source = "function foo(iterations) {\n" | 1029 static const char* bound_function_test_source = |
| 1027 " var r = 0;\n" | 1030 "function foo() {\n" |
| 1028 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 1031 " startProfiling('my_profile');\n" |
| 1029 " return r;\n" | |
| 1030 "}\n" | 1032 "}\n" |
| 1031 "function start(duration) {\n" | 1033 "function start() {\n" |
| 1032 " var callback = foo.bind(this);\n" | 1034 " var callback = foo.bind(this);\n" |
| 1033 " var start = Date.now();\n" | 1035 " callback();\n" |
| 1034 " while (Date.now() - start < duration) {\n" | |
| 1035 " callback(10 * 1000);\n" | |
| 1036 " }\n" | |
| 1037 "}"; | 1036 "}"; |
| 1038 | 1037 |
| 1039 | 1038 |
| 1040 TEST(BoundFunctionCall) { | 1039 TEST(BoundFunctionCall) { |
| 1041 LocalContext env; | 1040 v8::HandleScope scope(CcTest::isolate()); |
| 1042 v8::HandleScope scope(env->GetIsolate()); | 1041 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| 1042 v8::Context::Scope context_scope(env); | |
| 1043 | 1043 |
| 1044 v8::Script::Compile( | 1044 v8::Script::Compile( |
| 1045 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) | 1045 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) |
| 1046 ->Run(); | 1046 ->Run(); |
| 1047 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1047 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1048 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1048 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1049 | 1049 |
| 1050 int32_t duration_ms = 100; | 1050 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
| 1051 v8::Handle<v8::Value> args[] = { | |
| 1052 v8::Integer::New(env->GetIsolate(), duration_ms) | |
| 1053 }; | |
| 1054 v8::CpuProfile* profile = | |
| 1055 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | |
| 1056 | 1051 |
| 1057 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1052 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1058 ScopedVector<v8::Handle<v8::String> > names(3); | 1053 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1059 names[0] = v8::String::NewFromUtf8( | 1054 names[0] = v8::String::NewFromUtf8( |
| 1060 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1055 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1061 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1056 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1062 ProfileGenerator::kProgramEntryName); | 1057 ProfileGenerator::kProgramEntryName); |
| 1063 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1058 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1064 // Don't allow |foo| node to be at the top level. | 1059 // Don't allow |foo| node to be at the top level. |
| 1065 CheckChildrenNames(root, names); | 1060 CheckChildrenNames(root, names); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1241 CheckChildrenNames(unresolvedNode, names); | 1236 CheckChildrenNames(unresolvedNode, names); |
| 1242 GetChild(env->GetIsolate(), unresolvedNode, "apply"); | 1237 GetChild(env->GetIsolate(), unresolvedNode, "apply"); |
| 1243 } | 1238 } |
| 1244 } | 1239 } |
| 1245 | 1240 |
| 1246 profile->Delete(); | 1241 profile->Delete(); |
| 1247 } | 1242 } |
| 1248 | 1243 |
| 1249 | 1244 |
| 1250 static const char* js_native_js_test_source = | 1245 static const char* js_native_js_test_source = |
| 1251 "var is_profiling = false;\n" | 1246 "function foo() {\n" |
| 1252 "function foo(iterations) {\n" | 1247 " startProfiling('my_profile');\n" |
| 1253 " if (!is_profiling) {\n" | |
| 1254 " is_profiling = true;\n" | |
| 1255 " startProfiling('my_profile');\n" | |
| 1256 " }\n" | |
| 1257 " var r = 0;\n" | |
| 1258 " for (var i = 0; i < iterations; i++) { r += i; }\n" | |
| 1259 " return r;\n" | |
| 1260 "}\n" | 1248 "}\n" |
| 1261 "function bar(iterations) {\n" | 1249 "function bar() {\n" |
| 1262 " try { foo(iterations); } catch(e) {}\n" | 1250 " try { foo(); } catch(e) {}\n" |
| 1263 "}\n" | 1251 "}\n" |
| 1264 "function start(duration) {\n" | 1252 "function start() {\n" |
| 1265 " var start = Date.now();\n" | 1253 " try {\n" |
| 1266 " while (Date.now() - start < duration) {\n" | 1254 " CallJsFunction(bar);\n" |
| 1267 " try {\n" | 1255 " } catch(e) {}\n" |
| 1268 " CallJsFunction(bar, 10 * 1000);\n" | |
| 1269 " } catch(e) {}\n" | |
| 1270 " }\n" | |
| 1271 "}"; | 1256 "}"; |
| 1272 | 1257 |
| 1273 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1258 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1274 v8::Handle<v8::Function> function = info[0].As<v8::Function>(); | 1259 v8::Handle<v8::Function> function = info[0].As<v8::Function>(); |
| 1275 v8::Handle<v8::Value> argv[] = { info[1] }; | 1260 v8::Handle<v8::Value> argv[] = { info[1] }; |
| 1276 function->Call(info.This(), ARRAY_SIZE(argv), argv); | 1261 function->Call(info.This(), ARRAY_SIZE(argv), argv); |
| 1277 } | 1262 } |
| 1278 | 1263 |
| 1279 | 1264 |
| 1280 // [Top down]: | 1265 // [Top down]: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1294 v8::Local<v8::Function> func = func_template->GetFunction(); | 1279 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 1295 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); | 1280 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); |
| 1296 env->Global()->Set( | 1281 env->Global()->Set( |
| 1297 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); | 1282 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); |
| 1298 | 1283 |
| 1299 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1284 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
| 1300 js_native_js_test_source))->Run(); | 1285 js_native_js_test_source))->Run(); |
| 1301 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1286 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1302 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1287 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1303 | 1288 |
| 1304 int32_t duration_ms = 20; | 1289 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
| 1305 v8::Handle<v8::Value> args[] = { | |
| 1306 v8::Integer::New(env->GetIsolate(), duration_ms) | |
| 1307 }; | |
| 1308 v8::CpuProfile* profile = | |
| 1309 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | |
| 1310 | 1290 |
| 1311 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1291 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1312 { | 1292 { |
| 1313 ScopedVector<v8::Handle<v8::String> > names(3); | 1293 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1314 names[0] = v8::String::NewFromUtf8( | 1294 names[0] = v8::String::NewFromUtf8( |
| 1315 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1295 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1316 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1296 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1317 ProfileGenerator::kProgramEntryName); | 1297 ProfileGenerator::kProgramEntryName); |
| 1318 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1298 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1319 CheckChildrenNames(root, names); | 1299 CheckChildrenNames(root, names); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1330 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | 1310 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
| 1331 | 1311 |
| 1332 CHECK_EQ(1, barNode->GetChildrenCount()); | 1312 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1333 GetChild(env->GetIsolate(), barNode, "foo"); | 1313 GetChild(env->GetIsolate(), barNode, "foo"); |
| 1334 | 1314 |
| 1335 profile->Delete(); | 1315 profile->Delete(); |
| 1336 } | 1316 } |
| 1337 | 1317 |
| 1338 | 1318 |
| 1339 static const char* js_native_js_runtime_js_test_source = | 1319 static const char* js_native_js_runtime_js_test_source = |
| 1340 "var is_profiling = false;\n" | 1320 "function foo() {\n" |
| 1341 "function foo(iterations) {\n" | 1321 " startProfiling('my_profile');\n" |
| 1342 " if (!is_profiling) {\n" | |
| 1343 " is_profiling = true;\n" | |
| 1344 " startProfiling('my_profile');\n" | |
| 1345 " }\n" | |
| 1346 " var r = 0;\n" | |
| 1347 " for (var i = 0; i < iterations; i++) { r += i; }\n" | |
| 1348 " return r;\n" | |
| 1349 "}\n" | 1322 "}\n" |
| 1350 "var bound = foo.bind(this);\n" | 1323 "var bound = foo.bind(this);\n" |
| 1351 "function bar(iterations) {\n" | 1324 "function bar() {\n" |
| 1352 " try { bound(iterations); } catch(e) {}\n" | 1325 " try { bound(); } catch(e) {}\n" |
| 1353 "}\n" | 1326 "}\n" |
| 1354 "function start(duration) {\n" | 1327 "function start() {\n" |
| 1355 " var start = Date.now();\n" | 1328 " try {\n" |
| 1356 " while (Date.now() - start < duration) {\n" | 1329 " CallJsFunction(bar);\n" |
| 1357 " try {\n" | 1330 " } catch(e) {}\n" |
| 1358 " CallJsFunction(bar, 10 * 1000);\n" | |
| 1359 " } catch(e) {}\n" | |
| 1360 " }\n" | |
| 1361 "}"; | 1331 "}"; |
| 1362 | 1332 |
| 1363 | 1333 |
| 1364 // [Top down]: | 1334 // [Top down]: |
| 1365 // 57 0 (root) #0 1 | 1335 // 57 0 (root) #0 1 |
| 1366 // 55 1 start #16 3 | 1336 // 55 1 start #16 3 |
| 1367 // 54 0 CallJsFunction #0 4 | 1337 // 54 0 CallJsFunction #0 4 |
| 1368 // 54 3 bar #16 5 | 1338 // 54 3 bar #16 5 |
| 1369 // 51 51 foo #16 6 | 1339 // 51 51 foo #16 6 |
| 1370 // 2 2 (program) #0 2 | 1340 // 2 2 (program) #0 2 |
| 1371 TEST(JsNativeJsRuntimeJsSample) { | 1341 TEST(JsNativeJsRuntimeJsSample) { |
| 1372 v8::HandleScope scope(CcTest::isolate()); | 1342 v8::HandleScope scope(CcTest::isolate()); |
| 1373 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); | 1343 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
| 1374 v8::Context::Scope context_scope(env); | 1344 v8::Context::Scope context_scope(env); |
| 1375 | 1345 |
| 1376 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1346 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1377 env->GetIsolate(), CallJsFunction); | 1347 env->GetIsolate(), CallJsFunction); |
| 1378 v8::Local<v8::Function> func = func_template->GetFunction(); | 1348 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 1379 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); | 1349 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); |
| 1380 env->Global()->Set( | 1350 env->Global()->Set( |
| 1381 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); | 1351 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); |
| 1382 | 1352 |
| 1383 v8::Script::Compile( | 1353 v8::Script::Compile( |
| 1384 v8::String::NewFromUtf8(env->GetIsolate(), | 1354 v8::String::NewFromUtf8(env->GetIsolate(), |
| 1385 js_native_js_runtime_js_test_source))->Run(); | 1355 js_native_js_runtime_js_test_source))->Run(); |
| 1386 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1356 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1387 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1357 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1388 | 1358 |
| 1389 int32_t duration_ms = 20; | 1359 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
| 1390 v8::Handle<v8::Value> args[] = { | |
| 1391 v8::Integer::New(env->GetIsolate(), duration_ms) | |
| 1392 }; | |
| 1393 v8::CpuProfile* profile = | |
| 1394 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | |
| 1395 | 1360 |
| 1396 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1361 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1397 ScopedVector<v8::Handle<v8::String> > names(3); | 1362 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1398 names[0] = v8::String::NewFromUtf8( | 1363 names[0] = v8::String::NewFromUtf8( |
| 1399 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1364 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1400 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1365 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1401 ProfileGenerator::kProgramEntryName); | 1366 ProfileGenerator::kProgramEntryName); |
| 1402 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1367 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1403 CheckChildrenNames(root, names); | 1368 CheckChildrenNames(root, names); |
| 1404 | 1369 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1422 profile->Delete(); | 1387 profile->Delete(); |
| 1423 } | 1388 } |
| 1424 | 1389 |
| 1425 | 1390 |
| 1426 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1391 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1427 CallJsFunction(info); | 1392 CallJsFunction(info); |
| 1428 } | 1393 } |
| 1429 | 1394 |
| 1430 | 1395 |
| 1431 static const char* js_native1_js_native2_js_test_source = | 1396 static const char* js_native1_js_native2_js_test_source = |
| 1432 "var is_profiling = false;\n" | 1397 "function foo() {\n" |
| 1433 "function foo(iterations) {\n" | 1398 " try {\n" |
| 1434 " if (!is_profiling) {\n" | |
| 1435 " is_profiling = true;\n" | |
| 1436 " startProfiling('my_profile');\n" | 1399 " startProfiling('my_profile');\n" |
| 1437 " }\n" | 1400 " } catch(e) {}\n" |
| 1438 " var r = 0;\n" | |
| 1439 " for (var i = 0; i < iterations; i++) { r += i; }\n" | |
| 1440 " return r;\n" | |
| 1441 "}\n" | 1401 "}\n" |
| 1442 "function bar(iterations) {\n" | 1402 "function bar() {\n" |
| 1443 " CallJsFunction2(foo, iterations);\n" | 1403 " CallJsFunction2(foo);\n" |
| 1444 "}\n" | 1404 "}\n" |
| 1445 "function start(duration) {\n" | 1405 "function start() {\n" |
| 1446 " var start = Date.now();\n" | 1406 " try {\n" |
| 1447 " while (Date.now() - start < duration) {\n" | 1407 " CallJsFunction1(bar);\n" |
| 1448 " try {\n" | 1408 " } catch(e) {}\n" |
| 1449 " CallJsFunction1(bar, 10 * 1000);\n" | |
| 1450 " } catch(e) {}\n" | |
| 1451 " }\n" | |
| 1452 "}"; | 1409 "}"; |
| 1453 | 1410 |
| 1454 | 1411 |
| 1455 // [Top down]: | 1412 // [Top down]: |
| 1456 // 57 0 (root) #0 1 | 1413 // 57 0 (root) #0 1 |
| 1457 // 55 1 start #16 3 | 1414 // 55 1 start #16 3 |
| 1458 // 54 0 CallJsFunction1 #0 4 | 1415 // 54 0 CallJsFunction1 #0 4 |
| 1459 // 54 0 bar #16 5 | 1416 // 54 0 bar #16 5 |
| 1460 // 54 0 CallJsFunction2 #0 6 | 1417 // 54 0 CallJsFunction2 #0 6 |
| 1461 // 54 54 foo #16 7 | 1418 // 54 54 foo #16 7 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1477 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); | 1434 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); |
| 1478 env->Global()->Set( | 1435 env->Global()->Set( |
| 1479 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); | 1436 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); |
| 1480 | 1437 |
| 1481 v8::Script::Compile( | 1438 v8::Script::Compile( |
| 1482 v8::String::NewFromUtf8(env->GetIsolate(), | 1439 v8::String::NewFromUtf8(env->GetIsolate(), |
| 1483 js_native1_js_native2_js_test_source))->Run(); | 1440 js_native1_js_native2_js_test_source))->Run(); |
| 1484 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1441 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1485 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1442 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1486 | 1443 |
| 1487 int32_t duration_ms = 20; | 1444 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0, false); |
| 1488 v8::Handle<v8::Value> args[] = { | |
| 1489 v8::Integer::New(env->GetIsolate(), duration_ms) | |
| 1490 }; | |
| 1491 v8::CpuProfile* profile = | |
| 1492 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | |
| 1493 | 1445 |
| 1494 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1446 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1495 ScopedVector<v8::Handle<v8::String> > names(3); | 1447 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1496 names[0] = v8::String::NewFromUtf8( | 1448 names[0] = v8::String::NewFromUtf8( |
| 1497 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1449 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1498 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1450 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1499 ProfileGenerator::kProgramEntryName); | 1451 ProfileGenerator::kProgramEntryName); |
| 1500 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1452 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1501 CheckChildrenNames(root, names); | 1453 CheckChildrenNames(root, names); |
| 1502 | 1454 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 inner_profile = NULL; | 1612 inner_profile = NULL; |
| 1661 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1613 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1662 | 1614 |
| 1663 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); | 1615 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
| 1664 CHECK(outer_profile); | 1616 CHECK(outer_profile); |
| 1665 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1617 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 1666 outer_profile->Delete(); | 1618 outer_profile->Delete(); |
| 1667 outer_profile = NULL; | 1619 outer_profile = NULL; |
| 1668 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1620 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1669 } | 1621 } |
| OLD | NEW |