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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 348 |
349 | 349 |
350 TEST(DeleteCpuProfile) { | 350 TEST(DeleteCpuProfile) { |
351 LocalContext env; | 351 LocalContext env; |
352 v8::HandleScope scope(env->GetIsolate()); | 352 v8::HandleScope scope(env->GetIsolate()); |
353 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 353 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
354 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler); | 354 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler); |
355 | 355 |
356 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 356 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
357 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1"); | 357 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1"); |
358 cpu_profiler->StartCpuProfiling(name1); | 358 cpu_profiler->StartProfiling(name1); |
359 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); | 359 v8::CpuProfile* p1 = cpu_profiler->StopProfiling(name1); |
360 CHECK_NE(NULL, p1); | 360 CHECK_NE(NULL, p1); |
361 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 361 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
362 CHECK(FindCpuProfile(cpu_profiler, p1)); | 362 CHECK(FindCpuProfile(cpu_profiler, p1)); |
363 const_cast<v8::CpuProfile*>(p1)->Delete(); | 363 p1->Delete(); |
364 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 364 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
365 | 365 |
366 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2"); | 366 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2"); |
367 cpu_profiler->StartCpuProfiling(name2); | 367 cpu_profiler->StartProfiling(name2); |
368 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2); | 368 v8::CpuProfile* p2 = cpu_profiler->StopProfiling(name2); |
369 CHECK_NE(NULL, p2); | 369 CHECK_NE(NULL, p2); |
370 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 370 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
371 CHECK(FindCpuProfile(cpu_profiler, p2)); | 371 CHECK(FindCpuProfile(cpu_profiler, p2)); |
372 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3"); | 372 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3"); |
373 cpu_profiler->StartCpuProfiling(name3); | 373 cpu_profiler->StartProfiling(name3); |
374 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); | 374 v8::CpuProfile* p3 = cpu_profiler->StopProfiling(name3); |
375 CHECK_NE(NULL, p3); | 375 CHECK_NE(NULL, p3); |
376 CHECK_EQ(2, iprofiler->GetProfilesCount()); | 376 CHECK_EQ(2, iprofiler->GetProfilesCount()); |
377 CHECK_NE(p2, p3); | 377 CHECK_NE(p2, p3); |
378 CHECK(FindCpuProfile(cpu_profiler, p3)); | 378 CHECK(FindCpuProfile(cpu_profiler, p3)); |
379 CHECK(FindCpuProfile(cpu_profiler, p2)); | 379 CHECK(FindCpuProfile(cpu_profiler, p2)); |
380 const_cast<v8::CpuProfile*>(p2)->Delete(); | 380 p2->Delete(); |
381 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 381 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
382 CHECK(!FindCpuProfile(cpu_profiler, p2)); | 382 CHECK(!FindCpuProfile(cpu_profiler, p2)); |
383 CHECK(FindCpuProfile(cpu_profiler, p3)); | 383 CHECK(FindCpuProfile(cpu_profiler, p3)); |
384 const_cast<v8::CpuProfile*>(p3)->Delete(); | 384 p3->Delete(); |
385 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 385 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
386 } | 386 } |
387 | 387 |
388 | 388 |
389 TEST(ProfileStartEndTime) { | 389 TEST(ProfileStartEndTime) { |
390 LocalContext env; | 390 LocalContext env; |
391 v8::HandleScope scope(env->GetIsolate()); | 391 v8::HandleScope scope(env->GetIsolate()); |
392 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 392 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
393 | 393 |
394 v8::Local<v8::String> profile_name = | 394 v8::Local<v8::String> profile_name = |
395 v8::String::NewFromUtf8(env->GetIsolate(), "test"); | 395 v8::String::NewFromUtf8(env->GetIsolate(), "test"); |
396 cpu_profiler->StartCpuProfiling(profile_name); | 396 cpu_profiler->StartProfiling(profile_name); |
397 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 397 const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
398 CHECK(profile->GetStartTime() <= profile->GetEndTime()); | 398 CHECK(profile->GetStartTime() <= profile->GetEndTime()); |
399 } | 399 } |
400 | 400 |
401 | 401 |
402 static const v8::CpuProfile* RunProfiler( | 402 static v8::CpuProfile* RunProfiler( |
403 v8::Handle<v8::Context> env, v8::Handle<v8::Function> function, | 403 v8::Handle<v8::Context> env, v8::Handle<v8::Function> function, |
404 v8::Handle<v8::Value> argv[], int argc, | 404 v8::Handle<v8::Value> argv[], int argc, |
405 unsigned min_js_samples) { | 405 unsigned min_js_samples) { |
406 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 406 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
407 v8::Local<v8::String> profile_name = | 407 v8::Local<v8::String> profile_name = |
408 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); | 408 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
409 | 409 |
410 cpu_profiler->StartCpuProfiling(profile_name); | 410 cpu_profiler->StartProfiling(profile_name); |
411 | 411 |
412 i::Sampler* sampler = | 412 i::Sampler* sampler = |
413 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); | 413 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); |
414 sampler->StartCountingSamples(); | 414 sampler->StartCountingSamples(); |
415 do { | 415 do { |
416 function->Call(env->Global(), argc, argv); | 416 function->Call(env->Global(), argc, argv); |
417 } while (sampler->js_and_external_sample_count() < min_js_samples); | 417 } while (sampler->js_and_external_sample_count() < min_js_samples); |
418 | 418 |
419 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 419 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
420 | 420 |
421 CHECK_NE(NULL, profile); | 421 CHECK_NE(NULL, profile); |
422 // Dump collected profile to have a better diagnostic in case of failure. | 422 // Dump collected profile to have a better diagnostic in case of failure. |
423 reinterpret_cast<i::CpuProfile*>( | 423 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
424 const_cast<v8::CpuProfile*>(profile))->Print(); | |
425 | 424 |
426 return profile; | 425 return profile; |
427 } | 426 } |
428 | 427 |
429 | 428 |
430 static bool ContainsString(v8::Handle<v8::String> string, | 429 static bool ContainsString(v8::Handle<v8::String> string, |
431 const Vector<v8::Handle<v8::String> >& vector) { | 430 const Vector<v8::Handle<v8::String> >& vector) { |
432 for (int i = 0; i < vector.length(); i++) { | 431 for (int i = 0; i < vector.length(); i++) { |
433 if (string->Equals(vector[i])) | 432 if (string->Equals(vector[i])) |
434 return true; | 433 return true; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 | 545 |
547 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 546 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
548 cpu_profiler_test_source))->Run(); | 547 cpu_profiler_test_source))->Run(); |
549 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 548 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
550 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 549 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
551 | 550 |
552 int32_t profiling_interval_ms = 200; | 551 int32_t profiling_interval_ms = 200; |
553 v8::Handle<v8::Value> args[] = { | 552 v8::Handle<v8::Value> args[] = { |
554 v8::Integer::New(env->GetIsolate(), profiling_interval_ms) | 553 v8::Integer::New(env->GetIsolate(), profiling_interval_ms) |
555 }; | 554 }; |
556 const v8::CpuProfile* profile = | 555 v8::CpuProfile* profile = |
557 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200); | 556 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200); |
558 function->Call(env->Global(), ARRAY_SIZE(args), args); | 557 function->Call(env->Global(), ARRAY_SIZE(args), args); |
559 | 558 |
560 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 559 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
561 | 560 |
562 ScopedVector<v8::Handle<v8::String> > names(3); | 561 ScopedVector<v8::Handle<v8::String> > names(3); |
563 names[0] = v8::String::NewFromUtf8( | 562 names[0] = v8::String::NewFromUtf8( |
564 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 563 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
565 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 564 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
566 ProfileGenerator::kProgramEntryName); | 565 ProfileGenerator::kProgramEntryName); |
(...skipping 11 matching lines...) Expand all Loading... |
578 const char* barBranch[] = { "bar", "delay", "loop" }; | 577 const char* barBranch[] = { "bar", "delay", "loop" }; |
579 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, | 578 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, |
580 ARRAY_SIZE(barBranch)); | 579 ARRAY_SIZE(barBranch)); |
581 const char* bazBranch[] = { "baz", "delay", "loop" }; | 580 const char* bazBranch[] = { "baz", "delay", "loop" }; |
582 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, | 581 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, |
583 ARRAY_SIZE(bazBranch)); | 582 ARRAY_SIZE(bazBranch)); |
584 const char* delayBranch[] = { "delay", "loop" }; | 583 const char* delayBranch[] = { "delay", "loop" }; |
585 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, | 584 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, |
586 ARRAY_SIZE(delayBranch)); | 585 ARRAY_SIZE(delayBranch)); |
587 | 586 |
588 const_cast<v8::CpuProfile*>(profile)->Delete(); | 587 profile->Delete(); |
589 } | 588 } |
590 | 589 |
591 | 590 |
592 | 591 |
593 static const char* cpu_profiler_test_source2 = "function loop() {}\n" | 592 static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
594 "function delay() { loop(); }\n" | 593 "function delay() { loop(); }\n" |
595 "function start(count) {\n" | 594 "function start(count) {\n" |
596 " var k = 0;\n" | 595 " var k = 0;\n" |
597 " do {\n" | 596 " do {\n" |
598 " delay();\n" | 597 " delay();\n" |
(...skipping 21 matching lines...) Expand all Loading... |
620 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 619 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
621 | 620 |
622 int32_t repeat_count = 100; | 621 int32_t repeat_count = 100; |
623 #if defined(USE_SIMULATOR) | 622 #if defined(USE_SIMULATOR) |
624 // Simulators are much slower. | 623 // Simulators are much slower. |
625 repeat_count = 1; | 624 repeat_count = 1; |
626 #endif | 625 #endif |
627 v8::Handle<v8::Value> args[] = { | 626 v8::Handle<v8::Value> args[] = { |
628 v8::Integer::New(env->GetIsolate(), repeat_count) | 627 v8::Integer::New(env->GetIsolate(), repeat_count) |
629 }; | 628 }; |
630 const v8::CpuProfile* profile = | 629 v8::CpuProfile* profile = |
631 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | 630 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
632 | 631 |
633 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 632 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
634 | 633 |
635 ScopedVector<v8::Handle<v8::String> > names(3); | 634 ScopedVector<v8::Handle<v8::String> > names(3); |
636 names[0] = v8::String::NewFromUtf8( | 635 names[0] = v8::String::NewFromUtf8( |
637 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 636 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
638 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 637 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
639 ProfileGenerator::kProgramEntryName); | 638 ProfileGenerator::kProgramEntryName); |
640 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 639 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
641 CheckChildrenNames(root, names); | 640 CheckChildrenNames(root, names); |
642 | 641 |
643 const v8::CpuProfileNode* startNode = | 642 const v8::CpuProfileNode* startNode = |
644 FindChild(env->GetIsolate(), root, "start"); | 643 FindChild(env->GetIsolate(), root, "start"); |
645 // On slow machines there may be no meaningfull samples at all, skip the | 644 // On slow machines there may be no meaningfull samples at all, skip the |
646 // check there. | 645 // check there. |
647 if (startNode && startNode->GetChildrenCount() > 0) { | 646 if (startNode && startNode->GetChildrenCount() > 0) { |
648 CHECK_EQ(1, startNode->GetChildrenCount()); | 647 CHECK_EQ(1, startNode->GetChildrenCount()); |
649 const v8::CpuProfileNode* delayNode = | 648 const v8::CpuProfileNode* delayNode = |
650 GetChild(env->GetIsolate(), startNode, "delay"); | 649 GetChild(env->GetIsolate(), startNode, "delay"); |
651 if (delayNode->GetChildrenCount() > 0) { | 650 if (delayNode->GetChildrenCount() > 0) { |
652 CHECK_EQ(1, delayNode->GetChildrenCount()); | 651 CHECK_EQ(1, delayNode->GetChildrenCount()); |
653 GetChild(env->GetIsolate(), delayNode, "loop"); | 652 GetChild(env->GetIsolate(), delayNode, "loop"); |
654 } | 653 } |
655 } | 654 } |
656 | 655 |
657 const_cast<v8::CpuProfile*>(profile)->Delete(); | 656 profile->Delete(); |
658 } | 657 } |
659 | 658 |
660 | 659 |
661 static const char* native_accessor_test_source = "function start(count) {\n" | 660 static const char* native_accessor_test_source = "function start(count) {\n" |
662 " for (var i = 0; i < count; i++) {\n" | 661 " for (var i = 0; i < count; i++) {\n" |
663 " var o = instance.foo;\n" | 662 " var o = instance.foo;\n" |
664 " instance.foo = o + 1;\n" | 663 " instance.foo = o + 1;\n" |
665 " }\n" | 664 " }\n" |
666 "}\n"; | 665 "}\n"; |
667 | 666 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 instance); | 739 instance); |
741 | 740 |
742 v8::Script::Compile( | 741 v8::Script::Compile( |
743 v8::String::NewFromUtf8(isolate, native_accessor_test_source)) | 742 v8::String::NewFromUtf8(isolate, native_accessor_test_source)) |
744 ->Run(); | 743 ->Run(); |
745 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 744 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
746 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); | 745 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); |
747 | 746 |
748 int32_t repeat_count = 1; | 747 int32_t repeat_count = 1; |
749 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 748 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
750 const v8::CpuProfile* profile = | 749 v8::CpuProfile* profile = |
751 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 180); | 750 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 180); |
752 | 751 |
753 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 752 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
754 const v8::CpuProfileNode* startNode = | 753 const v8::CpuProfileNode* startNode = |
755 GetChild(isolate, root, "start"); | 754 GetChild(isolate, root, "start"); |
756 GetChild(isolate, startNode, "get foo"); | 755 GetChild(isolate, startNode, "get foo"); |
757 GetChild(isolate, startNode, "set foo"); | 756 GetChild(isolate, startNode, "set foo"); |
758 | 757 |
759 const_cast<v8::CpuProfile*>(profile)->Delete(); | 758 profile->Delete(); |
760 } | 759 } |
761 | 760 |
762 | 761 |
763 // Test that native accessors are properly reported in the CPU profile. | 762 // Test that native accessors are properly reported in the CPU profile. |
764 // This test makes sure that the accessors are called enough times to become | 763 // This test makes sure that the accessors are called enough times to become |
765 // hot and to trigger optimizations. | 764 // hot and to trigger optimizations. |
766 TEST(NativeAccessorMonomorphicIC) { | 765 TEST(NativeAccessorMonomorphicIC) { |
767 LocalContext env; | 766 LocalContext env; |
768 v8::Isolate* isolate = env->GetIsolate(); | 767 v8::Isolate* isolate = env->GetIsolate(); |
769 v8::HandleScope scope(isolate); | 768 v8::HandleScope scope(isolate); |
(...skipping 27 matching lines...) Expand all Loading... |
797 int32_t warm_up_iterations = 3; | 796 int32_t warm_up_iterations = 3; |
798 v8::Handle<v8::Value> args[] = { | 797 v8::Handle<v8::Value> args[] = { |
799 v8::Integer::New(isolate, warm_up_iterations) | 798 v8::Integer::New(isolate, warm_up_iterations) |
800 }; | 799 }; |
801 function->Call(env->Global(), ARRAY_SIZE(args), args); | 800 function->Call(env->Global(), ARRAY_SIZE(args), args); |
802 accessors.set_warming_up(false); | 801 accessors.set_warming_up(false); |
803 } | 802 } |
804 | 803 |
805 int32_t repeat_count = 100; | 804 int32_t repeat_count = 100; |
806 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 805 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
807 const v8::CpuProfile* profile = | 806 v8::CpuProfile* profile = |
808 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200); | 807 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 200); |
809 | 808 |
810 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 809 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
811 const v8::CpuProfileNode* startNode = | 810 const v8::CpuProfileNode* startNode = |
812 GetChild(isolate, root, "start"); | 811 GetChild(isolate, root, "start"); |
813 GetChild(isolate, startNode, "get foo"); | 812 GetChild(isolate, startNode, "get foo"); |
814 GetChild(isolate, startNode, "set foo"); | 813 GetChild(isolate, startNode, "set foo"); |
815 | 814 |
816 const_cast<v8::CpuProfile*>(profile)->Delete(); | 815 profile->Delete(); |
817 } | 816 } |
818 | 817 |
819 | 818 |
820 static const char* native_method_test_source = "function start(count) {\n" | 819 static const char* native_method_test_source = "function start(count) {\n" |
821 " for (var i = 0; i < count; i++) {\n" | 820 " for (var i = 0; i < count; i++) {\n" |
822 " instance.fooMethod();\n" | 821 " instance.fooMethod();\n" |
823 " }\n" | 822 " }\n" |
824 "}\n"; | 823 "}\n"; |
825 | 824 |
826 | 825 |
(...skipping 24 matching lines...) Expand all Loading... |
851 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"), | 850 env->Global()->Set(v8::String::NewFromUtf8(isolate, "instance"), |
852 instance); | 851 instance); |
853 | 852 |
854 v8::Script::Compile(v8::String::NewFromUtf8( | 853 v8::Script::Compile(v8::String::NewFromUtf8( |
855 isolate, native_method_test_source))->Run(); | 854 isolate, native_method_test_source))->Run(); |
856 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 855 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
857 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); | 856 env->Global()->Get(v8::String::NewFromUtf8(isolate, "start"))); |
858 | 857 |
859 int32_t repeat_count = 1; | 858 int32_t repeat_count = 1; |
860 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 859 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
861 const v8::CpuProfile* profile = | 860 v8::CpuProfile* profile = |
862 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | 861 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
863 | 862 |
864 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 863 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
865 const v8::CpuProfileNode* startNode = | 864 const v8::CpuProfileNode* startNode = |
866 GetChild(isolate, root, "start"); | 865 GetChild(isolate, root, "start"); |
867 GetChild(isolate, startNode, "fooMethod"); | 866 GetChild(isolate, startNode, "fooMethod"); |
868 | 867 |
869 const_cast<v8::CpuProfile*>(profile)->Delete(); | 868 profile->Delete(); |
870 } | 869 } |
871 | 870 |
872 | 871 |
873 TEST(NativeMethodMonomorphicIC) { | 872 TEST(NativeMethodMonomorphicIC) { |
874 LocalContext env; | 873 LocalContext env; |
875 v8::Isolate* isolate = env->GetIsolate(); | 874 v8::Isolate* isolate = env->GetIsolate(); |
876 v8::HandleScope scope(isolate); | 875 v8::HandleScope scope(isolate); |
877 | 876 |
878 TestApiCallbacks callbacks(1); | 877 TestApiCallbacks callbacks(1); |
879 v8::Local<v8::External> data = | 878 v8::Local<v8::External> data = |
(...skipping 28 matching lines...) Expand all Loading... |
908 int32_t warm_up_iterations = 3; | 907 int32_t warm_up_iterations = 3; |
909 v8::Handle<v8::Value> args[] = { | 908 v8::Handle<v8::Value> args[] = { |
910 v8::Integer::New(isolate, warm_up_iterations) | 909 v8::Integer::New(isolate, warm_up_iterations) |
911 }; | 910 }; |
912 function->Call(env->Global(), ARRAY_SIZE(args), args); | 911 function->Call(env->Global(), ARRAY_SIZE(args), args); |
913 callbacks.set_warming_up(false); | 912 callbacks.set_warming_up(false); |
914 } | 913 } |
915 | 914 |
916 int32_t repeat_count = 100; | 915 int32_t repeat_count = 100; |
917 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; | 916 v8::Handle<v8::Value> args[] = { v8::Integer::New(isolate, repeat_count) }; |
918 const v8::CpuProfile* profile = | 917 v8::CpuProfile* profile = |
919 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | 918 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
920 | 919 |
921 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 920 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
922 GetChild(isolate, root, "start"); | 921 GetChild(isolate, root, "start"); |
923 const v8::CpuProfileNode* startNode = | 922 const v8::CpuProfileNode* startNode = |
924 GetChild(isolate, root, "start"); | 923 GetChild(isolate, root, "start"); |
925 GetChild(isolate, startNode, "fooMethod"); | 924 GetChild(isolate, startNode, "fooMethod"); |
926 | 925 |
927 const_cast<v8::CpuProfile*>(profile)->Delete(); | 926 profile->Delete(); |
928 } | 927 } |
929 | 928 |
930 | 929 |
931 static const char* bound_function_test_source = "function foo(iterations) {\n" | 930 static const char* bound_function_test_source = "function foo(iterations) {\n" |
932 " var r = 0;\n" | 931 " var r = 0;\n" |
933 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 932 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
934 " return r;\n" | 933 " return r;\n" |
935 "}\n" | 934 "}\n" |
936 "function start(duration) {\n" | 935 "function start(duration) {\n" |
937 " var callback = foo.bind(this);\n" | 936 " var callback = foo.bind(this);\n" |
(...skipping 11 matching lines...) Expand all Loading... |
949 v8::Script::Compile( | 948 v8::Script::Compile( |
950 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) | 949 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) |
951 ->Run(); | 950 ->Run(); |
952 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 951 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
953 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 952 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
954 | 953 |
955 int32_t duration_ms = 100; | 954 int32_t duration_ms = 100; |
956 v8::Handle<v8::Value> args[] = { | 955 v8::Handle<v8::Value> args[] = { |
957 v8::Integer::New(env->GetIsolate(), duration_ms) | 956 v8::Integer::New(env->GetIsolate(), duration_ms) |
958 }; | 957 }; |
959 const v8::CpuProfile* profile = | 958 v8::CpuProfile* profile = |
960 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | 959 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
961 | 960 |
962 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 961 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
963 ScopedVector<v8::Handle<v8::String> > names(3); | 962 ScopedVector<v8::Handle<v8::String> > names(3); |
964 names[0] = v8::String::NewFromUtf8( | 963 names[0] = v8::String::NewFromUtf8( |
965 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 964 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
966 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 965 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
967 ProfileGenerator::kProgramEntryName); | 966 ProfileGenerator::kProgramEntryName); |
968 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 967 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
969 // Don't allow |foo| node to be at the top level. | 968 // Don't allow |foo| node to be at the top level. |
970 CheckChildrenNames(root, names); | 969 CheckChildrenNames(root, names); |
971 | 970 |
972 const v8::CpuProfileNode* startNode = | 971 const v8::CpuProfileNode* startNode = |
973 GetChild(env->GetIsolate(), root, "start"); | 972 GetChild(env->GetIsolate(), root, "start"); |
974 GetChild(env->GetIsolate(), startNode, "foo"); | 973 GetChild(env->GetIsolate(), startNode, "foo"); |
975 | 974 |
976 const_cast<v8::CpuProfile*>(profile)->Delete(); | 975 profile->Delete(); |
977 } | 976 } |
978 | 977 |
979 | 978 |
980 static const char* call_function_test_source = "function bar(iterations) {\n" | 979 static const char* call_function_test_source = "function bar(iterations) {\n" |
981 "}\n" | 980 "}\n" |
982 "function start(duration) {\n" | 981 "function start(duration) {\n" |
983 " var start = Date.now();\n" | 982 " var start = Date.now();\n" |
984 " while (Date.now() - start < duration) {\n" | 983 " while (Date.now() - start < duration) {\n" |
985 " try {\n" | 984 " try {\n" |
986 " bar.call(this, 10 * 1000);\n" | 985 " bar.call(this, 10 * 1000);\n" |
(...skipping 23 matching lines...) Expand all Loading... |
1010 | 1009 |
1011 v8::Script::Compile(v8::String::NewFromUtf8( | 1010 v8::Script::Compile(v8::String::NewFromUtf8( |
1012 env->GetIsolate(), call_function_test_source))->Run(); | 1011 env->GetIsolate(), call_function_test_source))->Run(); |
1013 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1012 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1014 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1013 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1015 | 1014 |
1016 int32_t duration_ms = 100; | 1015 int32_t duration_ms = 100; |
1017 v8::Handle<v8::Value> args[] = { | 1016 v8::Handle<v8::Value> args[] = { |
1018 v8::Integer::New(env->GetIsolate(), duration_ms) | 1017 v8::Integer::New(env->GetIsolate(), duration_ms) |
1019 }; | 1018 }; |
1020 const v8::CpuProfile* profile = | 1019 v8::CpuProfile* profile = |
1021 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | 1020 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
1022 | 1021 |
1023 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1022 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1024 { | 1023 { |
1025 ScopedVector<v8::Handle<v8::String> > names(4); | 1024 ScopedVector<v8::Handle<v8::String> > names(4); |
1026 names[0] = v8::String::NewFromUtf8( | 1025 names[0] = v8::String::NewFromUtf8( |
1027 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1026 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
1028 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1027 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
1029 ProfileGenerator::kProgramEntryName); | 1028 ProfileGenerator::kProgramEntryName); |
1030 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1029 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
(...skipping 18 matching lines...) Expand all Loading... |
1049 } | 1048 } |
1050 | 1049 |
1051 const v8::CpuProfileNode* unresolvedNode = FindChild( | 1050 const v8::CpuProfileNode* unresolvedNode = FindChild( |
1052 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); | 1051 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); |
1053 if (unresolvedNode) { | 1052 if (unresolvedNode) { |
1054 ScopedVector<v8::Handle<v8::String> > names(1); | 1053 ScopedVector<v8::Handle<v8::String> > names(1); |
1055 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); | 1054 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); |
1056 CheckChildrenNames(unresolvedNode, names); | 1055 CheckChildrenNames(unresolvedNode, names); |
1057 } | 1056 } |
1058 | 1057 |
1059 const_cast<v8::CpuProfile*>(profile)->Delete(); | 1058 profile->Delete(); |
1060 } | 1059 } |
1061 | 1060 |
1062 | 1061 |
1063 static const char* function_apply_test_source = "function bar(iterations) {\n" | 1062 static const char* function_apply_test_source = "function bar(iterations) {\n" |
1064 "}\n" | 1063 "}\n" |
1065 "function test() {\n" | 1064 "function test() {\n" |
1066 " bar.apply(this, [10 * 1000]);\n" | 1065 " bar.apply(this, [10 * 1000]);\n" |
1067 "}\n" | 1066 "}\n" |
1068 "function start(duration) {\n" | 1067 "function start(duration) {\n" |
1069 " var start = Date.now();\n" | 1068 " var start = Date.now();\n" |
(...skipping 23 matching lines...) Expand all Loading... |
1093 v8::String::NewFromUtf8(env->GetIsolate(), function_apply_test_source)) | 1092 v8::String::NewFromUtf8(env->GetIsolate(), function_apply_test_source)) |
1094 ->Run(); | 1093 ->Run(); |
1095 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1094 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1096 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1095 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1097 | 1096 |
1098 int32_t duration_ms = 100; | 1097 int32_t duration_ms = 100; |
1099 v8::Handle<v8::Value> args[] = { | 1098 v8::Handle<v8::Value> args[] = { |
1100 v8::Integer::New(env->GetIsolate(), duration_ms) | 1099 v8::Integer::New(env->GetIsolate(), duration_ms) |
1101 }; | 1100 }; |
1102 | 1101 |
1103 const v8::CpuProfile* profile = | 1102 v8::CpuProfile* profile = |
1104 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); | 1103 RunProfiler(env.local(), function, args, ARRAY_SIZE(args), 100); |
1105 | 1104 |
1106 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1105 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1107 { | 1106 { |
1108 ScopedVector<v8::Handle<v8::String> > names(3); | 1107 ScopedVector<v8::Handle<v8::String> > names(3); |
1109 names[0] = v8::String::NewFromUtf8( | 1108 names[0] = v8::String::NewFromUtf8( |
1110 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1109 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
1111 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1110 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
1112 ProfileGenerator::kProgramEntryName); | 1111 ProfileGenerator::kProgramEntryName); |
1113 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1112 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
(...skipping 24 matching lines...) Expand all Loading... |
1138 if (const v8::CpuProfileNode* unresolvedNode = | 1137 if (const v8::CpuProfileNode* unresolvedNode = |
1139 FindChild(env->GetIsolate(), startNode, | 1138 FindChild(env->GetIsolate(), startNode, |
1140 ProfileGenerator::kUnresolvedFunctionName)) { | 1139 ProfileGenerator::kUnresolvedFunctionName)) { |
1141 ScopedVector<v8::Handle<v8::String> > names(1); | 1140 ScopedVector<v8::Handle<v8::String> > names(1); |
1142 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); | 1141 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); |
1143 CheckChildrenNames(unresolvedNode, names); | 1142 CheckChildrenNames(unresolvedNode, names); |
1144 GetChild(env->GetIsolate(), unresolvedNode, "apply"); | 1143 GetChild(env->GetIsolate(), unresolvedNode, "apply"); |
1145 } | 1144 } |
1146 } | 1145 } |
1147 | 1146 |
1148 const_cast<v8::CpuProfile*>(profile)->Delete(); | 1147 profile->Delete(); |
1149 } | 1148 } |
1150 | 1149 |
1151 | 1150 |
1152 static const char* js_native_js_test_source = | 1151 static const char* js_native_js_test_source = |
1153 "var is_profiling = false;\n" | 1152 "var is_profiling = false;\n" |
1154 "function foo(iterations) {\n" | 1153 "function foo(iterations) {\n" |
1155 " if (!is_profiling) {\n" | 1154 " if (!is_profiling) {\n" |
1156 " is_profiling = true;\n" | 1155 " is_profiling = true;\n" |
1157 " startProfiling('my_profile');\n" | 1156 " startProfiling('my_profile');\n" |
1158 " }\n" | 1157 " }\n" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 | 1199 |
1201 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), | 1200 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
1202 js_native_js_test_source))->Run(); | 1201 js_native_js_test_source))->Run(); |
1203 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1202 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1204 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1203 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1205 | 1204 |
1206 int32_t duration_ms = 20; | 1205 int32_t duration_ms = 20; |
1207 v8::Handle<v8::Value> args[] = { | 1206 v8::Handle<v8::Value> args[] = { |
1208 v8::Integer::New(env->GetIsolate(), duration_ms) | 1207 v8::Integer::New(env->GetIsolate(), duration_ms) |
1209 }; | 1208 }; |
1210 const v8::CpuProfile* profile = | 1209 v8::CpuProfile* profile = |
1211 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | 1210 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
1212 | 1211 |
1213 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1212 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1214 { | 1213 { |
1215 ScopedVector<v8::Handle<v8::String> > names(3); | 1214 ScopedVector<v8::Handle<v8::String> > names(3); |
1216 names[0] = v8::String::NewFromUtf8( | 1215 names[0] = v8::String::NewFromUtf8( |
1217 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1216 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
1218 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1217 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
1219 ProfileGenerator::kProgramEntryName); | 1218 ProfileGenerator::kProgramEntryName); |
1220 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1219 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
1221 CheckChildrenNames(root, names); | 1220 CheckChildrenNames(root, names); |
1222 } | 1221 } |
1223 | 1222 |
1224 const v8::CpuProfileNode* startNode = | 1223 const v8::CpuProfileNode* startNode = |
1225 GetChild(env->GetIsolate(), root, "start"); | 1224 GetChild(env->GetIsolate(), root, "start"); |
1226 CHECK_EQ(1, startNode->GetChildrenCount()); | 1225 CHECK_EQ(1, startNode->GetChildrenCount()); |
1227 const v8::CpuProfileNode* nativeFunctionNode = | 1226 const v8::CpuProfileNode* nativeFunctionNode = |
1228 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); | 1227 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); |
1229 | 1228 |
1230 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1229 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
1231 const v8::CpuProfileNode* barNode = | 1230 const v8::CpuProfileNode* barNode = |
1232 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | 1231 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
1233 | 1232 |
1234 CHECK_EQ(1, barNode->GetChildrenCount()); | 1233 CHECK_EQ(1, barNode->GetChildrenCount()); |
1235 GetChild(env->GetIsolate(), barNode, "foo"); | 1234 GetChild(env->GetIsolate(), barNode, "foo"); |
1236 | 1235 |
1237 const_cast<v8::CpuProfile*>(profile)->Delete(); | 1236 profile->Delete(); |
1238 } | 1237 } |
1239 | 1238 |
1240 | 1239 |
1241 static const char* js_native_js_runtime_js_test_source = | 1240 static const char* js_native_js_runtime_js_test_source = |
1242 "var is_profiling = false;\n" | 1241 "var is_profiling = false;\n" |
1243 "function foo(iterations) {\n" | 1242 "function foo(iterations) {\n" |
1244 " if (!is_profiling) {\n" | 1243 " if (!is_profiling) {\n" |
1245 " is_profiling = true;\n" | 1244 " is_profiling = true;\n" |
1246 " startProfiling('my_profile');\n" | 1245 " startProfiling('my_profile');\n" |
1247 " }\n" | 1246 " }\n" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 v8::Script::Compile( | 1284 v8::Script::Compile( |
1286 v8::String::NewFromUtf8(env->GetIsolate(), | 1285 v8::String::NewFromUtf8(env->GetIsolate(), |
1287 js_native_js_runtime_js_test_source))->Run(); | 1286 js_native_js_runtime_js_test_source))->Run(); |
1288 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1287 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1289 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1288 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1290 | 1289 |
1291 int32_t duration_ms = 20; | 1290 int32_t duration_ms = 20; |
1292 v8::Handle<v8::Value> args[] = { | 1291 v8::Handle<v8::Value> args[] = { |
1293 v8::Integer::New(env->GetIsolate(), duration_ms) | 1292 v8::Integer::New(env->GetIsolate(), duration_ms) |
1294 }; | 1293 }; |
1295 const v8::CpuProfile* profile = | 1294 v8::CpuProfile* profile = |
1296 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | 1295 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
1297 | 1296 |
1298 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1297 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1299 ScopedVector<v8::Handle<v8::String> > names(3); | 1298 ScopedVector<v8::Handle<v8::String> > names(3); |
1300 names[0] = v8::String::NewFromUtf8( | 1299 names[0] = v8::String::NewFromUtf8( |
1301 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1300 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
1302 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1301 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
1303 ProfileGenerator::kProgramEntryName); | 1302 ProfileGenerator::kProgramEntryName); |
1304 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1303 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
1305 CheckChildrenNames(root, names); | 1304 CheckChildrenNames(root, names); |
1306 | 1305 |
1307 const v8::CpuProfileNode* startNode = | 1306 const v8::CpuProfileNode* startNode = |
1308 GetChild(env->GetIsolate(), root, "start"); | 1307 GetChild(env->GetIsolate(), root, "start"); |
1309 CHECK_EQ(1, startNode->GetChildrenCount()); | 1308 CHECK_EQ(1, startNode->GetChildrenCount()); |
1310 const v8::CpuProfileNode* nativeFunctionNode = | 1309 const v8::CpuProfileNode* nativeFunctionNode = |
1311 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); | 1310 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); |
1312 | 1311 |
1313 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1312 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
1314 const v8::CpuProfileNode* barNode = | 1313 const v8::CpuProfileNode* barNode = |
1315 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | 1314 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
1316 | 1315 |
1317 CHECK_EQ(1, barNode->GetChildrenCount()); | 1316 CHECK_EQ(1, barNode->GetChildrenCount()); |
1318 GetChild(env->GetIsolate(), barNode, "foo"); | 1317 GetChild(env->GetIsolate(), barNode, "foo"); |
1319 | 1318 |
1320 const_cast<v8::CpuProfile*>(profile)->Delete(); | 1319 profile->Delete(); |
1321 } | 1320 } |
1322 | 1321 |
1323 | 1322 |
1324 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1323 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
1325 CallJsFunction(info); | 1324 CallJsFunction(info); |
1326 } | 1325 } |
1327 | 1326 |
1328 | 1327 |
1329 static const char* js_native1_js_native2_js_test_source = | 1328 static const char* js_native1_js_native2_js_test_source = |
1330 "var is_profiling = false;\n" | 1329 "var is_profiling = false;\n" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 v8::Script::Compile( | 1378 v8::Script::Compile( |
1380 v8::String::NewFromUtf8(env->GetIsolate(), | 1379 v8::String::NewFromUtf8(env->GetIsolate(), |
1381 js_native1_js_native2_js_test_source))->Run(); | 1380 js_native1_js_native2_js_test_source))->Run(); |
1382 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1381 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
1383 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); | 1382 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
1384 | 1383 |
1385 int32_t duration_ms = 20; | 1384 int32_t duration_ms = 20; |
1386 v8::Handle<v8::Value> args[] = { | 1385 v8::Handle<v8::Value> args[] = { |
1387 v8::Integer::New(env->GetIsolate(), duration_ms) | 1386 v8::Integer::New(env->GetIsolate(), duration_ms) |
1388 }; | 1387 }; |
1389 const v8::CpuProfile* profile = | 1388 v8::CpuProfile* profile = |
1390 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | 1389 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
1391 | 1390 |
1392 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1391 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1393 ScopedVector<v8::Handle<v8::String> > names(3); | 1392 ScopedVector<v8::Handle<v8::String> > names(3); |
1394 names[0] = v8::String::NewFromUtf8( | 1393 names[0] = v8::String::NewFromUtf8( |
1395 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1394 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
1396 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1395 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
1397 ProfileGenerator::kProgramEntryName); | 1396 ProfileGenerator::kProgramEntryName); |
1398 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 1397 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
1399 CheckChildrenNames(root, names); | 1398 CheckChildrenNames(root, names); |
1400 | 1399 |
1401 const v8::CpuProfileNode* startNode = | 1400 const v8::CpuProfileNode* startNode = |
1402 GetChild(env->GetIsolate(), root, "start"); | 1401 GetChild(env->GetIsolate(), root, "start"); |
1403 CHECK_EQ(1, startNode->GetChildrenCount()); | 1402 CHECK_EQ(1, startNode->GetChildrenCount()); |
1404 const v8::CpuProfileNode* nativeNode1 = | 1403 const v8::CpuProfileNode* nativeNode1 = |
1405 GetChild(env->GetIsolate(), startNode, "CallJsFunction1"); | 1404 GetChild(env->GetIsolate(), startNode, "CallJsFunction1"); |
1406 | 1405 |
1407 CHECK_EQ(1, nativeNode1->GetChildrenCount()); | 1406 CHECK_EQ(1, nativeNode1->GetChildrenCount()); |
1408 const v8::CpuProfileNode* barNode = | 1407 const v8::CpuProfileNode* barNode = |
1409 GetChild(env->GetIsolate(), nativeNode1, "bar"); | 1408 GetChild(env->GetIsolate(), nativeNode1, "bar"); |
1410 | 1409 |
1411 CHECK_EQ(1, barNode->GetChildrenCount()); | 1410 CHECK_EQ(1, barNode->GetChildrenCount()); |
1412 const v8::CpuProfileNode* nativeNode2 = | 1411 const v8::CpuProfileNode* nativeNode2 = |
1413 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); | 1412 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); |
1414 | 1413 |
1415 CHECK_EQ(1, nativeNode2->GetChildrenCount()); | 1414 CHECK_EQ(1, nativeNode2->GetChildrenCount()); |
1416 GetChild(env->GetIsolate(), nativeNode2, "foo"); | 1415 GetChild(env->GetIsolate(), nativeNode2, "foo"); |
1417 | 1416 |
1418 const_cast<v8::CpuProfile*>(profile)->Delete(); | 1417 profile->Delete(); |
1419 } | 1418 } |
1420 | 1419 |
1421 | 1420 |
1422 // [Top down]: | 1421 // [Top down]: |
1423 // 6 0 (root) #0 1 | 1422 // 6 0 (root) #0 1 |
1424 // 3 3 (program) #0 2 | 1423 // 3 3 (program) #0 2 |
1425 // 3 3 (idle) #0 3 | 1424 // 3 3 (idle) #0 3 |
1426 TEST(IdleTime) { | 1425 TEST(IdleTime) { |
1427 LocalContext env; | 1426 LocalContext env; |
1428 v8::HandleScope scope(env->GetIsolate()); | 1427 v8::HandleScope scope(env->GetIsolate()); |
1429 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1428 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
1430 | 1429 |
1431 v8::Local<v8::String> profile_name = | 1430 v8::Local<v8::String> profile_name = |
1432 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); | 1431 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
1433 cpu_profiler->StartCpuProfiling(profile_name); | 1432 cpu_profiler->StartProfiling(profile_name); |
1434 | 1433 |
1435 i::Isolate* isolate = CcTest::i_isolate(); | 1434 i::Isolate* isolate = CcTest::i_isolate(); |
1436 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); | 1435 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); |
1437 processor->AddCurrentStack(isolate); | 1436 processor->AddCurrentStack(isolate); |
1438 | 1437 |
1439 cpu_profiler->SetIdle(true); | 1438 cpu_profiler->SetIdle(true); |
1440 | 1439 |
1441 for (int i = 0; i < 3; i++) { | 1440 for (int i = 0; i < 3; i++) { |
1442 processor->AddCurrentStack(isolate); | 1441 processor->AddCurrentStack(isolate); |
1443 } | 1442 } |
1444 | 1443 |
1445 cpu_profiler->SetIdle(false); | 1444 cpu_profiler->SetIdle(false); |
1446 processor->AddCurrentStack(isolate); | 1445 processor->AddCurrentStack(isolate); |
1447 | 1446 |
1448 | 1447 |
1449 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 1448 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); |
1450 CHECK_NE(NULL, profile); | 1449 CHECK_NE(NULL, profile); |
1451 // Dump collected profile to have a better diagnostic in case of failure. | 1450 // Dump collected profile to have a better diagnostic in case of failure. |
1452 reinterpret_cast<i::CpuProfile*>( | 1451 reinterpret_cast<i::CpuProfile*>(profile)->Print(); |
1453 const_cast<v8::CpuProfile*>(profile))->Print(); | |
1454 | 1452 |
1455 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1453 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
1456 ScopedVector<v8::Handle<v8::String> > names(3); | 1454 ScopedVector<v8::Handle<v8::String> > names(3); |
1457 names[0] = v8::String::NewFromUtf8( | 1455 names[0] = v8::String::NewFromUtf8( |
1458 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); | 1456 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
1459 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 1457 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
1460 ProfileGenerator::kProgramEntryName); | 1458 ProfileGenerator::kProgramEntryName); |
1461 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), | 1459 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), |
1462 ProfileGenerator::kIdleEntryName); | 1460 ProfileGenerator::kIdleEntryName); |
1463 CheckChildrenNames(root, names); | 1461 CheckChildrenNames(root, names); |
1464 | 1462 |
1465 const v8::CpuProfileNode* programNode = | 1463 const v8::CpuProfileNode* programNode = |
1466 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); | 1464 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); |
1467 CHECK_EQ(0, programNode->GetChildrenCount()); | 1465 CHECK_EQ(0, programNode->GetChildrenCount()); |
1468 CHECK_GE(programNode->GetHitCount(), 3); | 1466 CHECK_GE(programNode->GetHitCount(), 3); |
1469 | 1467 |
1470 const v8::CpuProfileNode* idleNode = | 1468 const v8::CpuProfileNode* idleNode = |
1471 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); | 1469 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); |
1472 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1470 CHECK_EQ(0, idleNode->GetChildrenCount()); |
1473 CHECK_GE(idleNode->GetHitCount(), 3); | 1471 CHECK_GE(idleNode->GetHitCount(), 3); |
1474 | 1472 |
1475 const_cast<v8::CpuProfile*>(profile)->Delete(); | 1473 profile->Delete(); |
1476 } | 1474 } |
1477 | 1475 |
1478 | 1476 |
1479 static void CheckFunctionDetails(v8::Isolate* isolate, | 1477 static void CheckFunctionDetails(v8::Isolate* isolate, |
1480 const v8::CpuProfileNode* node, | 1478 const v8::CpuProfileNode* node, |
1481 const char* name, const char* script_name, | 1479 const char* name, const char* script_name, |
1482 int script_id, int line, int column) { | 1480 int script_id, int line, int column) { |
1483 CHECK_EQ(v8::String::NewFromUtf8(isolate, name), | 1481 CHECK_EQ(v8::String::NewFromUtf8(isolate, name), |
1484 node->GetFunctionName()); | 1482 node->GetFunctionName()); |
1485 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name), | 1483 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 v8::HandleScope scope(CcTest::isolate()); | 1536 v8::HandleScope scope(CcTest::isolate()); |
1539 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); | 1537 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); |
1540 v8::Context::Scope context_scope(env); | 1538 v8::Context::Scope context_scope(env); |
1541 v8::Isolate* isolate = env->GetIsolate(); | 1539 v8::Isolate* isolate = env->GetIsolate(); |
1542 | 1540 |
1543 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); | 1541 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
1544 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); | 1542 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
1545 | 1543 |
1546 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1544 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1547 v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer"); | 1545 v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer"); |
1548 profiler->StartCpuProfiling(outer); | 1546 profiler->StartProfiling(outer); |
1549 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1547 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1550 | 1548 |
1551 v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner"); | 1549 v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner"); |
1552 profiler->StartCpuProfiling(inner); | 1550 profiler->StartProfiling(inner); |
1553 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1551 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1554 | 1552 |
1555 const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(inner); | 1553 v8::CpuProfile* inner_profile = profiler->StopProfiling(inner); |
1556 CHECK(inner_profile); | 1554 CHECK(inner_profile); |
1557 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1555 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1558 const_cast<v8::CpuProfile*>(inner_profile)->Delete(); | 1556 inner_profile->Delete(); |
1559 inner_profile = NULL; | 1557 inner_profile = NULL; |
1560 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1558 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1561 | 1559 |
1562 const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer); | 1560 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
1563 CHECK(outer_profile); | 1561 CHECK(outer_profile); |
1564 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1562 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1565 const_cast<v8::CpuProfile*>(outer_profile)->Delete(); | 1563 outer_profile->Delete(); |
1566 outer_profile = NULL; | 1564 outer_profile = NULL; |
1567 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1565 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1568 } | 1566 } |
OLD | NEW |