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

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

Issue 1665303004: Unflake CPU profiler tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: revert back to stochastic sampling. Created 4 years, 10 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
« no previous file with comments | « test/cctest/profiler-extension.cc ('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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 439 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
440 440
441 CHECK(profile); 441 CHECK(profile);
442 // Dump collected profile to have a better diagnostic in case of failure. 442 // Dump collected profile to have a better diagnostic in case of failure.
443 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 443 reinterpret_cast<i::CpuProfile*>(profile)->Print();
444 444
445 return profile; 445 return profile;
446 } 446 }
447 447
448 448
449 static bool ContainsString(v8::Local<v8::Context> context,
450 v8::Local<v8::String> string,
451 const Vector<v8::Local<v8::String> >& vector) {
452 for (int i = 0; i < vector.length(); i++) {
453 if (string->Equals(context, vector[i]).FromJust()) return true;
454 }
455 return false;
456 }
457
458
459 static void CheckChildrenNames(v8::Local<v8::Context> context,
460 const v8::CpuProfileNode* node,
461 const Vector<v8::Local<v8::String> >& names) {
462 int count = node->GetChildrenCount();
463 for (int i = 0; i < count; i++) {
464 v8::Local<v8::String> name = node->GetChild(i)->GetFunctionName();
465 if (!ContainsString(context, name, names)) {
466 char buffer[100];
467 i::SNPrintF(Vector<char>(buffer, arraysize(buffer)),
468 "Unexpected child '%s' found in '%s'",
469 *v8::String::Utf8Value(name),
470 *v8::String::Utf8Value(node->GetFunctionName()));
471 FATAL(buffer);
472 }
473 // Check that there are no duplicates.
474 for (int j = 0; j < count; j++) {
475 if (j == i) continue;
476 if (name->Equals(context, node->GetChild(j)->GetFunctionName())
477 .FromJust()) {
478 char buffer[100];
479 i::SNPrintF(Vector<char>(buffer, arraysize(buffer)),
480 "Second child with the same name '%s' found in '%s'",
481 *v8::String::Utf8Value(name),
482 *v8::String::Utf8Value(node->GetFunctionName()));
483 FATAL(buffer);
484 }
485 }
486 }
487 }
488
489
490 static const v8::CpuProfileNode* FindChild(v8::Local<v8::Context> context, 449 static const v8::CpuProfileNode* FindChild(v8::Local<v8::Context> context,
491 const v8::CpuProfileNode* node, 450 const v8::CpuProfileNode* node,
492 const char* name) { 451 const char* name) {
493 int count = node->GetChildrenCount(); 452 int count = node->GetChildrenCount();
494 v8::Local<v8::String> nameHandle = v8_str(name); 453 v8::Local<v8::String> nameHandle = v8_str(name);
495 for (int i = 0; i < count; i++) { 454 for (int i = 0; i < count; i++) {
496 const v8::CpuProfileNode* child = node->GetChild(i); 455 const v8::CpuProfileNode* child = node->GetChild(i);
497 if (nameHandle->Equals(context, child->GetFunctionName()).FromJust()) { 456 if (nameHandle->Equals(context, child->GetFunctionName()).FromJust()) {
498 return child; 457 return child;
499 } 458 }
(...skipping 15 matching lines...) Expand all
515 return result; 474 return result;
516 } 475 }
517 476
518 477
519 static void CheckSimpleBranch(v8::Local<v8::Context> context, 478 static void CheckSimpleBranch(v8::Local<v8::Context> context,
520 const v8::CpuProfileNode* node, 479 const v8::CpuProfileNode* node,
521 const char* names[], int length) { 480 const char* names[], int length) {
522 for (int i = 0; i < length; i++) { 481 for (int i = 0; i < length; i++) {
523 const char* name = names[i]; 482 const char* name = names[i];
524 node = GetChild(context, node, name); 483 node = GetChild(context, node, name);
525 int expectedChildrenCount = (i == length - 1) ? 0 : 1;
526 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount());
527 } 484 }
528 } 485 }
529 486
530 487
531 static const ProfileNode* GetSimpleBranch(v8::Local<v8::Context> context, 488 static const ProfileNode* GetSimpleBranch(v8::Local<v8::Context> context,
532 v8::CpuProfile* profile, 489 v8::CpuProfile* profile,
533 const char* names[], int length) { 490 const char* names[], int length) {
534 const v8::CpuProfileNode* node = profile->GetTopDownRoot(); 491 const v8::CpuProfileNode* node = profile->GetTopDownRoot();
535 for (int i = 0; i < length; i++) { 492 for (int i = 0; i < length; i++) {
536 node = GetChild(context, node, names[i]); 493 node = GetChild(context, node, names[i]);
537 } 494 }
538 return reinterpret_cast<const ProfileNode*>(node); 495 return reinterpret_cast<const ProfileNode*>(node);
539 } 496 }
540 497
541 static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) { 498 static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) {
542 info.GetIsolate()->GetCpuProfiler()->CollectSample(); 499 info.GetIsolate()->GetCpuProfiler()->CollectSample();
543 } 500 }
544 501
545 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" 502 static const char* cpu_profiler_test_source =
546 " this.mmm = 0;\n" 503 "%NeverOptimizeFunction(loop);\n"
547 " var start = Date.now();\n" 504 "%NeverOptimizeFunction(delay);\n"
548 " while (Date.now() - start < timeout) {\n" 505 "%NeverOptimizeFunction(bar);\n"
549 " var n = 100*1000;\n" 506 "%NeverOptimizeFunction(baz);\n"
550 " while(n > 1) {\n" 507 "%NeverOptimizeFunction(foo);\n"
551 " n--;\n" 508 "%NeverOptimizeFunction(start);\n"
552 " this.mmm += n * n * n;\n" 509 "function loop(timeout) {\n"
553 " }\n" 510 " this.mmm = 0;\n"
554 " }\n" 511 " var start = Date.now();\n"
555 "}\n" 512 " do {\n"
556 "function delay() { try { loop(10); } catch(e) { } }\n" 513 " var n = 1000;\n"
557 "function bar() { delay(); }\n" 514 " while(n > 1) {\n"
558 "function baz() { delay(); }\n" 515 " n--;\n"
559 "function foo() {\n" 516 " this.mmm += n * n * n;\n"
560 " try {\n" 517 " }\n"
561 " delay();\n" 518 " } while (Date.now() - start < timeout);\n"
562 " bar();\n" 519 "}\n"
563 " delay();\n" 520 "function delay() { loop(10); }\n"
564 " baz();\n" 521 "function bar() { delay(); }\n"
565 " } catch (e) { }\n" 522 "function baz() { delay(); }\n"
566 "}\n" 523 "function foo() {\n"
567 "function start(timeout) {\n" 524 " delay();\n"
568 " var start = Date.now();\n" 525 " bar();\n"
569 " do {\n" 526 " delay();\n"
570 " foo();\n" 527 " baz();\n"
571 " var duration = Date.now() - start;\n" 528 "}\n"
572 " } while (duration < timeout);\n" 529 "function start(duration) {\n"
573 " return duration;\n" 530 " var start = Date.now();\n"
574 "}\n"; 531 " do {\n"
575 532 " foo();\n"
533 " } while (Date.now() - start < duration);\n"
534 "}\n";
576 535
577 // Check that the profile tree for the script above will look like the 536 // Check that the profile tree for the script above will look like the
578 // following: 537 // following:
579 // 538 //
580 // [Top down]: 539 // [Top down]:
581 // 1062 0 (root) [-1] 540 // 1062 0 (root) [-1]
582 // 1054 0 start [-1] 541 // 1054 0 start [-1]
583 // 1054 1 foo [-1] 542 // 1054 1 foo [-1]
584 // 265 0 baz [-1] 543 // 265 0 baz [-1]
585 // 265 1 delay [-1] 544 // 265 1 delay [-1]
586 // 264 264 loop [-1] 545 // 264 264 loop [-1]
587 // 525 3 delay [-1] 546 // 525 3 delay [-1]
588 // 522 522 loop [-1] 547 // 522 522 loop [-1]
589 // 263 0 bar [-1] 548 // 263 0 bar [-1]
590 // 263 1 delay [-1] 549 // 263 1 delay [-1]
591 // 262 262 loop [-1] 550 // 262 262 loop [-1]
592 // 2 2 (program) [-1] 551 // 2 2 (program) [-1]
593 // 6 6 (garbage collector) [-1] 552 // 6 6 (garbage collector) [-1]
594 TEST(CollectCpuProfile) { 553 TEST(CollectCpuProfile) {
554 i::FLAG_allow_natives_syntax = true;
595 LocalContext env; 555 LocalContext env;
596 v8::HandleScope scope(env->GetIsolate()); 556 v8::HandleScope scope(env->GetIsolate());
597 557
598 CompileRun(cpu_profiler_test_source); 558 CompileRun(cpu_profiler_test_source);
599 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 559 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
600 560
601 int32_t profiling_interval_ms = 200; 561 int32_t profiling_interval_ms = 200;
602 v8::Local<v8::Value> args[] = { 562 v8::Local<v8::Value> args[] = {
603 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; 563 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
604 v8::CpuProfile* profile = 564 v8::CpuProfile* profile =
605 RunProfiler(env.local(), function, args, arraysize(args), 200); 565 RunProfiler(env.local(), function, args, arraysize(args), 1000);
606 function->Call(env.local(), env->Global(), arraysize(args), args)
607 .ToLocalChecked();
608 566
609 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 567 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
610
611 ScopedVector<v8::Local<v8::String> > names(3);
612 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
613 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
614 names[2] = v8_str("start");
615 CheckChildrenNames(env.local(), root, names);
616
617 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start"); 568 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
618 CHECK_EQ(1, startNode->GetChildrenCount());
619
620 const v8::CpuProfileNode* fooNode = GetChild(env.local(), startNode, "foo"); 569 const v8::CpuProfileNode* fooNode = GetChild(env.local(), startNode, "foo");
621 CHECK_EQ(3, fooNode->GetChildrenCount());
622 570
623 const char* barBranch[] = { "bar", "delay", "loop" }; 571 const char* barBranch[] = { "bar", "delay", "loop" };
624 CheckSimpleBranch(env.local(), fooNode, barBranch, arraysize(barBranch)); 572 CheckSimpleBranch(env.local(), fooNode, barBranch, arraysize(barBranch));
625 const char* bazBranch[] = { "baz", "delay", "loop" }; 573 const char* bazBranch[] = { "baz", "delay", "loop" };
626 CheckSimpleBranch(env.local(), fooNode, bazBranch, arraysize(bazBranch)); 574 CheckSimpleBranch(env.local(), fooNode, bazBranch, arraysize(bazBranch));
627 const char* delayBranch[] = { "delay", "loop" }; 575 const char* delayBranch[] = { "delay", "loop" };
628 CheckSimpleBranch(env.local(), fooNode, delayBranch, arraysize(delayBranch)); 576 CheckSimpleBranch(env.local(), fooNode, delayBranch, arraysize(delayBranch));
629 577
630 profile->Delete(); 578 profile->Delete();
631 } 579 }
632 580
633
634 static const char* hot_deopt_no_frame_entry_test_source = 581 static const char* hot_deopt_no_frame_entry_test_source =
635 "function foo(a, b) {\n" 582 "function foo(a, b) {\n"
636 " try {\n" 583 " try {\n"
yurys 2016/02/05 22:54:11 Can you also replace try/catch with %NeverOptimize
alph 2016/02/05 23:32:09 Done.
637 " return a + b;\n" 584 " return a + b;\n"
638 " } catch (e) { }\n" 585 " } catch (e) { }\n"
639 "}\n" 586 "}\n"
640 "function start(timeout) {\n" 587 "function start(timeout) {\n"
641 " var start = Date.now();\n" 588 " var start = Date.now();\n"
642 " do {\n" 589 " do {\n"
643 " for (var i = 1; i < 1000; ++i) foo(1, i);\n" 590 " for (var i = 1; i < 1000; ++i) foo(1, i);\n"
644 " var duration = Date.now() - start;\n" 591 " var duration = Date.now() - start;\n"
645 " } while (duration < timeout);\n" 592 " } while (duration < timeout);\n"
646 " return duration;\n" 593 " return duration;\n"
647 "}\n"; 594 "}\n";
648 595
649 // Check that the profile tree for the script above will look like the 596 // Check that the profile tree for the script above will look like the
650 // following: 597 // following:
651 // 598 //
652 // [Top down]: 599 // [Top down]:
653 // 1062 0 (root) [-1] 600 // 1062 0 (root) [-1]
654 // 1054 0 start [-1] 601 // 1054 0 start [-1]
655 // 1054 1 foo [-1] 602 // 1054 1 foo [-1]
656 // 2 2 (program) [-1] 603 // 2 2 (program) [-1]
657 // 6 6 (garbage collector) [-1] 604 // 6 6 (garbage collector) [-1]
658 // 605 //
659 // The test checks no FP ranges are present in a deoptimized funcion. 606 // The test checks no FP ranges are present in a deoptimized funcion.
660 // If 'foo' has no ranges the samples falling into the prologue will miss the 607 // If 'foo' has no ranges the samples falling into the prologue will miss the
661 // 'start' function on the stack, so 'foo' will be attached to the (root). 608 // 'start' function on the stack, so 'foo' will be attached to the (root).
662 TEST(HotDeoptNoFrameEntry) { 609 TEST(HotDeoptNoFrameEntry) {
663 LocalContext env; 610 LocalContext env;
664 v8::HandleScope scope(env->GetIsolate()); 611 v8::HandleScope scope(env->GetIsolate());
665 612
666 CompileRun(hot_deopt_no_frame_entry_test_source); 613 CompileRun(hot_deopt_no_frame_entry_test_source);
667 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 614 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
668 615
669 int32_t profiling_interval_ms = 200; 616 int32_t profiling_interval_ms = 200;
670 v8::Local<v8::Value> args[] = { 617 v8::Local<v8::Value> args[] = {
671 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; 618 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
672 v8::CpuProfile* profile = 619 v8::CpuProfile* profile =
673 RunProfiler(env.local(), function, args, arraysize(args), 200); 620 RunProfiler(env.local(), function, args, arraysize(args), 1000);
674 function->Call(env.local(), env->Global(), arraysize(args), args) 621 function->Call(env.local(), env->Global(), arraysize(args), args)
675 .ToLocalChecked(); 622 .ToLocalChecked();
676 623
677 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 624 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
678
679 ScopedVector<v8::Local<v8::String> > names(3);
680 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
681 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
682 names[2] = v8_str("start");
683 CheckChildrenNames(env.local(), root, names);
684
685 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start"); 625 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
686 CHECK_EQ(1, startNode->GetChildrenCount());
687
688 GetChild(env.local(), startNode, "foo"); 626 GetChild(env.local(), startNode, "foo");
689 627
690 profile->Delete(); 628 profile->Delete();
691 } 629 }
692 630
693
694 TEST(CollectCpuProfileSamples) { 631 TEST(CollectCpuProfileSamples) {
632 i::FLAG_allow_natives_syntax = true;
695 LocalContext env; 633 LocalContext env;
696 v8::HandleScope scope(env->GetIsolate()); 634 v8::HandleScope scope(env->GetIsolate());
697 635
698 CompileRun(cpu_profiler_test_source); 636 CompileRun(cpu_profiler_test_source);
699 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 637 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
700 638
701 int32_t profiling_interval_ms = 200; 639 int32_t profiling_interval_ms = 200;
702 v8::Local<v8::Value> args[] = { 640 v8::Local<v8::Value> args[] = {
703 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; 641 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
704 v8::CpuProfile* profile = 642 v8::CpuProfile* profile =
705 RunProfiler(env.local(), function, args, arraysize(args), 200, true); 643 RunProfiler(env.local(), function, args, arraysize(args), 1000, true);
706 644
707 CHECK_LE(200, profile->GetSamplesCount()); 645 CHECK_LE(200, profile->GetSamplesCount());
708 uint64_t end_time = profile->GetEndTime(); 646 uint64_t end_time = profile->GetEndTime();
709 uint64_t current_time = profile->GetStartTime(); 647 uint64_t current_time = profile->GetStartTime();
710 CHECK_LE(current_time, end_time); 648 CHECK_LE(current_time, end_time);
711 for (int i = 0; i < profile->GetSamplesCount(); i++) { 649 for (int i = 0; i < profile->GetSamplesCount(); i++) {
712 CHECK(profile->GetSample(i)); 650 CHECK(profile->GetSample(i));
713 uint64_t timestamp = profile->GetSampleTimestamp(i); 651 uint64_t timestamp = profile->GetSampleTimestamp(i);
714 CHECK_LE(current_time, timestamp); 652 CHECK_LE(current_time, timestamp);
715 CHECK_LE(timestamp, end_time); 653 CHECK_LE(timestamp, end_time);
716 current_time = timestamp; 654 current_time = timestamp;
717 } 655 }
718 656
719 profile->Delete(); 657 profile->Delete();
720 } 658 }
721 659
722 660 static const char* cpu_profiler_test_source2 =
723 static const char* cpu_profiler_test_source2 = "function loop() {}\n" 661 "function loop() {}\n"
724 "function delay() { loop(); }\n" 662 "function delay() { try { loop(); } catch (e) {} }\n"
725 "function start(count) {\n" 663 "function start(duration) {\n"
726 " var k = 0;\n" 664 " var start = Date.now();\n"
727 " do {\n" 665 " try {\n"
728 " delay();\n" 666 " do {\n"
729 " } while (++k < count*100*1000);\n" 667 " for (var i = 0; i < 10000; ++i) delay();\n"
730 "}\n"; 668 " } while (Date.now() - start < duration);\n"
669 " } catch (e) {}\n"
670 "}";
731 671
732 // Check that the profile tree doesn't contain unexpected traces: 672 // Check that the profile tree doesn't contain unexpected traces:
733 // - 'loop' can be called only by 'delay' 673 // - 'loop' can be called only by 'delay'
734 // - 'delay' may be called only by 'start' 674 // - 'delay' may be called only by 'start'
735 // The profile will look like the following: 675 // The profile will look like the following:
736 // 676 //
737 // [Top down]: 677 // [Top down]:
738 // 135 0 (root) [-1] #1 678 // 135 0 (root) [-1] #1
739 // 121 72 start [-1] #3 679 // 121 72 start [-1] #3
740 // 49 33 delay [-1] #4 680 // 49 33 delay [-1] #4
741 // 16 16 loop [-1] #5 681 // 16 16 loop [-1] #5
742 // 14 14 (program) [-1] #2 682 // 14 14 (program) [-1] #2
743 TEST(SampleWhenFrameIsNotSetup) { 683 TEST(SampleWhenFrameIsNotSetup) {
744 LocalContext env; 684 LocalContext env;
745 v8::HandleScope scope(env->GetIsolate()); 685 v8::HandleScope scope(env->GetIsolate());
746 686
747 CompileRun(cpu_profiler_test_source2); 687 CompileRun(cpu_profiler_test_source2);
748 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 688 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
749 689
750 int32_t repeat_count = 100; 690 int32_t duration_ms = 100;
751 #if defined(USE_SIMULATOR)
752 // Simulators are much slower.
753 repeat_count = 1;
754 #endif
755 v8::Local<v8::Value> args[] = { 691 v8::Local<v8::Value> args[] = {
756 v8::Integer::New(env->GetIsolate(), repeat_count)}; 692 v8::Integer::New(env->GetIsolate(), duration_ms)};
757 v8::CpuProfile* profile = 693 v8::CpuProfile* profile =
758 RunProfiler(env.local(), function, args, arraysize(args), 100); 694 RunProfiler(env.local(), function, args, arraysize(args), 1000);
759 695
760 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 696 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
761 697 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
762 ScopedVector<v8::Local<v8::String> > names(3); 698 const v8::CpuProfileNode* delayNode =
763 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); 699 GetChild(env.local(), startNode, "delay");
764 names[1] = v8_str(ProfileGenerator::kProgramEntryName); 700 GetChild(env.local(), delayNode, "loop");
765 names[2] = v8_str("start");
766 CheckChildrenNames(env.local(), root, names);
767
768 const v8::CpuProfileNode* startNode = FindChild(env.local(), root, "start");
769 // On slow machines there may be no meaningfull samples at all, skip the
770 // check there.
771 if (startNode && startNode->GetChildrenCount() > 0) {
772 CHECK_EQ(1, startNode->GetChildrenCount());
773 const v8::CpuProfileNode* delayNode =
774 GetChild(env.local(), startNode, "delay");
775 if (delayNode->GetChildrenCount() > 0) {
776 CHECK_EQ(1, delayNode->GetChildrenCount());
777 GetChild(env.local(), delayNode, "loop");
778 }
779 }
780 701
781 profile->Delete(); 702 profile->Delete();
782 } 703 }
783 704
784
785 static const char* native_accessor_test_source = "function start(count) {\n" 705 static const char* native_accessor_test_source = "function start(count) {\n"
786 " for (var i = 0; i < count; i++) {\n" 706 " for (var i = 0; i < count; i++) {\n"
787 " var o = instance.foo;\n" 707 " var o = instance.foo;\n"
788 " instance.foo = o + 1;\n" 708 " instance.foo = o + 1;\n"
789 " }\n" 709 " }\n"
790 "}\n"; 710 "}\n";
791 711
792
793 class TestApiCallbacks { 712 class TestApiCallbacks {
794 public: 713 public:
795 explicit TestApiCallbacks(int min_duration_ms) 714 explicit TestApiCallbacks(int min_duration_ms)
796 : min_duration_ms_(min_duration_ms), 715 : min_duration_ms_(min_duration_ms),
797 is_warming_up_(false) {} 716 is_warming_up_(false) {}
798 717
799 static void Getter(v8::Local<v8::String> name, 718 static void Getter(v8::Local<v8::String> name,
800 const v8::PropertyCallbackInfo<v8::Value>& info) { 719 const v8::PropertyCallbackInfo<v8::Value>& info) {
801 TestApiCallbacks* data = fromInfo(info); 720 TestApiCallbacks* data = fromInfo(info);
802 data->Wait(); 721 data->Wait();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 v8::HandleScope scope(CcTest::isolate()); 971 v8::HandleScope scope(CcTest::isolate());
1053 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 972 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1054 v8::Context::Scope context_scope(env); 973 v8::Context::Scope context_scope(env);
1055 974
1056 CompileRun(bound_function_test_source); 975 CompileRun(bound_function_test_source);
1057 v8::Local<v8::Function> function = GetFunction(env, "start"); 976 v8::Local<v8::Function> function = GetFunction(env, "start");
1058 977
1059 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); 978 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1060 979
1061 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 980 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1062 ScopedVector<v8::Local<v8::String> > names(3);
1063 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1064 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1065 names[2] = v8_str("start");
1066 // Don't allow |foo| node to be at the top level.
1067 CheckChildrenNames(env, root, names);
1068 981
1069 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); 982 const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
1070 GetChild(env, startNode, "foo"); 983 GetChild(env, startNode, "foo");
1071 984
1072 profile->Delete(); 985 profile->Delete();
1073 } 986 }
1074 987
1075 988
1076 // This tests checks distribution of the samples through the source lines. 989 // This tests checks distribution of the samples through the source lines.
1077 TEST(TickLines) { 990 TEST(TickLines) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 CHECK(func_node->GetLineTicks(&entries[0], line_count)); 1076 CHECK(func_node->GetLineTicks(&entries[0], line_count));
1164 int value = 0; 1077 int value = 0;
1165 for (int i = 0; i < entries.length(); i++) 1078 for (int i = 0; i < entries.length(); i++)
1166 if (entries[i].line == hit_line) { 1079 if (entries[i].line == hit_line) {
1167 value = entries[i].hit_count; 1080 value = entries[i].hit_count;
1168 break; 1081 break;
1169 } 1082 }
1170 CHECK_EQ(hit_count, value); 1083 CHECK_EQ(hit_count, value);
1171 } 1084 }
1172 1085
1173 1086 static const char* call_function_test_source =
1174 static const char* call_function_test_source = "function bar(iterations) {\n" 1087 "%NeverOptimizeFunction(bar);\n"
1175 "}\n" 1088 "%NeverOptimizeFunction(start);\n"
1176 "function start(duration) {\n" 1089 "function bar(iterations) { }\n"
1177 " var start = Date.now();\n" 1090 "function start(duration) {\n"
1178 " while (Date.now() - start < duration) {\n" 1091 " var start = Date.now();\n"
1179 " try {\n" 1092 " do {\n"
1180 " bar.call(this, 10 * 1000);\n" 1093 " for (var i = 0; i < 100; ++i)\n"
1181 " } catch(e) {}\n" 1094 " bar.call(this, 10 * 1000);\n"
1182 " }\n" 1095 " } while (Date.now() - start < duration);\n"
1183 "}"; 1096 "}";
1184
1185 1097
1186 // Test that if we sampled thread when it was inside FunctionCall buitin then 1098 // Test that if we sampled thread when it was inside FunctionCall buitin then
1187 // its caller frame will be '(unresolved function)' as we have no reliable way 1099 // its caller frame will be '(unresolved function)' as we have no reliable way
1188 // to resolve it. 1100 // to resolve it.
1189 // 1101 //
1190 // [Top down]: 1102 // [Top down]:
1191 // 96 0 (root) [-1] #1 1103 // 96 0 (root) [-1] #1
1192 // 1 1 (garbage collector) [-1] #4 1104 // 1 1 (garbage collector) [-1] #4
1193 // 5 0 (unresolved function) [-1] #5 1105 // 5 0 (unresolved function) [-1] #5
1194 // 5 5 call [-1] #6 1106 // 5 5 call [-1] #6
1195 // 71 70 start [-1] #3 1107 // 71 70 start [-1] #3
1196 // 1 1 bar [-1] #7 1108 // 1 1 bar [-1] #7
1197 // 19 19 (program) [-1] #2 1109 // 19 19 (program) [-1] #2
1198 TEST(FunctionCallSample) { 1110 TEST(FunctionCallSample) {
1111 i::FLAG_allow_natives_syntax = true;
1199 LocalContext env; 1112 LocalContext env;
1200 v8::HandleScope scope(env->GetIsolate()); 1113 v8::HandleScope scope(env->GetIsolate());
1201 1114
1202 // Collect garbage that might have be generated while installing 1115 // Collect garbage that might have be generated while installing
1203 // extensions. 1116 // extensions.
1204 CcTest::heap()->CollectAllGarbage(); 1117 CcTest::heap()->CollectAllGarbage();
1205 1118
1206 CompileRun(call_function_test_source); 1119 CompileRun(call_function_test_source);
1207 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 1120 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
1208 1121
1209 int32_t duration_ms = 100; 1122 int32_t duration_ms = 100;
1210 v8::Local<v8::Value> args[] = { 1123 v8::Local<v8::Value> args[] = {
1211 v8::Integer::New(env->GetIsolate(), duration_ms)}; 1124 v8::Integer::New(env->GetIsolate(), duration_ms)};
1212 v8::CpuProfile* profile = 1125 v8::CpuProfile* profile =
1213 RunProfiler(env.local(), function, args, arraysize(args), 100); 1126 RunProfiler(env.local(), function, args, arraysize(args), 100);
1127 // Dump collected profile to have a better diagnostic in case of failure.
1128 reinterpret_cast<i::CpuProfile*>(profile)->Print();
yurys 2016/02/05 22:54:11 RunProfiler already does this. Please remove.
alph 2016/02/05 23:32:09 Done.
1214 1129
1215 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1130 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1216 { 1131 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
1217 ScopedVector<v8::Local<v8::String> > names(4); 1132 GetChild(env.local(), startNode, "bar");
1218 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1219 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1220 names[2] = v8_str("start");
1221 names[3] = v8_str(i::ProfileGenerator::kUnresolvedFunctionName);
1222 // Don't allow |bar| and |call| nodes to be at the top level.
1223 CheckChildrenNames(env.local(), root, names);
1224 }
1225
1226 // In case of GC stress tests all samples may be in GC phase and there
1227 // won't be |start| node in the profiles.
1228 bool is_gc_stress_testing =
1229 (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction;
1230 const v8::CpuProfileNode* startNode = FindChild(env.local(), root, "start");
1231 CHECK(is_gc_stress_testing || startNode);
1232 if (startNode) {
1233 ScopedVector<v8::Local<v8::String> > names(2);
1234 names[0] = v8_str("bar");
1235 names[1] = v8_str("call");
1236 CheckChildrenNames(env.local(), startNode, names);
1237 }
1238 1133
1239 const v8::CpuProfileNode* unresolvedNode = FindChild( 1134 const v8::CpuProfileNode* unresolvedNode = FindChild(
1240 env.local(), root, i::ProfileGenerator::kUnresolvedFunctionName); 1135 env.local(), root, i::ProfileGenerator::kUnresolvedFunctionName);
1241 if (unresolvedNode) { 1136 CHECK(!unresolvedNode || GetChild(env.local(), unresolvedNode, "call"));
1242 ScopedVector<v8::Local<v8::String> > names(1);
1243 names[0] = v8_str("call");
1244 CheckChildrenNames(env.local(), unresolvedNode, names);
1245 }
1246 1137
1247 profile->Delete(); 1138 profile->Delete();
1248 } 1139 }
1249 1140
1250
1251 static const char* function_apply_test_source = 1141 static const char* function_apply_test_source =
1252 "function bar(iterations) {\n" 1142 "%NeverOptimizeFunction(bar);\n"
1253 "}\n" 1143 "%NeverOptimizeFunction(test);\n"
1144 "%NeverOptimizeFunction(start);\n"
1145 "function bar(iterations) { }\n"
1254 "function test() {\n" 1146 "function test() {\n"
1255 " bar.apply(this, [10 * 1000]);\n" 1147 " bar.apply(this, [10 * 1000]);\n"
1256 "}\n" 1148 "}\n"
1257 "function start(duration) {\n" 1149 "function start(duration) {\n"
1258 " var start = Date.now();\n" 1150 " var start = Date.now();\n"
1259 " while (Date.now() - start < duration) {\n" 1151 " do {\n"
1260 " try {\n" 1152 " for (var i = 0; i < 100; ++i) test();\n"
1261 " test();\n" 1153 " } while (Date.now() - start < duration);\n"
1262 " } catch(e) {}\n"
1263 " }\n"
1264 "}"; 1154 "}";
1265 1155
1266
1267 // [Top down]: 1156 // [Top down]:
1268 // 94 0 (root) [-1] #0 1 1157 // 94 0 (root) [-1] #0 1
1269 // 2 2 (garbage collector) [-1] #0 7 1158 // 2 2 (garbage collector) [-1] #0 7
1270 // 82 49 start [-1] #16 3 1159 // 82 49 start [-1] #16 3
1271 // 1 0 (unresolved function) [-1] #0 8 1160 // 1 0 (unresolved function) [-1] #0 8
1272 // 1 1 apply [-1] #0 9 1161 // 1 1 apply [-1] #0 9
1273 // 32 21 test [-1] #16 4 1162 // 32 21 test [-1] #16 4
1274 // 2 2 bar [-1] #16 6 1163 // 2 2 bar [-1] #16 6
1275 // 9 9 apply [-1] #0 5
1276 // 10 10 (program) [-1] #0 2 1164 // 10 10 (program) [-1] #0 2
1277 TEST(FunctionApplySample) { 1165 TEST(FunctionApplySample) {
1166 i::FLAG_allow_natives_syntax = true;
1278 LocalContext env; 1167 LocalContext env;
1279 v8::HandleScope scope(env->GetIsolate()); 1168 v8::HandleScope scope(env->GetIsolate());
1280 1169
1281 CompileRun(function_apply_test_source); 1170 CompileRun(function_apply_test_source);
1282 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 1171 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
1283 1172
1284 int32_t duration_ms = 100; 1173 int32_t duration_ms = 100;
1285 v8::Local<v8::Value> args[] = { 1174 v8::Local<v8::Value> args[] = {
1286 v8::Integer::New(env->GetIsolate(), duration_ms)}; 1175 v8::Integer::New(env->GetIsolate(), duration_ms)};
1287 1176
1288 v8::CpuProfile* profile = 1177 v8::CpuProfile* profile =
1289 RunProfiler(env.local(), function, args, arraysize(args), 100); 1178 RunProfiler(env.local(), function, args, arraysize(args), 1000);
1179 // Dump collected profile to have a better diagnostic in case of failure.
1180 reinterpret_cast<i::CpuProfile*>(profile)->Print();
yurys 2016/02/05 22:54:11 Ditto.
alph 2016/02/05 23:32:09 Done.
1290 1181
1291 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1182 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1292 { 1183 const v8::CpuProfileNode* startNode = GetChild(env.local(), root, "start");
yurys 2016/02/05 22:54:11 style nit: here and in other places start_node ins
alph 2016/02/05 23:32:09 Done.
1293 ScopedVector<v8::Local<v8::String> > names(3); 1184 const v8::CpuProfileNode* testNode = GetChild(env.local(), startNode, "test");
1294 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName); 1185 GetChild(env.local(), testNode, "bar");
1295 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1296 names[2] = v8_str("start");
1297 // Don't allow |test|, |bar| and |apply| nodes to be at the top level.
1298 CheckChildrenNames(env.local(), root, names);
1299 }
1300 1186
1301 const v8::CpuProfileNode* startNode = FindChild(env.local(), root, "start"); 1187 const v8::CpuProfileNode* unresolvedNode = FindChild(
1302 if (startNode) { 1188 env.local(), startNode, ProfileGenerator::kUnresolvedFunctionName);
1303 { 1189 CHECK(!unresolvedNode || GetChild(env.local(), unresolvedNode, "apply"));
1304 ScopedVector<v8::Local<v8::String> > names(2);
1305 names[0] = v8_str("test");
1306 names[1] = v8_str(ProfileGenerator::kUnresolvedFunctionName);
1307 CheckChildrenNames(env.local(), startNode, names);
1308 }
1309
1310 const v8::CpuProfileNode* testNode =
1311 FindChild(env.local(), startNode, "test");
1312 if (testNode) {
1313 ScopedVector<v8::Local<v8::String> > names(3);
1314 names[0] = v8_str("bar");
1315 names[1] = v8_str("apply");
1316 // apply calls "get length" before invoking the function itself
1317 // and we may get hit into it.
1318 names[2] = v8_str("get length");
1319 CheckChildrenNames(env.local(), testNode, names);
1320 }
1321
1322 if (const v8::CpuProfileNode* unresolvedNode =
1323 FindChild(env.local(), startNode,
1324 ProfileGenerator::kUnresolvedFunctionName)) {
1325 ScopedVector<v8::Local<v8::String> > names(1);
1326 names[0] = v8_str("apply");
1327 CheckChildrenNames(env.local(), unresolvedNode, names);
1328 GetChild(env.local(), unresolvedNode, "apply");
1329 }
1330 }
1331 1190
1332 profile->Delete(); 1191 profile->Delete();
1333 } 1192 }
1334 1193
1335
1336 static const char* cpu_profiler_deep_stack_test_source = 1194 static const char* cpu_profiler_deep_stack_test_source =
1337 "function foo(n) {\n" 1195 "function foo(n) {\n"
1338 " if (n)\n" 1196 " if (n)\n"
1339 " foo(n - 1);\n" 1197 " foo(n - 1);\n"
1340 " else\n" 1198 " else\n"
1341 " startProfiling('my_profile');\n" 1199 " collectSample();\n"
1342 "}\n" 1200 "}\n"
1343 "function start() {\n" 1201 "function start() {\n"
1344 " foo(250);\n" 1202 " startProfiling('my_profile');\n"
1345 "}\n"; 1203 " foo(250);\n"
1346 1204 "}\n";
1347 1205
1348 // Check a deep stack 1206 // Check a deep stack
1349 // 1207 //
1350 // [Top down]: 1208 // [Top down]:
1351 // 0 (root) 0 #1 1209 // 0 (root) 0 #1
1352 // 2 (program) 0 #2 1210 // 2 (program) 0 #2
1353 // 0 start 21 #3 no reason 1211 // 0 start 21 #3 no reason
1354 // 0 foo 21 #4 no reason 1212 // 0 foo 21 #4 no reason
1355 // 0 foo 21 #5 no reason 1213 // 0 foo 21 #5 no reason
1356 // .... 1214 // ....
1357 // 0 foo 21 #253 no reason 1215 // 0 foo 21 #254 no reason
1358 // 1 startProfiling 0 #254
1359 TEST(CpuProfileDeepStack) { 1216 TEST(CpuProfileDeepStack) {
1360 v8::HandleScope scope(CcTest::isolate()); 1217 v8::HandleScope scope(CcTest::isolate());
1361 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1218 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1362 v8::Context::Scope context_scope(env); 1219 v8::Context::Scope context_scope(env);
1363 1220
1364 CompileRun(cpu_profiler_deep_stack_test_source); 1221 CompileRun(cpu_profiler_deep_stack_test_source);
1365 v8::Local<v8::Function> function = GetFunction(env, "start"); 1222 v8::Local<v8::Function> function = GetFunction(env, "start");
1366 1223
1367 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1224 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1368 v8::Local<v8::String> profile_name = v8_str("my_profile"); 1225 v8::Local<v8::String> profile_name = v8_str("my_profile");
1369 function->Call(env, env->Global(), 0, NULL).ToLocalChecked(); 1226 function->Call(env, env->Global(), 0, NULL).ToLocalChecked();
1370 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 1227 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
1371 CHECK(profile); 1228 CHECK(profile);
1372 // Dump collected profile to have a better diagnostic in case of failure. 1229 // Dump collected profile to have a better diagnostic in case of failure.
1373 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 1230 reinterpret_cast<i::CpuProfile*>(profile)->Print();
1374 1231
1375 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1232 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1376 {
1377 ScopedVector<v8::Local<v8::String> > names(3);
1378 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1379 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1380 names[2] = v8_str("start");
1381 CheckChildrenNames(env, root, names);
1382 }
1383
1384 const v8::CpuProfileNode* node = GetChild(env, root, "start"); 1233 const v8::CpuProfileNode* node = GetChild(env, root, "start");
1385 for (int i = 0; i < 250; ++i) { 1234 for (int i = 0; i <= 250; ++i) {
1386 node = GetChild(env, node, "foo"); 1235 node = GetChild(env, node, "foo");
1387 } 1236 }
1388 // TODO(alph): 1237 CHECK(!FindChild(env, node, "foo"));
1389 // In theory there must be one more 'foo' and a 'startProfiling' nodes,
1390 // but due to unstable top frame extraction these might be missing.
1391 1238
1392 profile->Delete(); 1239 profile->Delete();
1393 } 1240 }
1394 1241
1395 1242
1396 static const char* js_native_js_test_source = 1243 static const char* js_native_js_test_source =
1397 "function foo() {\n" 1244 "function foo() {\n"
1398 " startProfiling('my_profile');\n" 1245 " startProfiling('my_profile');\n"
1399 "}\n" 1246 "}\n"
1400 "function bar() {\n" 1247 "function bar() {\n"
1401 " try { foo(); } catch(e) {}\n" 1248 " try { foo(); } catch(e) {}\n"
1402 "}\n" 1249 "}\n"
1403 "function start() {\n" 1250 "function start() {\n"
1404 " try {\n" 1251 " try {\n"
1405 " CallJsFunction(bar);\n" 1252 " CallJsFunction(bar);\n"
1406 " } catch(e) {}\n" 1253 " } catch(e) {}\n"
1407 "}"; 1254 "}";
1408 1255
1409 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) { 1256 static void CallJsFunction(const v8::FunctionCallbackInfo<v8::Value>& info) {
1410 v8::Local<v8::Function> function = info[0].As<v8::Function>(); 1257 v8::Local<v8::Function> function = info[0].As<v8::Function>();
1411 v8::Local<v8::Value> argv[] = {info[1]}; 1258 v8::Local<v8::Value> argv[] = {info[1]};
1412 function->Call(info.GetIsolate()->GetCurrentContext(), info.This(), 1259 function->Call(info.GetIsolate()->GetCurrentContext(), info.This(),
1413 arraysize(argv), argv) 1260 arraysize(argv), argv)
1414 .ToLocalChecked(); 1261 .ToLocalChecked();
1415 } 1262 }
1416 1263
1417
1418 // [Top down]: 1264 // [Top down]:
1419 // 58 0 (root) #0 1 1265 // 58 0 (root) #0 1
1420 // 2 2 (program) #0 2 1266 // 2 2 (program) #0 2
1421 // 56 1 start #16 3 1267 // 56 1 start #16 3
1422 // 55 0 CallJsFunction #0 4 1268 // 55 0 CallJsFunction #0 4
1423 // 55 1 bar #16 5 1269 // 55 1 bar #16 5
1424 // 54 54 foo #16 6 1270 // 54 54 foo #16 6
1425 TEST(JsNativeJsSample) { 1271 TEST(JsNativeJsSample) {
1426 v8::HandleScope scope(CcTest::isolate()); 1272 v8::HandleScope scope(CcTest::isolate());
1427 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1273 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1428 v8::Context::Scope context_scope(env); 1274 v8::Context::Scope context_scope(env);
1429 1275
1430 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1276 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1431 env->GetIsolate(), CallJsFunction); 1277 env->GetIsolate(), CallJsFunction);
1432 v8::Local<v8::Function> func = 1278 v8::Local<v8::Function> func =
1433 func_template->GetFunction(env).ToLocalChecked(); 1279 func_template->GetFunction(env).ToLocalChecked();
1434 func->SetName(v8_str("CallJsFunction")); 1280 func->SetName(v8_str("CallJsFunction"));
1435 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); 1281 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust();
1436 1282
1437 CompileRun(js_native_js_test_source); 1283 CompileRun(js_native_js_test_source);
1438 v8::Local<v8::Function> function = GetFunction(env, "start"); 1284 v8::Local<v8::Function> function = GetFunction(env, "start");
1439 1285
1440 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); 1286 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1441 1287
1442 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1288 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1443 {
1444 ScopedVector<v8::Local<v8::String> > names(3);
1445 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1446 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1447 names[2] = v8_str("start");
1448 CheckChildrenNames(env, root, names);
1449 }
1450
1451 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); 1289 const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
1452 CHECK_EQ(1, startNode->GetChildrenCount());
1453 const v8::CpuProfileNode* nativeFunctionNode = 1290 const v8::CpuProfileNode* nativeFunctionNode =
1454 GetChild(env, startNode, "CallJsFunction"); 1291 GetChild(env, startNode, "CallJsFunction");
1455
1456 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
1457 const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar"); 1292 const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar");
1458
1459 CHECK_EQ(1, barNode->GetChildrenCount());
1460 GetChild(env, barNode, "foo"); 1293 GetChild(env, barNode, "foo");
1461 1294
1462 profile->Delete(); 1295 profile->Delete();
1463 } 1296 }
1464 1297
1465
1466 static const char* js_native_js_runtime_js_test_source = 1298 static const char* js_native_js_runtime_js_test_source =
1467 "function foo() {\n" 1299 "function foo() {\n"
1468 " startProfiling('my_profile');\n" 1300 " startProfiling('my_profile');\n"
1469 "}\n" 1301 "}\n"
1470 "var bound = foo.bind(this);\n" 1302 "var bound = foo.bind(this);\n"
1471 "function bar() {\n" 1303 "function bar() {\n"
1472 " try { bound(); } catch(e) {}\n" 1304 " try { bound(); } catch(e) {}\n"
1473 "}\n" 1305 "}\n"
1474 "function start() {\n" 1306 "function start() {\n"
1475 " try {\n" 1307 " try {\n"
1476 " CallJsFunction(bar);\n" 1308 " CallJsFunction(bar);\n"
1477 " } catch(e) {}\n" 1309 " } catch(e) {}\n"
1478 "}"; 1310 "}";
1479 1311
1480
1481 // [Top down]: 1312 // [Top down]:
1482 // 57 0 (root) #0 1 1313 // 57 0 (root) #0 1
1483 // 55 1 start #16 3 1314 // 55 1 start #16 3
1484 // 54 0 CallJsFunction #0 4 1315 // 54 0 CallJsFunction #0 4
1485 // 54 3 bar #16 5 1316 // 54 3 bar #16 5
1486 // 51 51 foo #16 6 1317 // 51 51 foo #16 6
1487 // 2 2 (program) #0 2 1318 // 2 2 (program) #0 2
1488 TEST(JsNativeJsRuntimeJsSample) { 1319 TEST(JsNativeJsRuntimeJsSample) {
1489 v8::HandleScope scope(CcTest::isolate()); 1320 v8::HandleScope scope(CcTest::isolate());
1490 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1321 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1491 v8::Context::Scope context_scope(env); 1322 v8::Context::Scope context_scope(env);
1492 1323
1493 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1324 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1494 env->GetIsolate(), CallJsFunction); 1325 env->GetIsolate(), CallJsFunction);
1495 v8::Local<v8::Function> func = 1326 v8::Local<v8::Function> func =
1496 func_template->GetFunction(env).ToLocalChecked(); 1327 func_template->GetFunction(env).ToLocalChecked();
1497 func->SetName(v8_str("CallJsFunction")); 1328 func->SetName(v8_str("CallJsFunction"));
1498 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); 1329 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust();
1499 1330
1500 CompileRun(js_native_js_runtime_js_test_source); 1331 CompileRun(js_native_js_runtime_js_test_source);
1501 v8::Local<v8::Function> function = GetFunction(env, "start"); 1332 v8::Local<v8::Function> function = GetFunction(env, "start");
1502
1503 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); 1333 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1504 1334
1505 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1335 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1506 ScopedVector<v8::Local<v8::String> > names(3);
1507 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1508 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1509 names[2] = v8_str("start");
1510 CheckChildrenNames(env, root, names);
1511
1512 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); 1336 const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
1513 CHECK_EQ(1, startNode->GetChildrenCount());
1514 const v8::CpuProfileNode* nativeFunctionNode = 1337 const v8::CpuProfileNode* nativeFunctionNode =
1515 GetChild(env, startNode, "CallJsFunction"); 1338 GetChild(env, startNode, "CallJsFunction");
1516
1517 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount());
1518 const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar"); 1339 const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar");
1519
1520 // The child is in fact a bound foo.
1521 // A bound function has a wrapper that may make calls to
1522 // other functions e.g. "get length".
1523 CHECK_LE(1, barNode->GetChildrenCount());
1524 CHECK_GE(2, barNode->GetChildrenCount());
1525 GetChild(env, barNode, "foo"); 1340 GetChild(env, barNode, "foo");
1526 1341
1527 profile->Delete(); 1342 profile->Delete();
1528 } 1343 }
1529 1344
1530
1531 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { 1345 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) {
1532 v8::base::OS::Print("In CallJsFunction2\n"); 1346 v8::base::OS::Print("In CallJsFunction2\n");
1533 CallJsFunction(info); 1347 CallJsFunction(info);
1534 } 1348 }
1535 1349
1536
1537 static const char* js_native1_js_native2_js_test_source = 1350 static const char* js_native1_js_native2_js_test_source =
1538 "function foo() {\n" 1351 "function foo() {\n"
1539 " try {\n" 1352 " try {\n"
1540 " startProfiling('my_profile');\n" 1353 " collectSample();\n"
1541 " } catch(e) {}\n" 1354 " } catch(e) {}\n"
1542 "}\n" 1355 "}\n"
1543 "function bar() {\n" 1356 "function bar() {\n"
1544 " CallJsFunction2(foo);\n" 1357 " CallJsFunction2(foo);\n"
1545 "}\n" 1358 "}\n"
1546 "function start() {\n" 1359 "function start() {\n"
1547 " try {\n" 1360 " try {\n"
1548 " CallJsFunction1(bar);\n" 1361 " CallJsFunction1(bar);\n"
1549 " } catch(e) {}\n" 1362 " } catch(e) {}\n"
1550 "}"; 1363 "}";
1551 1364
1552
1553 // [Top down]: 1365 // [Top down]:
1554 // 57 0 (root) #0 1 1366 // 57 0 (root) #0 1
1555 // 55 1 start #16 3 1367 // 55 1 start #16 3
1556 // 54 0 CallJsFunction1 #0 4 1368 // 54 0 CallJsFunction1 #0 4
1557 // 54 0 bar #16 5 1369 // 54 0 bar #16 5
1558 // 54 0 CallJsFunction2 #0 6 1370 // 54 0 CallJsFunction2 #0 6
1559 // 54 54 foo #16 7 1371 // 54 54 foo #16 7
1560 // 2 2 (program) #0 2 1372 // 2 2 (program) #0 2
1561 TEST(JsNative1JsNative2JsSample) { 1373 TEST(JsNative1JsNative2JsSample) {
1562 v8::HandleScope scope(CcTest::isolate()); 1374 v8::HandleScope scope(CcTest::isolate());
1563 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1375 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1564 v8::Context::Scope context_scope(env); 1376 v8::Context::Scope context_scope(env);
1565 1377
1566 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1567 env->GetIsolate(), CallJsFunction);
1568 v8::Local<v8::Function> func1 = 1378 v8::Local<v8::Function> func1 =
1569 func_template->GetFunction(env).ToLocalChecked(); 1379 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction)
1380 ->GetFunction(env)
1381 .ToLocalChecked();
yurys 2016/02/05 22:54:11 Place on the previous line?
alph 2016/02/05 23:32:09 I can't. It's git cl format.
1570 func1->SetName(v8_str("CallJsFunction1")); 1382 func1->SetName(v8_str("CallJsFunction1"));
1571 env->Global()->Set(env, v8_str("CallJsFunction1"), func1).FromJust(); 1383 env->Global()->Set(env, v8_str("CallJsFunction1"), func1).FromJust();
1572 1384
1573 v8::Local<v8::Function> func2 = 1385 v8::Local<v8::Function> func2 =
1574 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction2) 1386 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction2)
1575 ->GetFunction(env) 1387 ->GetFunction(env)
1576 .ToLocalChecked(); 1388 .ToLocalChecked();
1577 func2->SetName(v8_str("CallJsFunction2")); 1389 func2->SetName(v8_str("CallJsFunction2"));
1578 env->Global()->Set(env, v8_str("CallJsFunction2"), func2).FromJust(); 1390 env->Global()->Set(env, v8_str("CallJsFunction2"), func2).FromJust();
1579 1391
1580 CompileRun(js_native1_js_native2_js_test_source); 1392 CompileRun(js_native1_js_native2_js_test_source);
1581 v8::Local<v8::Function> function = GetFunction(env, "start"); 1393 v8::Local<v8::Function> function = GetFunction(env, "start");
1582 1394
1583 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); 1395 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000);
yurys 2016/02/05 22:54:11 Why is it not enough to have a single sample here?
alph 2016/02/05 23:32:09 Because as you said it won't be a JS sample on top
1584 1396
1585 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1397 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1586 ScopedVector<v8::Local<v8::String> > names(3);
1587 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1588 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1589 names[2] = v8_str("start");
1590 CheckChildrenNames(env, root, names);
1591
1592 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); 1398 const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
1593 CHECK_EQ(1, startNode->GetChildrenCount());
1594 const v8::CpuProfileNode* nativeNode1 = 1399 const v8::CpuProfileNode* nativeNode1 =
1595 GetChild(env, startNode, "CallJsFunction1"); 1400 GetChild(env, startNode, "CallJsFunction1");
1596
1597 CHECK_EQ(1, nativeNode1->GetChildrenCount());
1598 const v8::CpuProfileNode* barNode = GetChild(env, nativeNode1, "bar"); 1401 const v8::CpuProfileNode* barNode = GetChild(env, nativeNode1, "bar");
1599
1600 CHECK_EQ(1, barNode->GetChildrenCount());
1601 const v8::CpuProfileNode* nativeNode2 = 1402 const v8::CpuProfileNode* nativeNode2 =
1602 GetChild(env, barNode, "CallJsFunction2"); 1403 GetChild(env, barNode, "CallJsFunction2");
1603
1604 CHECK_EQ(1, nativeNode2->GetChildrenCount());
1605 GetChild(env, nativeNode2, "foo"); 1404 GetChild(env, nativeNode2, "foo");
1606 1405
1607 profile->Delete(); 1406 profile->Delete();
1608 } 1407 }
1609 1408
1610 static const char* js_force_collect_sample_source = 1409 static const char* js_force_collect_sample_source =
1611 "function start() {\n" 1410 "function start() {\n"
1612 " CallCollectSample();\n" 1411 " CallCollectSample();\n"
1613 "}"; 1412 "}";
1614 1413
1615 TEST(CollectSampleAPI) { 1414 TEST(CollectSampleAPI) {
1616 v8::HandleScope scope(CcTest::isolate()); 1415 v8::HandleScope scope(CcTest::isolate());
1617 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1416 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1618 v8::Context::Scope context_scope(env); 1417 v8::Context::Scope context_scope(env);
1619 1418
1620 v8::Local<v8::FunctionTemplate> func_template = 1419 v8::Local<v8::FunctionTemplate> func_template =
1621 v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample); 1420 v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample);
1622 v8::Local<v8::Function> func = 1421 v8::Local<v8::Function> func =
1623 func_template->GetFunction(env).ToLocalChecked(); 1422 func_template->GetFunction(env).ToLocalChecked();
1624 func->SetName(v8_str("CallCollectSample")); 1423 func->SetName(v8_str("CallCollectSample"));
1625 env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust(); 1424 env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust();
1626 1425
1627 CompileRun(js_force_collect_sample_source); 1426 CompileRun(js_force_collect_sample_source);
1628 v8::Local<v8::Function> function = GetFunction(env, "start"); 1427 v8::Local<v8::Function> function = GetFunction(env, "start");
1629
1630 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); 1428 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0);
1631 1429
1632 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1430 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1633 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); 1431 const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
1634 CHECK_LE(1, startNode->GetChildrenCount()); 1432 CHECK_LE(1, startNode->GetChildrenCount());
1635 GetChild(env, startNode, "CallCollectSample"); 1433 GetChild(env, startNode, "CallCollectSample");
1636 1434
1637 profile->Delete(); 1435 profile->Delete();
1638 } 1436 }
1639 1437
1640 static const char* js_native_js_runtime_multiple_test_source = 1438 static const char* js_native_js_runtime_multiple_test_source =
1641 "function foo() {\n" 1439 "function foo() {\n"
1642 " CallCollectSample();"
1643 " return Math.sin(Math.random());\n" 1440 " return Math.sin(Math.random());\n"
1644 "}\n" 1441 "}\n"
1645 "var bound = foo.bind(this);\n" 1442 "var bound = foo.bind(this);\n"
1646 "function bar() {\n" 1443 "function bar() {\n"
1647 " try { return bound(); } catch(e) {}\n" 1444 " try { return bound(); } catch(e) {}\n"
1648 "}\n" 1445 "}\n"
1649 "function start() {\n" 1446 "function start() {\n"
1650 " try {\n" 1447 " try {\n"
1651 " startProfiling('my_profile');\n" 1448 " startProfiling('my_profile');\n"
1652 " var startTime = Date.now();\n" 1449 " var startTime = Date.now();\n"
1653 " do {\n" 1450 " do {\n"
1654 " CallJsFunction(bar);\n" 1451 " CallJsFunction(bar);\n"
1655 " } while (Date.now() - startTime < 200);\n" 1452 " } while (Date.now() - startTime < 200);\n"
1656 " } catch(e) {}\n" 1453 " } catch(e) {}\n"
1657 "}"; 1454 "}";
1658 1455
1659 // The test check multiple entrances/exits between JS and native code. 1456 // The test check multiple entrances/exits between JS and native code.
1660 // 1457 //
1661 // [Top down]: 1458 // [Top down]:
1662 // (root) #0 1 1459 // (root) #0 1
1663 // start #16 3 1460 // start #16 3
1664 // CallJsFunction #0 4 1461 // CallJsFunction #0 4
1665 // bar #16 5 1462 // bar #16 5
1666 // foo #16 6 1463 // foo #16 6
1667 // CallCollectSample
1668 // (program) #0 2 1464 // (program) #0 2
1669 TEST(JsNativeJsRuntimeJsSampleMultiple) { 1465 TEST(JsNativeJsRuntimeJsSampleMultiple) {
1670 v8::HandleScope scope(CcTest::isolate()); 1466 v8::HandleScope scope(CcTest::isolate());
1671 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1467 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1672 v8::Context::Scope context_scope(env); 1468 v8::Context::Scope context_scope(env);
1673 1469
1674 v8::Local<v8::FunctionTemplate> func_template = 1470 v8::Local<v8::FunctionTemplate> func_template =
1675 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction); 1471 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction);
1676 v8::Local<v8::Function> func = 1472 v8::Local<v8::Function> func =
1677 func_template->GetFunction(env).ToLocalChecked(); 1473 func_template->GetFunction(env).ToLocalChecked();
1678 func->SetName(v8_str("CallJsFunction")); 1474 func->SetName(v8_str("CallJsFunction"));
1679 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); 1475 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust();
1680 1476
1681 func_template =
1682 v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample);
1683 func = func_template->GetFunction(env).ToLocalChecked();
1684 func->SetName(v8_str("CallCollectSample"));
1685 env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust();
1686
1687 CompileRun(js_native_js_runtime_multiple_test_source); 1477 CompileRun(js_native_js_runtime_multiple_test_source);
1688 v8::Local<v8::Function> function = GetFunction(env, "start"); 1478 v8::Local<v8::Function> function = GetFunction(env, "start");
1689 1479
1690 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); 1480 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000);
1481 CHECK(profile);
1482 // Dump collected profile to have a better diagnostic in case of failure.
1483 reinterpret_cast<i::CpuProfile*>(profile)->Print();
yurys 2016/02/05 22:54:11 Please remove.
alph 2016/02/05 23:32:09 Done.
1691 1484
1692 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1485 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1693 const v8::CpuProfileNode* startNode = GetChild(env, root, "start"); 1486 const v8::CpuProfileNode* startNode = GetChild(env, root, "start");
1694 const v8::CpuProfileNode* nativeFunctionNode = 1487 const v8::CpuProfileNode* nativeFunctionNode =
1695 GetChild(env, startNode, "CallJsFunction"); 1488 GetChild(env, startNode, "CallJsFunction");
1696
1697 const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar"); 1489 const v8::CpuProfileNode* barNode = GetChild(env, nativeFunctionNode, "bar");
1698 const v8::CpuProfileNode* fooNode = GetChild(env, barNode, "foo"); 1490 GetChild(env, barNode, "foo");
1699 GetChild(env, fooNode, "CallCollectSample");
1700 1491
1701 profile->Delete(); 1492 profile->Delete();
1702 } 1493 }
1703 1494
1704 // [Top down]: 1495 // [Top down]:
1705 // 0 (root) #0 1 1496 // 0 (root) #0 1
1706 // 2 (program) #0 2 1497 // 2 (program) #0 2
1707 // 3 (idle) #0 3 1498 // 3 (idle) #0 3
1708 TEST(IdleTime) { 1499 TEST(IdleTime) {
1709 LocalContext env; 1500 LocalContext env;
1710 v8::HandleScope scope(env->GetIsolate()); 1501 v8::HandleScope scope(env->GetIsolate());
1711 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1502 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1712 1503
1713 v8::Local<v8::String> profile_name = v8_str("my_profile"); 1504 v8::Local<v8::String> profile_name = v8_str("my_profile");
1714 cpu_profiler->StartProfiling(profile_name); 1505 cpu_profiler->StartProfiling(profile_name);
1715 1506
1716 i::Isolate* isolate = CcTest::i_isolate(); 1507 i::Isolate* isolate = CcTest::i_isolate();
1717 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); 1508 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor();
1509
1718 processor->AddCurrentStack(isolate, true); 1510 processor->AddCurrentStack(isolate, true);
1719
1720 cpu_profiler->SetIdle(true); 1511 cpu_profiler->SetIdle(true);
1721
1722 for (int i = 0; i < 3; i++) { 1512 for (int i = 0; i < 3; i++) {
1723 processor->AddCurrentStack(isolate, true); 1513 processor->AddCurrentStack(isolate, true);
1724 } 1514 }
1725
1726 cpu_profiler->SetIdle(false); 1515 cpu_profiler->SetIdle(false);
1727 processor->AddCurrentStack(isolate, true); 1516 processor->AddCurrentStack(isolate, true);
1728 1517
1729 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 1518 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
1730 CHECK(profile); 1519 CHECK(profile);
1731 // Dump collected profile to have a better diagnostic in case of failure. 1520 // Dump collected profile to have a better diagnostic in case of failure.
1732 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 1521 reinterpret_cast<i::CpuProfile*>(profile)->Print();
1733 1522
1734 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1523 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1735 ScopedVector<v8::Local<v8::String> > names(3);
1736 names[0] = v8_str(ProfileGenerator::kGarbageCollectorEntryName);
1737 names[1] = v8_str(ProfileGenerator::kProgramEntryName);
1738 names[2] = v8_str(ProfileGenerator::kIdleEntryName);
1739 CheckChildrenNames(env.local(), root, names);
1740
1741 const v8::CpuProfileNode* programNode = 1524 const v8::CpuProfileNode* programNode =
1742 GetChild(env.local(), root, ProfileGenerator::kProgramEntryName); 1525 GetChild(env.local(), root, ProfileGenerator::kProgramEntryName);
1743 CHECK_EQ(0, programNode->GetChildrenCount()); 1526 CHECK_EQ(0, programNode->GetChildrenCount());
1744 CHECK_GE(programNode->GetHitCount(), 2u); 1527 CHECK_GE(programNode->GetHitCount(), 2u);
1745 1528
1746 const v8::CpuProfileNode* idleNode = 1529 const v8::CpuProfileNode* idleNode =
1747 GetChild(env.local(), root, ProfileGenerator::kIdleEntryName); 1530 GetChild(env.local(), root, ProfileGenerator::kIdleEntryName);
1748 CHECK_EQ(0, idleNode->GetChildrenCount()); 1531 CHECK_EQ(0, idleNode->GetChildrenCount());
1749 CHECK_GE(idleNode->GetHitCount(), 3u); 1532 CHECK_GE(idleNode->GetHitCount(), 3u);
1750 1533
1751 profile->Delete(); 1534 profile->Delete();
1752 } 1535 }
1753 1536
1754
1755 static void CheckFunctionDetails(v8::Isolate* isolate, 1537 static void CheckFunctionDetails(v8::Isolate* isolate,
1756 const v8::CpuProfileNode* node, 1538 const v8::CpuProfileNode* node,
1757 const char* name, const char* script_name, 1539 const char* name, const char* script_name,
1758 int script_id, int line, int column) { 1540 int script_id, int line, int column) {
1759 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 1541 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1760 CHECK(v8_str(name)->Equals(context, node->GetFunctionName()).FromJust()); 1542 CHECK(v8_str(name)->Equals(context, node->GetFunctionName()).FromJust());
1761 CHECK(v8_str(script_name) 1543 CHECK(v8_str(script_name)
1762 ->Equals(context, node->GetScriptResourceName()) 1544 ->Equals(context, node->GetScriptResourceName())
1763 .FromJust()); 1545 .FromJust());
1764 CHECK_EQ(script_id, node->GetScriptId()); 1546 CHECK_EQ(script_id, node->GetScriptId());
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 iprofile->Print(); 1946 iprofile->Print();
2165 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 1947 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
2166 1948
2167 const char* branch[] = {"", "test"}; 1949 const char* branch[] = {"", "test"};
2168 const ProfileNode* itest_node = 1950 const ProfileNode* itest_node =
2169 GetSimpleBranch(env, profile, branch, arraysize(branch)); 1951 GetSimpleBranch(env, profile, branch, arraysize(branch));
2170 CHECK_EQ(0U, itest_node->deopt_infos().size()); 1952 CHECK_EQ(0U, itest_node->deopt_infos().size());
2171 1953
2172 iprofiler->DeleteProfile(iprofile); 1954 iprofiler->DeleteProfile(iprofile);
2173 } 1955 }
OLDNEW
« no previous file with comments | « test/cctest/profiler-extension.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698