Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: test/cctest/test-cpu-profiler.cc

Issue 301603005: Unflake and speedup JsNative*Sample cpu profile tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebaseline Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1016 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1017 GetChild(isolate, root, "start"); 1017 GetChild(isolate, root, "start");
1018 const v8::CpuProfileNode* startNode = 1018 const v8::CpuProfileNode* startNode =
1019 GetChild(isolate, root, "start"); 1019 GetChild(isolate, root, "start");
1020 GetChild(isolate, startNode, "fooMethod"); 1020 GetChild(isolate, startNode, "fooMethod");
1021 1021
1022 profile->Delete(); 1022 profile->Delete();
1023 } 1023 }
1024 1024
1025 1025
1026 static const char* bound_function_test_source = "function foo(iterations) {\n" 1026 static const char* bound_function_test_source =
1027 " var r = 0;\n" 1027 "function foo() {\n"
1028 " for (var i = 0; i < iterations; i++) { r += i; }\n" 1028 " startProfiling('my_profile');\n"
1029 " return r;\n" 1029 "}\n"
1030 "}\n" 1030 "function start() {\n"
1031 "function start(duration) {\n" 1031 " var callback = foo.bind(this);\n"
1032 " var callback = foo.bind(this);\n" 1032 " callback();\n"
1033 " var start = Date.now();\n" 1033 "}";
1034 " while (Date.now() - start < duration) {\n"
1035 " callback(10 * 1000);\n"
1036 " }\n"
1037 "}";
1038 1034
1039 1035
1040 TEST(BoundFunctionCall) { 1036 TEST(BoundFunctionCall) {
1041 LocalContext env; 1037 v8::HandleScope scope(CcTest::isolate());
1042 v8::HandleScope scope(env->GetIsolate()); 1038 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1039 v8::Context::Scope context_scope(env);
1043 1040
1044 v8::Script::Compile( 1041 v8::Script::Compile(
1045 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) 1042 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source))
1046 ->Run(); 1043 ->Run();
1047 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1044 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1048 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1045 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
1049 1046
1050 int32_t duration_ms = 100; 1047 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
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 1048
1057 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1049 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1058 ScopedVector<v8::Handle<v8::String> > names(3); 1050 ScopedVector<v8::Handle<v8::String> > names(3);
1059 names[0] = v8::String::NewFromUtf8( 1051 names[0] = v8::String::NewFromUtf8(
1060 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); 1052 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
1061 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), 1053 names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
1062 ProfileGenerator::kProgramEntryName); 1054 ProfileGenerator::kProgramEntryName);
1063 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); 1055 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
1064 // Don't allow |foo| node to be at the top level. 1056 // Don't allow |foo| node to be at the top level.
1065 CheckChildrenNames(root, names); 1057 CheckChildrenNames(root, names);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1299 }
1308 // TODO(alph): 1300 // TODO(alph):
1309 // In theory there must be one more 'foo' and a 'startProfiling' nodes, 1301 // In theory there must be one more 'foo' and a 'startProfiling' nodes,
1310 // but due to unstable top frame extraction these might be missing. 1302 // but due to unstable top frame extraction these might be missing.
1311 1303
1312 profile->Delete(); 1304 profile->Delete();
1313 } 1305 }
1314 1306
1315 1307
1316 static const char* js_native_js_test_source = 1308 static const char* js_native_js_test_source =
1317 "var is_profiling = false;\n" 1309 "function foo() {\n"
1318 "function foo(iterations) {\n" 1310 " startProfiling('my_profile');\n"
1319 " if (!is_profiling) {\n" 1311 "}\n"
1320 " is_profiling = true;\n" 1312 "function bar() {\n"
1321 " startProfiling('my_profile');\n" 1313 " try { foo(); } catch(e) {}\n"
1322 " }\n" 1314 "}\n"
1323 " var r = 0;\n" 1315 "function start() {\n"
1324 " for (var i = 0; i < iterations; i++) { r += i; }\n" 1316 " try {\n"
1325 " return r;\n" 1317 " CallJsFunction(bar);\n"
1326 "}\n" 1318 " } catch(e) {}\n"
1327 "function bar(iterations) {\n" 1319 "}";
1328 " try { foo(iterations); } catch(e) {}\n"
1329 "}\n"
1330 "function start(duration) {\n"
1331 " var start = Date.now();\n"
1332 " while (Date.now() - start < duration) {\n"
1333 " try {\n"
1334 " CallJsFunction(bar, 10 * 1000);\n"
1335 " } catch(e) {}\n"
1336 " }\n"
1337 "}";
1338 1320
1339 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { 1321 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
1340 v8::Handle<v8::Function> function = info[0].As<v8::Function>(); 1322 v8::Handle<v8::Function> function = info[0].As<v8::Function>();
1341 v8::Handle<v8::Value> argv[] = { info[1] }; 1323 v8::Handle<v8::Value> argv[] = { info[1] };
1342 function->Call(info.This(), ARRAY_SIZE(argv), argv); 1324 function->Call(info.This(), ARRAY_SIZE(argv), argv);
1343 } 1325 }
1344 1326
1345 1327
1346 // [Top down]: 1328 // [Top down]:
1347 // 58 0 (root) #0 1 1329 // 58 0 (root) #0 1
(...skipping 12 matching lines...) Expand all
1360 v8::Local<v8::Function> func = func_template->GetFunction(); 1342 v8::Local<v8::Function> func = func_template->GetFunction();
1361 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); 1343 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
1362 env->Global()->Set( 1344 env->Global()->Set(
1363 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); 1345 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
1364 1346
1365 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), 1347 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(),
1366 js_native_js_test_source))->Run(); 1348 js_native_js_test_source))->Run();
1367 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1349 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1368 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1350 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
1369 1351
1370 int32_t duration_ms = 20; 1352 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1371 v8::Handle<v8::Value> args[] = {
1372 v8::Integer::New(env->GetIsolate(), duration_ms)
1373 };
1374 v8::CpuProfile* profile =
1375 RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
1376 1353
1377 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1354 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1378 { 1355 {
1379 ScopedVector<v8::Handle<v8::String> > names(3); 1356 ScopedVector<v8::Handle<v8::String> > names(3);
1380 names[0] = v8::String::NewFromUtf8( 1357 names[0] = v8::String::NewFromUtf8(
1381 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); 1358 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
1382 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), 1359 names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
1383 ProfileGenerator::kProgramEntryName); 1360 ProfileGenerator::kProgramEntryName);
1384 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); 1361 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
1385 CheckChildrenNames(root, names); 1362 CheckChildrenNames(root, names);
(...skipping 10 matching lines...) Expand all
1396 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); 1373 GetChild(env->GetIsolate(), nativeFunctionNode, "bar");
1397 1374
1398 CHECK_EQ(1, barNode->GetChildrenCount()); 1375 CHECK_EQ(1, barNode->GetChildrenCount());
1399 GetChild(env->GetIsolate(), barNode, "foo"); 1376 GetChild(env->GetIsolate(), barNode, "foo");
1400 1377
1401 profile->Delete(); 1378 profile->Delete();
1402 } 1379 }
1403 1380
1404 1381
1405 static const char* js_native_js_runtime_js_test_source = 1382 static const char* js_native_js_runtime_js_test_source =
1406 "var is_profiling = false;\n" 1383 "function foo() {\n"
1407 "function foo(iterations) {\n" 1384 " startProfiling('my_profile');\n"
1408 " if (!is_profiling) {\n" 1385 "}\n"
1409 " is_profiling = true;\n" 1386 "var bound = foo.bind(this);\n"
1410 " startProfiling('my_profile');\n" 1387 "function bar() {\n"
1411 " }\n" 1388 " try { bound(); } catch(e) {}\n"
1412 " var r = 0;\n" 1389 "}\n"
1413 " for (var i = 0; i < iterations; i++) { r += i; }\n" 1390 "function start() {\n"
1414 " return r;\n" 1391 " try {\n"
1415 "}\n" 1392 " CallJsFunction(bar);\n"
1416 "var bound = foo.bind(this);\n" 1393 " } catch(e) {}\n"
1417 "function bar(iterations) {\n" 1394 "}";
1418 " try { bound(iterations); } catch(e) {}\n"
1419 "}\n"
1420 "function start(duration) {\n"
1421 " var start = Date.now();\n"
1422 " while (Date.now() - start < duration) {\n"
1423 " try {\n"
1424 " CallJsFunction(bar, 10 * 1000);\n"
1425 " } catch(e) {}\n"
1426 " }\n"
1427 "}";
1428 1395
1429 1396
1430 // [Top down]: 1397 // [Top down]:
1431 // 57 0 (root) #0 1 1398 // 57 0 (root) #0 1
1432 // 55 1 start #16 3 1399 // 55 1 start #16 3
1433 // 54 0 CallJsFunction #0 4 1400 // 54 0 CallJsFunction #0 4
1434 // 54 3 bar #16 5 1401 // 54 3 bar #16 5
1435 // 51 51 foo #16 6 1402 // 51 51 foo #16 6
1436 // 2 2 (program) #0 2 1403 // 2 2 (program) #0 2
1437 TEST(JsNativeJsRuntimeJsSample) { 1404 TEST(JsNativeJsRuntimeJsSample) {
1438 v8::HandleScope scope(CcTest::isolate()); 1405 v8::HandleScope scope(CcTest::isolate());
1439 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1406 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1440 v8::Context::Scope context_scope(env); 1407 v8::Context::Scope context_scope(env);
1441 1408
1442 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1409 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1443 env->GetIsolate(), CallJsFunction); 1410 env->GetIsolate(), CallJsFunction);
1444 v8::Local<v8::Function> func = func_template->GetFunction(); 1411 v8::Local<v8::Function> func = func_template->GetFunction();
1445 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); 1412 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"));
1446 env->Global()->Set( 1413 env->Global()->Set(
1447 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); 1414 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func);
1448 1415
1449 v8::Script::Compile( 1416 v8::Script::Compile(
1450 v8::String::NewFromUtf8(env->GetIsolate(), 1417 v8::String::NewFromUtf8(env->GetIsolate(),
1451 js_native_js_runtime_js_test_source))->Run(); 1418 js_native_js_runtime_js_test_source))->Run();
1452 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1419 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1453 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1420 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
1454 1421
1455 int32_t duration_ms = 20; 1422 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1456 v8::Handle<v8::Value> args[] = {
1457 v8::Integer::New(env->GetIsolate(), duration_ms)
1458 };
1459 v8::CpuProfile* profile =
1460 RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
1461 1423
1462 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1424 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1463 ScopedVector<v8::Handle<v8::String> > names(3); 1425 ScopedVector<v8::Handle<v8::String> > names(3);
1464 names[0] = v8::String::NewFromUtf8( 1426 names[0] = v8::String::NewFromUtf8(
1465 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); 1427 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
1466 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), 1428 names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
1467 ProfileGenerator::kProgramEntryName); 1429 ProfileGenerator::kProgramEntryName);
1468 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); 1430 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
1469 CheckChildrenNames(root, names); 1431 CheckChildrenNames(root, names);
1470 1432
(...skipping 18 matching lines...) Expand all
1489 } 1451 }
1490 1452
1491 1453
1492 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { 1454 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
1493 v8::base::OS::Print("In CallJsFunction2\n"); 1455 v8::base::OS::Print("In CallJsFunction2\n");
1494 CallJsFunction(info); 1456 CallJsFunction(info);
1495 } 1457 }
1496 1458
1497 1459
1498 static const char* js_native1_js_native2_js_test_source = 1460 static const char* js_native1_js_native2_js_test_source =
1499 "var is_profiling = false;\n" 1461 "function foo() {\n"
1500 "function foo(iterations) {\n" 1462 " try {\n"
1501 " if (!is_profiling) {\n" 1463 " startProfiling('my_profile');\n"
1502 " is_profiling = true;\n" 1464 " } catch(e) {}\n"
1503 " startProfiling('my_profile');\n" 1465 "}\n"
1504 " }\n" 1466 "function bar() {\n"
1505 " var r = 0;\n" 1467 " CallJsFunction2(foo);\n"
1506 " for (var i = 0; i < iterations; i++) { r += i; }\n" 1468 "}\n"
1507 " return r;\n" 1469 "function start() {\n"
1508 "}\n" 1470 " try {\n"
1509 "function bar(iterations) {\n" 1471 " CallJsFunction1(bar);\n"
1510 " CallJsFunction2(foo, iterations);\n" 1472 " } catch(e) {}\n"
1511 "}\n" 1473 "}";
1512 "function start(duration) {\n"
1513 " var start = Date.now();\n"
1514 " while (Date.now() - start < duration) {\n"
1515 " try {\n"
1516 " CallJsFunction1(bar, 10 * 1000);\n"
1517 " } catch(e) {}\n"
1518 " }\n"
1519 "}";
1520 1474
1521 1475
1522 // [Top down]: 1476 // [Top down]:
1523 // 57 0 (root) #0 1 1477 // 57 0 (root) #0 1
1524 // 55 1 start #16 3 1478 // 55 1 start #16 3
1525 // 54 0 CallJsFunction1 #0 4 1479 // 54 0 CallJsFunction1 #0 4
1526 // 54 0 bar #16 5 1480 // 54 0 bar #16 5
1527 // 54 0 CallJsFunction2 #0 6 1481 // 54 0 CallJsFunction2 #0 6
1528 // 54 54 foo #16 7 1482 // 54 54 foo #16 7
1529 // 2 2 (program) #0 2 1483 // 2 2 (program) #0 2
(...skipping 14 matching lines...) Expand all
1544 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); 1498 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"));
1545 env->Global()->Set( 1499 env->Global()->Set(
1546 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); 1500 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2);
1547 1501
1548 v8::Script::Compile( 1502 v8::Script::Compile(
1549 v8::String::NewFromUtf8(env->GetIsolate(), 1503 v8::String::NewFromUtf8(env->GetIsolate(),
1550 js_native1_js_native2_js_test_source))->Run(); 1504 js_native1_js_native2_js_test_source))->Run();
1551 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 1505 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
1552 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); 1506 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start")));
1553 1507
1554 int32_t duration_ms = 20; 1508 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1555 v8::Handle<v8::Value> args[] = {
1556 v8::Integer::New(env->GetIsolate(), duration_ms)
1557 };
1558 v8::CpuProfile* profile =
1559 RunProfiler(env, function, args, ARRAY_SIZE(args), 10);
1560 1509
1561 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1510 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1562 ScopedVector<v8::Handle<v8::String> > names(3); 1511 ScopedVector<v8::Handle<v8::String> > names(3);
1563 names[0] = v8::String::NewFromUtf8( 1512 names[0] = v8::String::NewFromUtf8(
1564 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); 1513 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName);
1565 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), 1514 names[1] = v8::String::NewFromUtf8(env->GetIsolate(),
1566 ProfileGenerator::kProgramEntryName); 1515 ProfileGenerator::kProgramEntryName);
1567 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); 1516 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start");
1568 CheckChildrenNames(root, names); 1517 CheckChildrenNames(root, names);
1569 1518
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 inner_profile = NULL; 1676 inner_profile = NULL;
1728 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1677 CHECK_EQ(0, iprofiler->GetProfilesCount());
1729 1678
1730 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); 1679 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
1731 CHECK(outer_profile); 1680 CHECK(outer_profile);
1732 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1681 CHECK_EQ(1, iprofiler->GetProfilesCount());
1733 outer_profile->Delete(); 1682 outer_profile->Delete();
1734 outer_profile = NULL; 1683 outer_profile = NULL;
1735 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1684 CHECK_EQ(0, iprofiler->GetProfilesCount());
1736 } 1685 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698