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 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 CHECK_EQ(0, programNode->GetChildrenCount()); | 1353 CHECK_EQ(0, programNode->GetChildrenCount()); |
1354 CHECK_GE(programNode->GetHitCount(), 3); | 1354 CHECK_GE(programNode->GetHitCount(), 3); |
1355 | 1355 |
1356 const v8::CpuProfileNode* idleNode = | 1356 const v8::CpuProfileNode* idleNode = |
1357 GetChild(root, ProfileGenerator::kIdleEntryName); | 1357 GetChild(root, ProfileGenerator::kIdleEntryName); |
1358 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1358 CHECK_EQ(0, idleNode->GetChildrenCount()); |
1359 CHECK_GE(idleNode->GetHitCount(), 3); | 1359 CHECK_GE(idleNode->GetHitCount(), 3); |
1360 | 1360 |
1361 cpu_profiler->DeleteAllCpuProfiles(); | 1361 cpu_profiler->DeleteAllCpuProfiles(); |
1362 } | 1362 } |
| 1363 |
| 1364 |
| 1365 static void CheckFunctionDetails(const v8::CpuProfileNode* node, |
| 1366 const char* name, const char* script_name, int script_id, |
| 1367 int line, int column) { |
| 1368 CHECK_EQ(v8::String::New(name), node->GetFunctionName()); |
| 1369 CHECK_EQ(v8::String::New(script_name), node->GetScriptResourceName()); |
| 1370 CHECK_EQ(script_id, node->GetScriptId()); |
| 1371 CHECK_EQ(line, node->GetLineNumber()); |
| 1372 CHECK_EQ(column, node->GetColumnNumber()); |
| 1373 } |
| 1374 |
| 1375 |
| 1376 TEST(FunctionDetails) { |
| 1377 const char* extensions[] = { "v8/profiler" }; |
| 1378 v8::ExtensionConfiguration config(1, extensions); |
| 1379 LocalContext env(&config); |
| 1380 v8::HandleScope handleScope(env->GetIsolate()); |
| 1381 |
| 1382 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1383 CHECK_EQ(0, profiler->GetProfileCount()); |
| 1384 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::New( |
| 1385 " function foo\n() { try { bar(); } catch(e) {} }\n" |
| 1386 " function bar() { startProfiling(); }\n"), v8::String::New("script_a")); |
| 1387 script_a->Run(); |
| 1388 v8::Handle<v8::Script> script_b = v8::Script::Compile(v8::String::New( |
| 1389 "\n\n function baz() { try { foo(); } catch(e) {} }\n" |
| 1390 "\n\nbaz();\n" |
| 1391 "stopProfiling();\n"), v8::String::New("script_b")); |
| 1392 script_b->Run(); |
| 1393 CHECK_EQ(1, profiler->GetProfileCount()); |
| 1394 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); |
| 1395 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
| 1396 reinterpret_cast<ProfileNode*>( |
| 1397 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
| 1398 // The tree should look like this: |
| 1399 // 0 (root) 0 #1 |
| 1400 // 0 (anonymous function) 19 #2 no reason script_b:1 |
| 1401 // 0 baz 19 #3 TryCatchStatement script_b:3 |
| 1402 // 0 foo 18 #4 TryCatchStatement script_a:2 |
| 1403 // 1 bar 18 #5 no reason script_a:3 |
| 1404 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1405 const v8::CpuProfileNode* script = GetChild(root, |
| 1406 ProfileGenerator::kAnonymousFunctionName); |
| 1407 CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName, |
| 1408 "script_b", script_b->GetId(), 1, 1); |
| 1409 const v8::CpuProfileNode* baz = GetChild(script, "baz"); |
| 1410 CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16); |
| 1411 const v8::CpuProfileNode* foo = GetChild(baz, "foo"); |
| 1412 CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1); |
| 1413 const v8::CpuProfileNode* bar = GetChild(foo, "bar"); |
| 1414 CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14); |
| 1415 } |
OLD | NEW |