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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 427 |
428 | 428 |
429 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, | 429 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, |
430 const char* name) { | 430 const char* name) { |
431 int count = node->GetChildrenCount(); | 431 int count = node->GetChildrenCount(); |
432 v8::Handle<v8::String> nameHandle = v8::String::New(name); | 432 v8::Handle<v8::String> nameHandle = v8::String::New(name); |
433 for (int i = 0; i < count; i++) { | 433 for (int i = 0; i < count; i++) { |
434 const v8::CpuProfileNode* child = node->GetChild(i); | 434 const v8::CpuProfileNode* child = node->GetChild(i); |
435 if (nameHandle->Equals(child->GetFunctionName())) return child; | 435 if (nameHandle->Equals(child->GetFunctionName())) return child; |
436 } | 436 } |
437 CHECK(false); | |
438 return NULL; | 437 return NULL; |
439 } | 438 } |
440 | 439 |
441 | 440 |
| 441 static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node, |
| 442 const char* name) { |
| 443 const v8::CpuProfileNode* result = FindChild(node, name); |
| 444 CHECK(result); |
| 445 return result; |
| 446 } |
| 447 |
| 448 |
442 static void CheckSimpleBranch(const v8::CpuProfileNode* node, | 449 static void CheckSimpleBranch(const v8::CpuProfileNode* node, |
443 const char* names[], int length) { | 450 const char* names[], int length) { |
444 for (int i = 0; i < length; i++) { | 451 for (int i = 0; i < length; i++) { |
445 const char* name = names[i]; | 452 const char* name = names[i]; |
446 node = FindChild(node, name); | 453 node = GetChild(node, name); |
447 CHECK(node); | |
448 int expectedChildrenCount = (i == length - 1) ? 0 : 1; | 454 int expectedChildrenCount = (i == length - 1) ? 0 : 1; |
449 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); | 455 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); |
450 } | 456 } |
451 } | 457 } |
452 | 458 |
453 | 459 |
454 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" | 460 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" |
455 " this.mmm = 0;\n" | 461 " this.mmm = 0;\n" |
456 " var start = Date.now();\n" | 462 " var start = Date.now();\n" |
457 " while (Date.now() - start < timeout) {\n" | 463 " while (Date.now() - start < timeout) {\n" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 const_cast<v8::CpuProfile*>(profile))->Print(); | 534 const_cast<v8::CpuProfile*>(profile))->Print(); |
529 | 535 |
530 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 536 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
531 | 537 |
532 ScopedVector<v8::Handle<v8::String> > names(3); | 538 ScopedVector<v8::Handle<v8::String> > names(3); |
533 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 539 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
534 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 540 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
535 names[2] = v8::String::New("start"); | 541 names[2] = v8::String::New("start"); |
536 CheckChildrenNames(root, names); | 542 CheckChildrenNames(root, names); |
537 | 543 |
538 const v8::CpuProfileNode* startNode = FindChild(root, "start"); | 544 const v8::CpuProfileNode* startNode = GetChild(root, "start"); |
539 CHECK_EQ(1, startNode->GetChildrenCount()); | 545 CHECK_EQ(1, startNode->GetChildrenCount()); |
540 | 546 |
541 const v8::CpuProfileNode* fooNode = FindChild(startNode, "foo"); | 547 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); |
542 CHECK_EQ(3, fooNode->GetChildrenCount()); | 548 CHECK_EQ(3, fooNode->GetChildrenCount()); |
543 | 549 |
544 const char* barBranch[] = { "bar", "delay", "loop" }; | 550 const char* barBranch[] = { "bar", "delay", "loop" }; |
545 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); | 551 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); |
546 const char* bazBranch[] = { "baz", "delay", "loop" }; | 552 const char* bazBranch[] = { "baz", "delay", "loop" }; |
547 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); | 553 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); |
548 const char* delayBranch[] = { "delay", "loop" }; | 554 const char* delayBranch[] = { "delay", "loop" }; |
549 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); | 555 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); |
550 | 556 |
551 cpu_profiler->DeleteAllCpuProfiles(); | 557 cpu_profiler->DeleteAllCpuProfiles(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 611 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
606 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 612 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
607 names[2] = v8::String::New("start"); | 613 names[2] = v8::String::New("start"); |
608 CheckChildrenNames(root, names); | 614 CheckChildrenNames(root, names); |
609 | 615 |
610 const v8::CpuProfileNode* startNode = FindChild(root, "start"); | 616 const v8::CpuProfileNode* startNode = FindChild(root, "start"); |
611 // On slow machines there may be no meaningfull samples at all, skip the | 617 // On slow machines there may be no meaningfull samples at all, skip the |
612 // check there. | 618 // check there. |
613 if (startNode && startNode->GetChildrenCount() > 0) { | 619 if (startNode && startNode->GetChildrenCount() > 0) { |
614 CHECK_EQ(1, startNode->GetChildrenCount()); | 620 CHECK_EQ(1, startNode->GetChildrenCount()); |
615 const v8::CpuProfileNode* delayNode = FindChild(startNode, "delay"); | 621 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); |
616 if (delayNode->GetChildrenCount() > 0) { | 622 if (delayNode->GetChildrenCount() > 0) { |
617 CHECK_EQ(1, delayNode->GetChildrenCount()); | 623 CHECK_EQ(1, delayNode->GetChildrenCount()); |
618 FindChild(delayNode, "loop"); | 624 GetChild(delayNode, "loop"); |
619 } | 625 } |
620 } | 626 } |
621 | 627 |
622 cpu_profiler->DeleteAllCpuProfiles(); | 628 cpu_profiler->DeleteAllCpuProfiles(); |
623 } | 629 } |
OLD | NEW |