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

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

Issue 2117343006: Introduce v8::CpuProfiler::New and v8::CpuProfiler::Dispose API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-profile-generator.cc » ('j') | 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 CHECK_EQ(0, top_down_ddd_children->length()); 271 CHECK_EQ(0, top_down_ddd_children->length());
272 272
273 isolate->code_event_dispatcher()->RemoveListener(&profiler_listener); 273 isolate->code_event_dispatcher()->RemoveListener(&profiler_listener);
274 } 274 }
275 275
276 // http://crbug/51594 276 // http://crbug/51594
277 // This test must not crash. 277 // This test must not crash.
278 TEST(CrashIfStoppingLastNonExistentProfile) { 278 TEST(CrashIfStoppingLastNonExistentProfile) {
279 CcTest::InitializeVM(); 279 CcTest::InitializeVM();
280 TestSetup test_setup; 280 TestSetup test_setup;
281 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); 281 std::unique_ptr<CpuProfiler> profiler(new CpuProfiler(CcTest::i_isolate()));
282 profiler->StartProfiling("1"); 282 profiler->StartProfiling("1");
283 profiler->StopProfiling("2"); 283 profiler->StopProfiling("2");
284 profiler->StartProfiling("1"); 284 profiler->StartProfiling("1");
285 profiler->StopProfiling(""); 285 profiler->StopProfiling("");
286 } 286 }
287 287
288 // http://code.google.com/p/v8/issues/detail?id=1398 288 // http://code.google.com/p/v8/issues/detail?id=1398
289 // Long stacks (exceeding max frames limit) must not be erased. 289 // Long stacks (exceeding max frames limit) must not be erased.
290 TEST(Issue1398) { 290 TEST(Issue1398) {
291 TestSetup test_setup; 291 TestSetup test_setup;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 node = node->children()->last(); 330 node = node->children()->last();
331 ++actual_depth; 331 ++actual_depth;
332 } 332 }
333 333
334 CHECK_EQ(1 + v8::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. 334 CHECK_EQ(1 + v8::TickSample::kMaxFramesCount, actual_depth); // +1 for PC.
335 } 335 }
336 336
337 TEST(DeleteAllCpuProfiles) { 337 TEST(DeleteAllCpuProfiles) {
338 CcTest::InitializeVM(); 338 CcTest::InitializeVM();
339 TestSetup test_setup; 339 TestSetup test_setup;
340 CpuProfiler* profiler = CcTest::i_isolate()->cpu_profiler(); 340 std::unique_ptr<CpuProfiler> profiler(new CpuProfiler(CcTest::i_isolate()));
341 CHECK_EQ(0, profiler->GetProfilesCount()); 341 CHECK_EQ(0, profiler->GetProfilesCount());
342 profiler->DeleteAllProfiles(); 342 profiler->DeleteAllProfiles();
343 CHECK_EQ(0, profiler->GetProfilesCount()); 343 CHECK_EQ(0, profiler->GetProfilesCount());
344 344
345 profiler->StartProfiling("1"); 345 profiler->StartProfiling("1");
346 profiler->StopProfiling("1"); 346 profiler->StopProfiling("1");
347 CHECK_EQ(1, profiler->GetProfilesCount()); 347 CHECK_EQ(1, profiler->GetProfilesCount());
348 profiler->DeleteAllProfiles(); 348 profiler->DeleteAllProfiles();
349 CHECK_EQ(0, profiler->GetProfilesCount()); 349 CHECK_EQ(0, profiler->GetProfilesCount());
350 profiler->StartProfiling("1"); 350 profiler->StartProfiling("1");
(...skipping 23 matching lines...) Expand all
374 if (profile == profiler->GetProfile(i)) 374 if (profile == profiler->GetProfile(i))
375 return true; 375 return true;
376 } 376 }
377 return false; 377 return false;
378 } 378 }
379 379
380 380
381 TEST(DeleteCpuProfile) { 381 TEST(DeleteCpuProfile) {
382 LocalContext env; 382 LocalContext env;
383 v8::HandleScope scope(env->GetIsolate()); 383 v8::HandleScope scope(env->GetIsolate());
384 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 384 v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(env->GetIsolate());
385 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler); 385 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler);
386 386
387 CHECK_EQ(0, iprofiler->GetProfilesCount()); 387 CHECK_EQ(0, iprofiler->GetProfilesCount());
388 v8::Local<v8::String> name1 = v8_str("1"); 388 v8::Local<v8::String> name1 = v8_str("1");
389 cpu_profiler->StartProfiling(name1); 389 cpu_profiler->StartProfiling(name1);
390 v8::CpuProfile* p1 = cpu_profiler->StopProfiling(name1); 390 v8::CpuProfile* p1 = cpu_profiler->StopProfiling(name1);
391 CHECK(p1); 391 CHECK(p1);
392 CHECK_EQ(1, iprofiler->GetProfilesCount()); 392 CHECK_EQ(1, iprofiler->GetProfilesCount());
393 CHECK(FindCpuProfile(cpu_profiler, p1)); 393 CHECK(FindCpuProfile(cpu_profiler, p1));
394 p1->Delete(); 394 p1->Delete();
(...skipping 12 matching lines...) Expand all
407 CHECK_EQ(2, iprofiler->GetProfilesCount()); 407 CHECK_EQ(2, iprofiler->GetProfilesCount());
408 CHECK_NE(p2, p3); 408 CHECK_NE(p2, p3);
409 CHECK(FindCpuProfile(cpu_profiler, p3)); 409 CHECK(FindCpuProfile(cpu_profiler, p3));
410 CHECK(FindCpuProfile(cpu_profiler, p2)); 410 CHECK(FindCpuProfile(cpu_profiler, p2));
411 p2->Delete(); 411 p2->Delete();
412 CHECK_EQ(1, iprofiler->GetProfilesCount()); 412 CHECK_EQ(1, iprofiler->GetProfilesCount());
413 CHECK(!FindCpuProfile(cpu_profiler, p2)); 413 CHECK(!FindCpuProfile(cpu_profiler, p2));
414 CHECK(FindCpuProfile(cpu_profiler, p3)); 414 CHECK(FindCpuProfile(cpu_profiler, p3));
415 p3->Delete(); 415 p3->Delete();
416 CHECK_EQ(0, iprofiler->GetProfilesCount()); 416 CHECK_EQ(0, iprofiler->GetProfilesCount());
417 cpu_profiler->Dispose();
417 } 418 }
418 419
419 420
420 TEST(ProfileStartEndTime) { 421 TEST(ProfileStartEndTime) {
421 LocalContext env; 422 LocalContext env;
422 v8::HandleScope scope(env->GetIsolate()); 423 v8::HandleScope scope(env->GetIsolate());
423 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 424 v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(env->GetIsolate());
424 425
425 v8::Local<v8::String> profile_name = v8_str("test"); 426 v8::Local<v8::String> profile_name = v8_str("test");
426 cpu_profiler->StartProfiling(profile_name); 427 cpu_profiler->StartProfiling(profile_name);
427 const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 428 const v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
428 CHECK(profile->GetStartTime() <= profile->GetEndTime()); 429 CHECK(profile->GetStartTime() <= profile->GetEndTime());
430 cpu_profiler->Dispose();
429 } 431 }
430 432
431 static v8::CpuProfile* RunProfiler(v8::Local<v8::Context> env, 433 class ProfilerHelper {
432 v8::Local<v8::Function> function, 434 public:
433 v8::Local<v8::Value> argv[], int argc, 435 explicit ProfilerHelper(v8::Local<v8::Context> context)
434 unsigned min_js_samples = 0, 436 : context_(context),
435 unsigned min_external_samples = 0, 437 profiler_(v8::CpuProfiler::New(context->GetIsolate())),
436 bool collect_samples = false) { 438 owned_(true) {}
437 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 439 ProfilerHelper(v8::Local<v8::Context> context, v8::CpuProfiler* profiler)
440 : context_(context), profiler_(profiler), owned_(false) {}
441 ~ProfilerHelper() {
442 if (owned_) profiler_->Dispose();
443 }
444
445 v8::CpuProfile* Run(v8::Local<v8::Function> function,
446 v8::Local<v8::Value> argv[], int argc,
447 unsigned min_js_samples = 0,
448 unsigned min_external_samples = 0,
449 bool collect_samples = false);
450
451 v8::CpuProfiler* profiler() { return profiler_; }
452
453 private:
454 v8::Local<v8::Context> context_;
455 v8::CpuProfiler* profiler_;
456 bool owned_;
457 };
458
459 v8::CpuProfile* ProfilerHelper::Run(v8::Local<v8::Function> function,
460 v8::Local<v8::Value> argv[], int argc,
461 unsigned min_js_samples,
462 unsigned min_external_samples,
463 bool collect_samples) {
438 v8::Local<v8::String> profile_name = v8_str("my_profile"); 464 v8::Local<v8::String> profile_name = v8_str("my_profile");
439 465
440 cpu_profiler->SetSamplingInterval(100); 466 profiler_->SetSamplingInterval(100);
441 cpu_profiler->StartProfiling(profile_name, collect_samples); 467 profiler_->StartProfiling(profile_name, collect_samples);
442 468
443 v8::internal::CpuProfiler* i_cpu_profiler = 469 v8::internal::CpuProfiler* iprofiler =
444 reinterpret_cast<v8::internal::CpuProfiler*>(cpu_profiler); 470 reinterpret_cast<v8::internal::CpuProfiler*>(profiler_);
445 v8::sampler::Sampler* sampler = i_cpu_profiler->processor()->sampler(); 471 v8::sampler::Sampler* sampler = iprofiler->processor()->sampler();
446 sampler->StartCountingSamples(); 472 sampler->StartCountingSamples();
447 do { 473 do {
448 function->Call(env, env->Global(), argc, argv).ToLocalChecked(); 474 function->Call(context_, context_->Global(), argc, argv).ToLocalChecked();
449 } while (sampler->js_sample_count() < min_js_samples || 475 } while (sampler->js_sample_count() < min_js_samples ||
450 sampler->external_sample_count() < min_external_samples); 476 sampler->external_sample_count() < min_external_samples);
451 477
452 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 478 v8::CpuProfile* profile = profiler_->StopProfiling(profile_name);
453 479
454 CHECK(profile); 480 CHECK(profile);
455 // Dump collected profile to have a better diagnostic in case of failure. 481 // Dump collected profile to have a better diagnostic in case of failure.
456 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 482 reinterpret_cast<i::CpuProfile*>(profile)->Print();
457 483
458 return profile; 484 return profile;
459 } 485 }
460 486
461
462 static const v8::CpuProfileNode* FindChild(v8::Local<v8::Context> context, 487 static const v8::CpuProfileNode* FindChild(v8::Local<v8::Context> context,
463 const v8::CpuProfileNode* node, 488 const v8::CpuProfileNode* node,
464 const char* name) { 489 const char* name) {
465 int count = node->GetChildrenCount(); 490 int count = node->GetChildrenCount();
466 v8::Local<v8::String> name_handle = v8_str(name); 491 v8::Local<v8::String> name_handle = v8_str(name);
467 for (int i = 0; i < count; i++) { 492 for (int i = 0; i < count; i++) {
468 const v8::CpuProfileNode* child = node->GetChild(i); 493 const v8::CpuProfileNode* child = node->GetChild(i);
469 if (name_handle->Equals(context, child->GetFunctionName()).FromJust()) { 494 if (name_handle->Equals(context, child->GetFunctionName()).FromJust()) {
470 return child; 495 return child;
471 } 496 }
(...skipping 28 matching lines...) Expand all
500 static const ProfileNode* GetSimpleBranch(v8::Local<v8::Context> context, 525 static const ProfileNode* GetSimpleBranch(v8::Local<v8::Context> context,
501 v8::CpuProfile* profile, 526 v8::CpuProfile* profile,
502 const char* names[], int length) { 527 const char* names[], int length) {
503 const v8::CpuProfileNode* node = profile->GetTopDownRoot(); 528 const v8::CpuProfileNode* node = profile->GetTopDownRoot();
504 for (int i = 0; i < length; i++) { 529 for (int i = 0; i < length; i++) {
505 node = GetChild(context, node, names[i]); 530 node = GetChild(context, node, names[i]);
506 } 531 }
507 return reinterpret_cast<const ProfileNode*>(node); 532 return reinterpret_cast<const ProfileNode*>(node);
508 } 533 }
509 534
510 static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) {
511 info.GetIsolate()->GetCpuProfiler()->CollectSample();
512 }
513
514 static const char* cpu_profiler_test_source = 535 static const char* cpu_profiler_test_source =
515 "%NeverOptimizeFunction(loop);\n" 536 "%NeverOptimizeFunction(loop);\n"
516 "%NeverOptimizeFunction(delay);\n" 537 "%NeverOptimizeFunction(delay);\n"
517 "%NeverOptimizeFunction(bar);\n" 538 "%NeverOptimizeFunction(bar);\n"
518 "%NeverOptimizeFunction(baz);\n" 539 "%NeverOptimizeFunction(baz);\n"
519 "%NeverOptimizeFunction(foo);\n" 540 "%NeverOptimizeFunction(foo);\n"
520 "%NeverOptimizeFunction(start);\n" 541 "%NeverOptimizeFunction(start);\n"
521 "function loop(timeout) {\n" 542 "function loop(timeout) {\n"
522 " this.mmm = 0;\n" 543 " this.mmm = 0;\n"
523 " var start = Date.now();\n" 544 " var start = Date.now();\n"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 i::FLAG_allow_natives_syntax = true; 587 i::FLAG_allow_natives_syntax = true;
567 LocalContext env; 588 LocalContext env;
568 v8::HandleScope scope(env->GetIsolate()); 589 v8::HandleScope scope(env->GetIsolate());
569 590
570 CompileRun(cpu_profiler_test_source); 591 CompileRun(cpu_profiler_test_source);
571 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 592 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
572 593
573 int32_t profiling_interval_ms = 200; 594 int32_t profiling_interval_ms = 200;
574 v8::Local<v8::Value> args[] = { 595 v8::Local<v8::Value> args[] = {
575 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; 596 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
576 v8::CpuProfile* profile = 597 ProfilerHelper helper(env.local());
577 RunProfiler(env.local(), function, args, arraysize(args), 1000); 598 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000);
578 599
579 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 600 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
580 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 601 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
581 const v8::CpuProfileNode* foo_node = GetChild(env.local(), start_node, "foo"); 602 const v8::CpuProfileNode* foo_node = GetChild(env.local(), start_node, "foo");
582 603
583 const char* bar_branch[] = {"bar", "delay", "loop"}; 604 const char* bar_branch[] = {"bar", "delay", "loop"};
584 CheckSimpleBranch(env.local(), foo_node, bar_branch, arraysize(bar_branch)); 605 CheckSimpleBranch(env.local(), foo_node, bar_branch, arraysize(bar_branch));
585 const char* baz_branch[] = {"baz", "delay", "loop"}; 606 const char* baz_branch[] = {"baz", "delay", "loop"};
586 CheckSimpleBranch(env.local(), foo_node, baz_branch, arraysize(baz_branch)); 607 CheckSimpleBranch(env.local(), foo_node, baz_branch, arraysize(baz_branch));
587 const char* delay_branch[] = {"delay", "loop"}; 608 const char* delay_branch[] = {"delay", "loop"};
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 i::FLAG_allow_natives_syntax = true; 644 i::FLAG_allow_natives_syntax = true;
624 LocalContext env; 645 LocalContext env;
625 v8::HandleScope scope(env->GetIsolate()); 646 v8::HandleScope scope(env->GetIsolate());
626 647
627 CompileRun(hot_deopt_no_frame_entry_test_source); 648 CompileRun(hot_deopt_no_frame_entry_test_source);
628 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 649 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
629 650
630 int32_t profiling_interval_ms = 200; 651 int32_t profiling_interval_ms = 200;
631 v8::Local<v8::Value> args[] = { 652 v8::Local<v8::Value> args[] = {
632 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; 653 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
633 v8::CpuProfile* profile = 654 ProfilerHelper helper(env.local());
634 RunProfiler(env.local(), function, args, arraysize(args), 1000); 655 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000);
635 function->Call(env.local(), env->Global(), arraysize(args), args) 656 function->Call(env.local(), env->Global(), arraysize(args), args)
636 .ToLocalChecked(); 657 .ToLocalChecked();
637 658
638 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 659 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
639 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 660 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
640 GetChild(env.local(), start_node, "foo"); 661 GetChild(env.local(), start_node, "foo");
641 662
642 profile->Delete(); 663 profile->Delete();
643 } 664 }
644 665
645 TEST(CollectCpuProfileSamples) { 666 TEST(CollectCpuProfileSamples) {
646 i::FLAG_allow_natives_syntax = true; 667 i::FLAG_allow_natives_syntax = true;
647 LocalContext env; 668 LocalContext env;
648 v8::HandleScope scope(env->GetIsolate()); 669 v8::HandleScope scope(env->GetIsolate());
649 670
650 CompileRun(cpu_profiler_test_source); 671 CompileRun(cpu_profiler_test_source);
651 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 672 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
652 673
653 int32_t profiling_interval_ms = 200; 674 int32_t profiling_interval_ms = 200;
654 v8::Local<v8::Value> args[] = { 675 v8::Local<v8::Value> args[] = {
655 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)}; 676 v8::Integer::New(env->GetIsolate(), profiling_interval_ms)};
677 ProfilerHelper helper(env.local());
656 v8::CpuProfile* profile = 678 v8::CpuProfile* profile =
657 RunProfiler(env.local(), function, args, arraysize(args), 1000, 0, true); 679 helper.Run(function, args, arraysize(args), 1000, 0, true);
658 680
659 CHECK_LE(200, profile->GetSamplesCount()); 681 CHECK_LE(200, profile->GetSamplesCount());
660 uint64_t end_time = profile->GetEndTime(); 682 uint64_t end_time = profile->GetEndTime();
661 uint64_t current_time = profile->GetStartTime(); 683 uint64_t current_time = profile->GetStartTime();
662 CHECK_LE(current_time, end_time); 684 CHECK_LE(current_time, end_time);
663 for (int i = 0; i < profile->GetSamplesCount(); i++) { 685 for (int i = 0; i < profile->GetSamplesCount(); i++) {
664 CHECK(profile->GetSample(i)); 686 CHECK(profile->GetSample(i));
665 uint64_t timestamp = profile->GetSampleTimestamp(i); 687 uint64_t timestamp = profile->GetSampleTimestamp(i);
666 CHECK_LE(current_time, timestamp); 688 CHECK_LE(current_time, timestamp);
667 CHECK_LE(timestamp, end_time); 689 CHECK_LE(timestamp, end_time);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 i::FLAG_allow_natives_syntax = true; 721 i::FLAG_allow_natives_syntax = true;
700 LocalContext env; 722 LocalContext env;
701 v8::HandleScope scope(env->GetIsolate()); 723 v8::HandleScope scope(env->GetIsolate());
702 724
703 CompileRun(cpu_profiler_test_source2); 725 CompileRun(cpu_profiler_test_source2);
704 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 726 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
705 727
706 int32_t duration_ms = 100; 728 int32_t duration_ms = 100;
707 v8::Local<v8::Value> args[] = { 729 v8::Local<v8::Value> args[] = {
708 v8::Integer::New(env->GetIsolate(), duration_ms)}; 730 v8::Integer::New(env->GetIsolate(), duration_ms)};
709 v8::CpuProfile* profile = 731 ProfilerHelper helper(env.local());
710 RunProfiler(env.local(), function, args, arraysize(args), 1000); 732 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000);
711 733
712 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 734 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
713 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 735 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
714 const v8::CpuProfileNode* delay_node = 736 const v8::CpuProfileNode* delay_node =
715 GetChild(env.local(), start_node, "delay"); 737 GetChild(env.local(), start_node, "delay");
716 GetChild(env.local(), delay_node, "loop"); 738 GetChild(env.local(), delay_node, "loop");
717 739
718 profile->Delete(); 740 profile->Delete();
719 } 741 }
720 742
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 LocalContext env; 803 LocalContext env;
782 v8::Isolate* isolate = env->GetIsolate(); 804 v8::Isolate* isolate = env->GetIsolate();
783 v8::HandleScope scope(isolate); 805 v8::HandleScope scope(isolate);
784 806
785 v8::Local<v8::FunctionTemplate> func_template = 807 v8::Local<v8::FunctionTemplate> func_template =
786 v8::FunctionTemplate::New(isolate); 808 v8::FunctionTemplate::New(isolate);
787 v8::Local<v8::ObjectTemplate> instance_template = 809 v8::Local<v8::ObjectTemplate> instance_template =
788 func_template->InstanceTemplate(); 810 func_template->InstanceTemplate();
789 811
790 TestApiCallbacks accessors(100); 812 TestApiCallbacks accessors(100);
791 v8::Local<v8::External> data = 813 v8::Local<v8::External> data = v8::External::New(isolate, &accessors);
792 v8::External::New(isolate, &accessors);
793 instance_template->SetAccessor(v8_str("foo"), &TestApiCallbacks::Getter, 814 instance_template->SetAccessor(v8_str("foo"), &TestApiCallbacks::Getter,
794 &TestApiCallbacks::Setter, data); 815 &TestApiCallbacks::Setter, data);
795 v8::Local<v8::Function> func = 816 v8::Local<v8::Function> func =
796 func_template->GetFunction(env.local()).ToLocalChecked(); 817 func_template->GetFunction(env.local()).ToLocalChecked();
797 v8::Local<v8::Object> instance = 818 v8::Local<v8::Object> instance =
798 func->NewInstance(env.local()).ToLocalChecked(); 819 func->NewInstance(env.local()).ToLocalChecked();
799 env->Global()->Set(env.local(), v8_str("instance"), instance).FromJust(); 820 env->Global()->Set(env.local(), v8_str("instance"), instance).FromJust();
800 821
801 CompileRun(native_accessor_test_source); 822 CompileRun(native_accessor_test_source);
802 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 823 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
803 824
825 ProfilerHelper helper(env.local());
804 int32_t repeat_count = 1; 826 int32_t repeat_count = 1;
805 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; 827 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
806 v8::CpuProfile* profile = 828 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 100);
807 RunProfiler(env.local(), function, args, arraysize(args), 0, 100);
808 829
809 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 830 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
810 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 831 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
811 GetChild(env.local(), start_node, "get foo"); 832 GetChild(env.local(), start_node, "get foo");
812 GetChild(env.local(), start_node, "set foo"); 833 GetChild(env.local(), start_node, "set foo");
813 834
814 profile->Delete(); 835 profile->Delete();
815 } 836 }
816 837
817 838
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 int32_t warm_up_iterations = 3; 870 int32_t warm_up_iterations = 3;
850 v8::Local<v8::Value> args[] = { 871 v8::Local<v8::Value> args[] = {
851 v8::Integer::New(isolate, warm_up_iterations)}; 872 v8::Integer::New(isolate, warm_up_iterations)};
852 function->Call(env.local(), env->Global(), arraysize(args), args) 873 function->Call(env.local(), env->Global(), arraysize(args), args)
853 .ToLocalChecked(); 874 .ToLocalChecked();
854 accessors.set_warming_up(false); 875 accessors.set_warming_up(false);
855 } 876 }
856 877
857 int32_t repeat_count = 100; 878 int32_t repeat_count = 100;
858 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; 879 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
859 v8::CpuProfile* profile = 880 ProfilerHelper helper(env.local());
860 RunProfiler(env.local(), function, args, arraysize(args), 0, 100); 881 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 100);
861 882
862 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 883 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
863 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 884 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
864 GetChild(env.local(), start_node, "get foo"); 885 GetChild(env.local(), start_node, "get foo");
865 GetChild(env.local(), start_node, "set foo"); 886 GetChild(env.local(), start_node, "set foo");
866 887
867 profile->Delete(); 888 profile->Delete();
868 } 889 }
869 890
870 891
871 static const char* native_method_test_source = "function start(count) {\n" 892 static const char* native_method_test_source = "function start(count) {\n"
872 " for (var i = 0; i < count; i++) {\n" 893 " for (var i = 0; i < count; i++) {\n"
873 " instance.fooMethod();\n" 894 " instance.fooMethod();\n"
874 " }\n" 895 " }\n"
875 "}\n"; 896 "}\n";
876 897
877 898
878 TEST(NativeMethodUninitializedIC) { 899 TEST(NativeMethodUninitializedIC) {
879 LocalContext env; 900 LocalContext env;
880 v8::Isolate* isolate = env->GetIsolate(); 901 v8::Isolate* isolate = env->GetIsolate();
881 v8::HandleScope scope(isolate); 902 v8::HandleScope scope(isolate);
882 903
883 TestApiCallbacks callbacks(100); 904 TestApiCallbacks callbacks(100);
884 v8::Local<v8::External> data = 905 v8::Local<v8::External> data = v8::External::New(isolate, &callbacks);
885 v8::External::New(isolate, &callbacks);
886 906
887 v8::Local<v8::FunctionTemplate> func_template = 907 v8::Local<v8::FunctionTemplate> func_template =
888 v8::FunctionTemplate::New(isolate); 908 v8::FunctionTemplate::New(isolate);
889 func_template->SetClassName(v8_str("Test_InstanceCostructor")); 909 func_template->SetClassName(v8_str("Test_InstanceConstructor"));
890 v8::Local<v8::ObjectTemplate> proto_template = 910 v8::Local<v8::ObjectTemplate> proto_template =
891 func_template->PrototypeTemplate(); 911 func_template->PrototypeTemplate();
892 v8::Local<v8::Signature> signature = 912 v8::Local<v8::Signature> signature =
893 v8::Signature::New(isolate, func_template); 913 v8::Signature::New(isolate, func_template);
894 proto_template->Set( 914 proto_template->Set(
895 v8_str("fooMethod"), 915 v8_str("fooMethod"),
896 v8::FunctionTemplate::New(isolate, &TestApiCallbacks::Callback, data, 916 v8::FunctionTemplate::New(isolate, &TestApiCallbacks::Callback, data,
897 signature, 0)); 917 signature, 0));
898 918
899 v8::Local<v8::Function> func = 919 v8::Local<v8::Function> func =
900 func_template->GetFunction(env.local()).ToLocalChecked(); 920 func_template->GetFunction(env.local()).ToLocalChecked();
901 v8::Local<v8::Object> instance = 921 v8::Local<v8::Object> instance =
902 func->NewInstance(env.local()).ToLocalChecked(); 922 func->NewInstance(env.local()).ToLocalChecked();
903 env->Global()->Set(env.local(), v8_str("instance"), instance).FromJust(); 923 env->Global()->Set(env.local(), v8_str("instance"), instance).FromJust();
904 924
905 CompileRun(native_method_test_source); 925 CompileRun(native_method_test_source);
906 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 926 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
907 927
928 ProfilerHelper helper(env.local());
908 int32_t repeat_count = 1; 929 int32_t repeat_count = 1;
909 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; 930 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
910 v8::CpuProfile* profile = 931 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 100);
911 RunProfiler(env.local(), function, args, arraysize(args), 0, 100);
912 932
913 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 933 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
914 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 934 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
915 GetChild(env.local(), start_node, "fooMethod"); 935 GetChild(env.local(), start_node, "fooMethod");
916 936
917 profile->Delete(); 937 profile->Delete();
918 } 938 }
919 939
920 940
921 TEST(NativeMethodMonomorphicIC) { 941 TEST(NativeMethodMonomorphicIC) {
(...skipping 30 matching lines...) Expand all
952 // profiling. 972 // profiling.
953 callbacks.set_warming_up(true); 973 callbacks.set_warming_up(true);
954 int32_t warm_up_iterations = 3; 974 int32_t warm_up_iterations = 3;
955 v8::Local<v8::Value> args[] = { 975 v8::Local<v8::Value> args[] = {
956 v8::Integer::New(isolate, warm_up_iterations)}; 976 v8::Integer::New(isolate, warm_up_iterations)};
957 function->Call(env.local(), env->Global(), arraysize(args), args) 977 function->Call(env.local(), env->Global(), arraysize(args), args)
958 .ToLocalChecked(); 978 .ToLocalChecked();
959 callbacks.set_warming_up(false); 979 callbacks.set_warming_up(false);
960 } 980 }
961 981
982 ProfilerHelper helper(env.local());
962 int32_t repeat_count = 100; 983 int32_t repeat_count = 100;
963 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)}; 984 v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
964 v8::CpuProfile* profile = 985 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 0, 200);
965 RunProfiler(env.local(), function, args, arraysize(args), 0, 200);
966 986
967 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 987 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
968 GetChild(env.local(), root, "start"); 988 GetChild(env.local(), root, "start");
969 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 989 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
970 GetChild(env.local(), start_node, "fooMethod"); 990 GetChild(env.local(), start_node, "fooMethod");
971 991
972 profile->Delete(); 992 profile->Delete();
973 } 993 }
974 994
975 995
976 static const char* bound_function_test_source = 996 static const char* bound_function_test_source =
977 "function foo() {\n" 997 "function foo() {\n"
978 " startProfiling('my_profile');\n" 998 " startProfiling('my_profile');\n"
979 "}\n" 999 "}\n"
980 "function start() {\n" 1000 "function start() {\n"
981 " var callback = foo.bind(this);\n" 1001 " var callback = foo.bind(this);\n"
982 " callback();\n" 1002 " callback();\n"
983 "}"; 1003 "}";
984 1004
985 1005
986 TEST(BoundFunctionCall) { 1006 TEST(BoundFunctionCall) {
987 v8::HandleScope scope(CcTest::isolate()); 1007 v8::HandleScope scope(CcTest::isolate());
988 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1008 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
989 v8::Context::Scope context_scope(env); 1009 v8::Context::Scope context_scope(env);
1010 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
lpy 2016/07/06 21:34:35 I don't understand why we use a scope here to crea
alph 2016/07/06 21:45:16 Besides ProfilerHelper ProfilerExtension does also
alph 2016/07/06 23:12:41 I simplified it a bit.
990 1011
991 CompileRun(bound_function_test_source); 1012 CompileRun(bound_function_test_source);
992 v8::Local<v8::Function> function = GetFunction(env, "start"); 1013 v8::Local<v8::Function> function = GetFunction(env, "start");
993 1014
994 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0); 1015 ProfilerHelper helper(env, profiler_scope.profiler());
1016 v8::CpuProfile* profile = helper.Run(function, nullptr, 0);
995 1017
996 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1018 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
997 1019
998 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1020 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
999 GetChild(env, start_node, "foo"); 1021 GetChild(env, start_node, "foo");
1000 1022
1001 profile->Delete(); 1023 profile->Delete();
1002 } 1024 }
1003 1025
1004 // This tests checks distribution of the samples through the source lines. 1026 // This tests checks distribution of the samples through the source lines.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 LocalContext env; 1161 LocalContext env;
1140 v8::HandleScope scope(env->GetIsolate()); 1162 v8::HandleScope scope(env->GetIsolate());
1141 1163
1142 // Collect garbage that might have be generated while installing 1164 // Collect garbage that might have be generated while installing
1143 // extensions. 1165 // extensions.
1144 CcTest::heap()->CollectAllGarbage(); 1166 CcTest::heap()->CollectAllGarbage();
1145 1167
1146 CompileRun(call_function_test_source); 1168 CompileRun(call_function_test_source);
1147 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 1169 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
1148 1170
1171 ProfilerHelper helper(env.local());
1149 int32_t duration_ms = 100; 1172 int32_t duration_ms = 100;
1150 v8::Local<v8::Value> args[] = { 1173 v8::Local<v8::Value> args[] = {
1151 v8::Integer::New(env->GetIsolate(), duration_ms)}; 1174 v8::Integer::New(env->GetIsolate(), duration_ms)};
1152 v8::CpuProfile* profile = 1175 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000);
1153 RunProfiler(env.local(), function, args, arraysize(args), 1000);
1154 1176
1155 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1177 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1156 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 1178 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
1157 GetChild(env.local(), start_node, "bar"); 1179 GetChild(env.local(), start_node, "bar");
1158 1180
1159 const v8::CpuProfileNode* unresolved_node = 1181 const v8::CpuProfileNode* unresolved_node =
1160 FindChild(env.local(), root, i::CodeEntry::kUnresolvedFunctionName); 1182 FindChild(env.local(), root, i::CodeEntry::kUnresolvedFunctionName);
1161 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "call")); 1183 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "call"));
1162 1184
1163 profile->Delete(); 1185 profile->Delete();
(...skipping 28 matching lines...) Expand all
1192 // 2 2 bar [-1] #16 6 1214 // 2 2 bar [-1] #16 6
1193 // 10 10 (program) [-1] #0 2 1215 // 10 10 (program) [-1] #0 2
1194 TEST(FunctionApplySample) { 1216 TEST(FunctionApplySample) {
1195 i::FLAG_allow_natives_syntax = true; 1217 i::FLAG_allow_natives_syntax = true;
1196 LocalContext env; 1218 LocalContext env;
1197 v8::HandleScope scope(env->GetIsolate()); 1219 v8::HandleScope scope(env->GetIsolate());
1198 1220
1199 CompileRun(function_apply_test_source); 1221 CompileRun(function_apply_test_source);
1200 v8::Local<v8::Function> function = GetFunction(env.local(), "start"); 1222 v8::Local<v8::Function> function = GetFunction(env.local(), "start");
1201 1223
1224 ProfilerHelper helper(env.local());
1202 int32_t duration_ms = 100; 1225 int32_t duration_ms = 100;
1203 v8::Local<v8::Value> args[] = { 1226 v8::Local<v8::Value> args[] = {
1204 v8::Integer::New(env->GetIsolate(), duration_ms)}; 1227 v8::Integer::New(env->GetIsolate(), duration_ms)};
1205 1228 v8::CpuProfile* profile = helper.Run(function, args, arraysize(args), 1000);
1206 v8::CpuProfile* profile =
1207 RunProfiler(env.local(), function, args, arraysize(args), 1000);
1208 1229
1209 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1230 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1210 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start"); 1231 const v8::CpuProfileNode* start_node = GetChild(env.local(), root, "start");
1211 const v8::CpuProfileNode* test_node = 1232 const v8::CpuProfileNode* test_node =
1212 GetChild(env.local(), start_node, "test"); 1233 GetChild(env.local(), start_node, "test");
1213 GetChild(env.local(), test_node, "bar"); 1234 GetChild(env.local(), test_node, "bar");
1214 1235
1215 const v8::CpuProfileNode* unresolved_node = 1236 const v8::CpuProfileNode* unresolved_node =
1216 FindChild(env.local(), start_node, CodeEntry::kUnresolvedFunctionName); 1237 FindChild(env.local(), start_node, CodeEntry::kUnresolvedFunctionName);
1217 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "apply")); 1238 CHECK(!unresolved_node || GetChild(env.local(), unresolved_node, "apply"));
(...skipping 20 matching lines...) Expand all
1238 // 2 (program) 0 #2 1259 // 2 (program) 0 #2
1239 // 0 start 21 #3 no reason 1260 // 0 start 21 #3 no reason
1240 // 0 foo 21 #4 no reason 1261 // 0 foo 21 #4 no reason
1241 // 0 foo 21 #5 no reason 1262 // 0 foo 21 #5 no reason
1242 // .... 1263 // ....
1243 // 0 foo 21 #254 no reason 1264 // 0 foo 21 #254 no reason
1244 TEST(CpuProfileDeepStack) { 1265 TEST(CpuProfileDeepStack) {
1245 v8::HandleScope scope(CcTest::isolate()); 1266 v8::HandleScope scope(CcTest::isolate());
1246 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1267 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1247 v8::Context::Scope context_scope(env); 1268 v8::Context::Scope context_scope(env);
1269 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1248 1270
1249 CompileRun(cpu_profiler_deep_stack_test_source); 1271 CompileRun(cpu_profiler_deep_stack_test_source);
1250 v8::Local<v8::Function> function = GetFunction(env, "start"); 1272 v8::Local<v8::Function> function = GetFunction(env, "start");
1251 1273
1252 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1253 v8::Local<v8::String> profile_name = v8_str("my_profile"); 1274 v8::Local<v8::String> profile_name = v8_str("my_profile");
1254 function->Call(env, env->Global(), 0, NULL).ToLocalChecked(); 1275 function->Call(env, env->Global(), 0, NULL).ToLocalChecked();
1255 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 1276 v8::CpuProfile* profile =
1277 profiler_scope.profiler()->StopProfiling(profile_name);
1256 CHECK(profile); 1278 CHECK(profile);
1257 // Dump collected profile to have a better diagnostic in case of failure. 1279 // Dump collected profile to have a better diagnostic in case of failure.
1258 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 1280 reinterpret_cast<i::CpuProfile*>(profile)->Print();
1259 1281
1260 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1282 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1261 const v8::CpuProfileNode* node = GetChild(env, root, "start"); 1283 const v8::CpuProfileNode* node = GetChild(env, root, "start");
1262 for (int i = 0; i <= 250; ++i) { 1284 for (int i = 0; i <= 250; ++i) {
1263 node = GetChild(env, node, "foo"); 1285 node = GetChild(env, node, "foo");
1264 } 1286 }
1265 CHECK(!FindChild(env, node, "foo")); 1287 CHECK(!FindChild(env, node, "foo"));
(...skipping 30 matching lines...) Expand all
1296 // 2 2 (program) #0 2 1318 // 2 2 (program) #0 2
1297 // 56 1 start #16 3 1319 // 56 1 start #16 3
1298 // 55 0 CallJsFunction #0 4 1320 // 55 0 CallJsFunction #0 4
1299 // 55 1 bar #16 5 1321 // 55 1 bar #16 5
1300 // 54 54 foo #16 6 1322 // 54 54 foo #16 6
1301 TEST(JsNativeJsSample) { 1323 TEST(JsNativeJsSample) {
1302 i::FLAG_allow_natives_syntax = true; 1324 i::FLAG_allow_natives_syntax = true;
1303 v8::HandleScope scope(CcTest::isolate()); 1325 v8::HandleScope scope(CcTest::isolate());
1304 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1326 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1305 v8::Context::Scope context_scope(env); 1327 v8::Context::Scope context_scope(env);
1328 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1306 1329
1307 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1330 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1308 env->GetIsolate(), CallJsFunction); 1331 env->GetIsolate(), CallJsFunction);
1309 v8::Local<v8::Function> func = 1332 v8::Local<v8::Function> func =
1310 func_template->GetFunction(env).ToLocalChecked(); 1333 func_template->GetFunction(env).ToLocalChecked();
1311 func->SetName(v8_str("CallJsFunction")); 1334 func->SetName(v8_str("CallJsFunction"));
1312 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); 1335 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust();
1313 1336
1314 CompileRun(js_native_js_test_source); 1337 CompileRun(js_native_js_test_source);
1315 v8::Local<v8::Function> function = GetFunction(env, "start"); 1338 v8::Local<v8::Function> function = GetFunction(env, "start");
1316 1339
1317 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); 1340 ProfilerHelper helper(env, profiler_scope.profiler());
1341 v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 1000);
1318 1342
1319 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1343 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1320 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1344 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
1321 const v8::CpuProfileNode* native_node = 1345 const v8::CpuProfileNode* native_node =
1322 GetChild(env, start_node, "CallJsFunction"); 1346 GetChild(env, start_node, "CallJsFunction");
1323 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar"); 1347 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar");
1324 GetChild(env, bar_node, "foo"); 1348 GetChild(env, bar_node, "foo");
1325 1349
1326 profile->Delete(); 1350 profile->Delete();
1327 } 1351 }
(...skipping 29 matching lines...) Expand all
1357 v8::Context::Scope context_scope(env); 1381 v8::Context::Scope context_scope(env);
1358 1382
1359 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( 1383 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(
1360 env->GetIsolate(), CallJsFunction); 1384 env->GetIsolate(), CallJsFunction);
1361 v8::Local<v8::Function> func = 1385 v8::Local<v8::Function> func =
1362 func_template->GetFunction(env).ToLocalChecked(); 1386 func_template->GetFunction(env).ToLocalChecked();
1363 func->SetName(v8_str("CallJsFunction")); 1387 func->SetName(v8_str("CallJsFunction"));
1364 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); 1388 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust();
1365 1389
1366 CompileRun(js_native_js_runtime_js_test_source); 1390 CompileRun(js_native_js_runtime_js_test_source);
1391 ProfilerHelper helper(env);
1367 v8::Local<v8::Function> function = GetFunction(env, "start"); 1392 v8::Local<v8::Function> function = GetFunction(env, "start");
1368 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000); 1393 v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 1000);
1369 1394
1370 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1395 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1371 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1396 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
1372 const v8::CpuProfileNode* native_node = 1397 const v8::CpuProfileNode* native_node =
1373 GetChild(env, start_node, "CallJsFunction"); 1398 GetChild(env, start_node, "CallJsFunction");
1374 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar"); 1399 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar");
1375 GetChild(env, bar_node, "foo"); 1400 GetChild(env, bar_node, "foo");
1376 1401
1377 profile->Delete(); 1402 profile->Delete();
1378 } 1403 }
(...skipping 24 matching lines...) Expand all
1403 // 55 1 start #16 3 1428 // 55 1 start #16 3
1404 // 54 0 CallJsFunction1 #0 4 1429 // 54 0 CallJsFunction1 #0 4
1405 // 54 0 bar #16 5 1430 // 54 0 bar #16 5
1406 // 54 0 CallJsFunction2 #0 6 1431 // 54 0 CallJsFunction2 #0 6
1407 // 54 54 foo #16 7 1432 // 54 54 foo #16 7
1408 // 2 2 (program) #0 2 1433 // 2 2 (program) #0 2
1409 TEST(JsNative1JsNative2JsSample) { 1434 TEST(JsNative1JsNative2JsSample) {
1410 i::FLAG_allow_natives_syntax = true; 1435 i::FLAG_allow_natives_syntax = true;
1411 v8::HandleScope scope(CcTest::isolate()); 1436 v8::HandleScope scope(CcTest::isolate());
1412 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1437 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1438 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1413 v8::Context::Scope context_scope(env); 1439 v8::Context::Scope context_scope(env);
1414 1440
1415 v8::Local<v8::Function> func1 = 1441 v8::Local<v8::Function> func1 =
1416 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction) 1442 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction)
1417 ->GetFunction(env) 1443 ->GetFunction(env)
1418 .ToLocalChecked(); 1444 .ToLocalChecked();
1419 func1->SetName(v8_str("CallJsFunction1")); 1445 func1->SetName(v8_str("CallJsFunction1"));
1420 env->Global()->Set(env, v8_str("CallJsFunction1"), func1).FromJust(); 1446 env->Global()->Set(env, v8_str("CallJsFunction1"), func1).FromJust();
1421 1447
1422 v8::Local<v8::Function> func2 = 1448 v8::Local<v8::Function> func2 =
1423 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction2) 1449 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction2)
1424 ->GetFunction(env) 1450 ->GetFunction(env)
1425 .ToLocalChecked(); 1451 .ToLocalChecked();
1426 func2->SetName(v8_str("CallJsFunction2")); 1452 func2->SetName(v8_str("CallJsFunction2"));
1427 env->Global()->Set(env, v8_str("CallJsFunction2"), func2).FromJust(); 1453 env->Global()->Set(env, v8_str("CallJsFunction2"), func2).FromJust();
1428 1454
1429 CompileRun(js_native1_js_native2_js_test_source); 1455 CompileRun(js_native1_js_native2_js_test_source);
1456
1457 ProfilerHelper helper(env, profiler_scope.profiler());
1430 v8::Local<v8::Function> function = GetFunction(env, "start"); 1458 v8::Local<v8::Function> function = GetFunction(env, "start");
1431 1459 v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 1000);
1432 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 1000);
1433 1460
1434 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1461 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1435 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1462 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
1436 const v8::CpuProfileNode* native_node1 = 1463 const v8::CpuProfileNode* native_node1 =
1437 GetChild(env, start_node, "CallJsFunction1"); 1464 GetChild(env, start_node, "CallJsFunction1");
1438 const v8::CpuProfileNode* bar_node = GetChild(env, native_node1, "bar"); 1465 const v8::CpuProfileNode* bar_node = GetChild(env, native_node1, "bar");
1439 const v8::CpuProfileNode* native_node2 = 1466 const v8::CpuProfileNode* native_node2 =
1440 GetChild(env, bar_node, "CallJsFunction2"); 1467 GetChild(env, bar_node, "CallJsFunction2");
1441 GetChild(env, native_node2, "foo"); 1468 GetChild(env, native_node2, "foo");
1442 1469
1443 profile->Delete(); 1470 profile->Delete();
1444 } 1471 }
1445 1472
1446 static const char* js_force_collect_sample_source = 1473 static const char* js_force_collect_sample_source =
1447 "function start() {\n" 1474 "function start() {\n"
1448 " CallCollectSample();\n" 1475 " CallCollectSample();\n"
1449 "}"; 1476 "}";
1450 1477
1478 static void CallCollectSample(const v8::FunctionCallbackInfo<v8::Value>& info) {
1479 i::ProfilerExtension::Scope::profiler()->CollectSample();
1480 }
1481
1451 TEST(CollectSampleAPI) { 1482 TEST(CollectSampleAPI) {
1452 v8::HandleScope scope(CcTest::isolate()); 1483 v8::HandleScope scope(CcTest::isolate());
1453 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1484 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1454 v8::Context::Scope context_scope(env); 1485 v8::Context::Scope context_scope(env);
1486 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1455 1487
1456 v8::Local<v8::FunctionTemplate> func_template = 1488 v8::Local<v8::FunctionTemplate> func_template =
1457 v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample); 1489 v8::FunctionTemplate::New(env->GetIsolate(), CallCollectSample);
1458 v8::Local<v8::Function> func = 1490 v8::Local<v8::Function> func =
1459 func_template->GetFunction(env).ToLocalChecked(); 1491 func_template->GetFunction(env).ToLocalChecked();
1460 func->SetName(v8_str("CallCollectSample")); 1492 func->SetName(v8_str("CallCollectSample"));
1461 env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust(); 1493 env->Global()->Set(env, v8_str("CallCollectSample"), func).FromJust();
1462 1494
1463 CompileRun(js_force_collect_sample_source); 1495 CompileRun(js_force_collect_sample_source);
1496 ProfilerHelper helper(env, profiler_scope.profiler());
1464 v8::Local<v8::Function> function = GetFunction(env, "start"); 1497 v8::Local<v8::Function> function = GetFunction(env, "start");
1465 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 0); 1498 v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 0);
1466 1499
1467 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1500 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1468 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1501 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
1469 CHECK_LE(1, start_node->GetChildrenCount()); 1502 CHECK_LE(1, start_node->GetChildrenCount());
1470 GetChild(env, start_node, "CallCollectSample"); 1503 GetChild(env, start_node, "CallCollectSample");
1471 1504
1472 profile->Delete(); 1505 profile->Delete();
1473 } 1506 }
1474 1507
1475 static const char* js_native_js_runtime_multiple_test_source = 1508 static const char* js_native_js_runtime_multiple_test_source =
(...skipping 22 matching lines...) Expand all
1498 // start #16 3 1531 // start #16 3
1499 // CallJsFunction #0 4 1532 // CallJsFunction #0 4
1500 // bar #16 5 1533 // bar #16 5
1501 // foo #16 6 1534 // foo #16 6
1502 // (program) #0 2 1535 // (program) #0 2
1503 TEST(JsNativeJsRuntimeJsSampleMultiple) { 1536 TEST(JsNativeJsRuntimeJsSampleMultiple) {
1504 i::FLAG_allow_natives_syntax = true; 1537 i::FLAG_allow_natives_syntax = true;
1505 v8::HandleScope scope(CcTest::isolate()); 1538 v8::HandleScope scope(CcTest::isolate());
1506 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1539 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1507 v8::Context::Scope context_scope(env); 1540 v8::Context::Scope context_scope(env);
1541 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1508 1542
1509 v8::Local<v8::FunctionTemplate> func_template = 1543 v8::Local<v8::FunctionTemplate> func_template =
1510 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction); 1544 v8::FunctionTemplate::New(env->GetIsolate(), CallJsFunction);
1511 v8::Local<v8::Function> func = 1545 v8::Local<v8::Function> func =
1512 func_template->GetFunction(env).ToLocalChecked(); 1546 func_template->GetFunction(env).ToLocalChecked();
1513 func->SetName(v8_str("CallJsFunction")); 1547 func->SetName(v8_str("CallJsFunction"));
1514 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust(); 1548 env->Global()->Set(env, v8_str("CallJsFunction"), func).FromJust();
1515 1549
1516 CompileRun(js_native_js_runtime_multiple_test_source); 1550 CompileRun(js_native_js_runtime_multiple_test_source);
1551
1552 ProfilerHelper helper(env, profiler_scope.profiler());
1517 v8::Local<v8::Function> function = GetFunction(env, "start"); 1553 v8::Local<v8::Function> function = GetFunction(env, "start");
1518 1554 v8::CpuProfile* profile = helper.Run(function, nullptr, 0, 500, 500);
1519 v8::CpuProfile* profile = RunProfiler(env, function, NULL, 0, 500, 500);
1520 1555
1521 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1556 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1522 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1557 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
1523 const v8::CpuProfileNode* native_node = 1558 const v8::CpuProfileNode* native_node =
1524 GetChild(env, start_node, "CallJsFunction"); 1559 GetChild(env, start_node, "CallJsFunction");
1525 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar"); 1560 const v8::CpuProfileNode* bar_node = GetChild(env, native_node, "bar");
1526 GetChild(env, bar_node, "foo"); 1561 GetChild(env, bar_node, "foo");
1527 1562
1528 profile->Delete(); 1563 profile->Delete();
1529 } 1564 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 // level1 #0 4 1596 // level1 #0 4
1562 // level2 #16 5 1597 // level2 #16 5
1563 // level3 #16 6 1598 // level3 #16 6
1564 // action #16 7 1599 // action #16 7
1565 // (program) #0 2 1600 // (program) #0 2
1566 TEST(Inlining) { 1601 TEST(Inlining) {
1567 i::FLAG_allow_natives_syntax = true; 1602 i::FLAG_allow_natives_syntax = true;
1568 v8::HandleScope scope(CcTest::isolate()); 1603 v8::HandleScope scope(CcTest::isolate());
1569 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1604 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1570 v8::Context::Scope context_scope(env); 1605 v8::Context::Scope context_scope(env);
1606 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1571 1607
1572 CompileRun(inlining_test_source); 1608 CompileRun(inlining_test_source);
1573 v8::Local<v8::Function> function = GetFunction(env, "start"); 1609 v8::Local<v8::Function> function = GetFunction(env, "start");
1574 1610
1575 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
1576 v8::Local<v8::String> profile_name = v8_str("my_profile"); 1611 v8::Local<v8::String> profile_name = v8_str("my_profile");
1577 function->Call(env, env->Global(), 0, NULL).ToLocalChecked(); 1612 function->Call(env, env->Global(), 0, NULL).ToLocalChecked();
1578 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 1613 v8::CpuProfile* profile =
1614 profiler_scope.profiler()->StopProfiling(profile_name);
1579 CHECK(profile); 1615 CHECK(profile);
1580 // Dump collected profile to have a better diagnostic in case of failure. 1616 // Dump collected profile to have a better diagnostic in case of failure.
1581 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 1617 reinterpret_cast<i::CpuProfile*>(profile)->Print();
1582 1618
1583 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1619 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1584 const v8::CpuProfileNode* start_node = GetChild(env, root, "start"); 1620 const v8::CpuProfileNode* start_node = GetChild(env, root, "start");
1585 const v8::CpuProfileNode* level1_node = GetChild(env, start_node, "level1"); 1621 const v8::CpuProfileNode* level1_node = GetChild(env, start_node, "level1");
1586 const v8::CpuProfileNode* level2_node = GetChild(env, level1_node, "level2"); 1622 const v8::CpuProfileNode* level2_node = GetChild(env, level1_node, "level2");
1587 const v8::CpuProfileNode* level3_node = GetChild(env, level2_node, "level3"); 1623 const v8::CpuProfileNode* level3_node = GetChild(env, level2_node, "level3");
1588 GetChild(env, level3_node, "action"); 1624 GetChild(env, level3_node, "action");
1589 1625
1590 profile->Delete(); 1626 profile->Delete();
1591 } 1627 }
1592 1628
1593 // [Top down]: 1629 // [Top down]:
1594 // 0 (root) #0 1 1630 // 0 (root) #0 1
1595 // 2 (program) #0 2 1631 // 2 (program) #0 2
1596 // 3 (idle) #0 3 1632 // 3 (idle) #0 3
1597 TEST(IdleTime) { 1633 TEST(IdleTime) {
1598 LocalContext env; 1634 LocalContext env;
1599 v8::HandleScope scope(env->GetIsolate()); 1635 v8::HandleScope scope(env->GetIsolate());
1600 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 1636 v8::CpuProfiler* cpu_profiler = v8::CpuProfiler::New(env->GetIsolate());
1601 1637
1602 v8::Local<v8::String> profile_name = v8_str("my_profile"); 1638 v8::Local<v8::String> profile_name = v8_str("my_profile");
1603 cpu_profiler->StartProfiling(profile_name); 1639 cpu_profiler->StartProfiling(profile_name);
1604 1640
1605 i::Isolate* isolate = CcTest::i_isolate(); 1641 i::Isolate* isolate = CcTest::i_isolate();
1606 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); 1642 i::ProfilerEventsProcessor* processor =
1643 reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->processor();
1607 1644
1608 processor->AddCurrentStack(isolate, true); 1645 processor->AddCurrentStack(isolate, true);
1609 cpu_profiler->SetIdle(true); 1646 cpu_profiler->SetIdle(true);
1610 for (int i = 0; i < 3; i++) { 1647 for (int i = 0; i < 3; i++) {
1611 processor->AddCurrentStack(isolate, true); 1648 processor->AddCurrentStack(isolate, true);
1612 } 1649 }
1613 cpu_profiler->SetIdle(false); 1650 cpu_profiler->SetIdle(false);
1614 processor->AddCurrentStack(isolate, true); 1651 processor->AddCurrentStack(isolate, true);
1615 1652
1616 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name); 1653 v8::CpuProfile* profile = cpu_profiler->StopProfiling(profile_name);
1617 CHECK(profile); 1654 CHECK(profile);
1618 // Dump collected profile to have a better diagnostic in case of failure. 1655 // Dump collected profile to have a better diagnostic in case of failure.
1619 reinterpret_cast<i::CpuProfile*>(profile)->Print(); 1656 reinterpret_cast<i::CpuProfile*>(profile)->Print();
1620 1657
1621 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); 1658 const v8::CpuProfileNode* root = profile->GetTopDownRoot();
1622 const v8::CpuProfileNode* program_node = 1659 const v8::CpuProfileNode* program_node =
1623 GetChild(env.local(), root, CodeEntry::kProgramEntryName); 1660 GetChild(env.local(), root, CodeEntry::kProgramEntryName);
1624 CHECK_EQ(0, program_node->GetChildrenCount()); 1661 CHECK_EQ(0, program_node->GetChildrenCount());
1625 CHECK_GE(program_node->GetHitCount(), 2u); 1662 CHECK_GE(program_node->GetHitCount(), 2u);
1626 1663
1627 const v8::CpuProfileNode* idle_node = 1664 const v8::CpuProfileNode* idle_node =
1628 GetChild(env.local(), root, CodeEntry::kIdleEntryName); 1665 GetChild(env.local(), root, CodeEntry::kIdleEntryName);
1629 CHECK_EQ(0, idle_node->GetChildrenCount()); 1666 CHECK_EQ(0, idle_node->GetChildrenCount());
1630 CHECK_GE(idle_node->GetHitCount(), 3u); 1667 CHECK_GE(idle_node->GetHitCount(), 3u);
1631 1668
1632 profile->Delete(); 1669 profile->Delete();
1670 cpu_profiler->Dispose();
1633 } 1671 }
1634 1672
1635 static void CheckFunctionDetails(v8::Isolate* isolate, 1673 static void CheckFunctionDetails(v8::Isolate* isolate,
1636 const v8::CpuProfileNode* node, 1674 const v8::CpuProfileNode* node,
1637 const char* name, const char* script_name, 1675 const char* name, const char* script_name,
1638 int script_id, int line, int column) { 1676 int script_id, int line, int column) {
1639 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 1677 v8::Local<v8::Context> context = isolate->GetCurrentContext();
1640 CHECK(v8_str(name)->Equals(context, node->GetFunctionName()).FromJust()); 1678 CHECK(v8_str(name)->Equals(context, node->GetFunctionName()).FromJust());
1641 CHECK(v8_str(script_name) 1679 CHECK(v8_str(script_name)
1642 ->Equals(context, node->GetScriptResourceName()) 1680 ->Equals(context, node->GetScriptResourceName())
1643 .FromJust()); 1681 .FromJust());
1644 CHECK_EQ(script_id, node->GetScriptId()); 1682 CHECK_EQ(script_id, node->GetScriptId());
1645 CHECK_EQ(line, node->GetLineNumber()); 1683 CHECK_EQ(line, node->GetLineNumber());
1646 CHECK_EQ(column, node->GetColumnNumber()); 1684 CHECK_EQ(column, node->GetColumnNumber());
1647 } 1685 }
1648 1686
1649 1687
1650 TEST(FunctionDetails) { 1688 TEST(FunctionDetails) {
1651 i::FLAG_allow_natives_syntax = true; 1689 i::FLAG_allow_natives_syntax = true;
1652 v8::HandleScope scope(CcTest::isolate()); 1690 v8::HandleScope scope(CcTest::isolate());
1653 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1691 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1654 v8::Context::Scope context_scope(env); 1692 v8::Context::Scope context_scope(env);
1693 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1655 1694
1656 v8::Local<v8::Script> script_a = CompileWithOrigin( 1695 v8::Local<v8::Script> script_a = CompileWithOrigin(
1657 "%NeverOptimizeFunction(foo);\n" 1696 "%NeverOptimizeFunction(foo);\n"
1658 "%NeverOptimizeFunction(bar);\n" 1697 "%NeverOptimizeFunction(bar);\n"
1659 " function foo\n() { bar(); }\n" 1698 " function foo\n() { bar(); }\n"
1660 " function bar() { startProfiling(); }\n", 1699 " function bar() { startProfiling(); }\n",
1661 "script_a"); 1700 "script_a");
1662 script_a->Run(env).ToLocalChecked(); 1701 script_a->Run(env).ToLocalChecked();
1663 v8::Local<v8::Script> script_b = CompileWithOrigin( 1702 v8::Local<v8::Script> script_b = CompileWithOrigin(
1664 "%NeverOptimizeFunction(baz);" 1703 "%NeverOptimizeFunction(baz);"
(...skipping 26 matching lines...) Expand all
1691 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a", 1730 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a",
1692 script_a->GetUnboundScript()->GetId(), 5, 14); 1731 script_a->GetUnboundScript()->GetId(), 5, 14);
1693 } 1732 }
1694 1733
1695 1734
1696 TEST(DontStopOnFinishedProfileDelete) { 1735 TEST(DontStopOnFinishedProfileDelete) {
1697 v8::HandleScope scope(CcTest::isolate()); 1736 v8::HandleScope scope(CcTest::isolate());
1698 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1737 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1699 v8::Context::Scope context_scope(env); 1738 v8::Context::Scope context_scope(env);
1700 1739
1701 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); 1740 v8::CpuProfiler* profiler = v8::CpuProfiler::New(env->GetIsolate());
1702 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 1741 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler);
1703 1742
1704 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1743 CHECK_EQ(0, iprofiler->GetProfilesCount());
1705 v8::Local<v8::String> outer = v8_str("outer"); 1744 v8::Local<v8::String> outer = v8_str("outer");
1706 profiler->StartProfiling(outer); 1745 profiler->StartProfiling(outer);
1707 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1746 CHECK_EQ(0, iprofiler->GetProfilesCount());
1708 1747
1709 v8::Local<v8::String> inner = v8_str("inner"); 1748 v8::Local<v8::String> inner = v8_str("inner");
1710 profiler->StartProfiling(inner); 1749 profiler->StartProfiling(inner);
1711 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1750 CHECK_EQ(0, iprofiler->GetProfilesCount());
1712 1751
1713 v8::CpuProfile* inner_profile = profiler->StopProfiling(inner); 1752 v8::CpuProfile* inner_profile = profiler->StopProfiling(inner);
1714 CHECK(inner_profile); 1753 CHECK(inner_profile);
1715 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1754 CHECK_EQ(1, iprofiler->GetProfilesCount());
1716 inner_profile->Delete(); 1755 inner_profile->Delete();
1717 inner_profile = NULL; 1756 inner_profile = NULL;
1718 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1757 CHECK_EQ(0, iprofiler->GetProfilesCount());
1719 1758
1720 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); 1759 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer);
1721 CHECK(outer_profile); 1760 CHECK(outer_profile);
1722 CHECK_EQ(1, iprofiler->GetProfilesCount()); 1761 CHECK_EQ(1, iprofiler->GetProfilesCount());
1723 outer_profile->Delete(); 1762 outer_profile->Delete();
1724 outer_profile = NULL; 1763 outer_profile = NULL;
1725 CHECK_EQ(0, iprofiler->GetProfilesCount()); 1764 CHECK_EQ(0, iprofiler->GetProfilesCount());
1765 profiler->Dispose();
1726 } 1766 }
1727 1767
1728 1768
1729 const char* GetBranchDeoptReason(v8::Local<v8::Context> context, 1769 const char* GetBranchDeoptReason(v8::Local<v8::Context> context,
1730 i::CpuProfile* iprofile, const char* branch[], 1770 i::CpuProfile* iprofile, const char* branch[],
1731 int length) { 1771 int length) {
1732 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 1772 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
1733 const ProfileNode* iopt_function = NULL; 1773 const ProfileNode* iopt_function = NULL;
1734 iopt_function = GetSimpleBranch(context, profile, branch, length); 1774 iopt_function = GetSimpleBranch(context, profile, branch, length);
1735 CHECK_EQ(1U, iopt_function->deopt_infos().size()); 1775 CHECK_EQ(1U, iopt_function->deopt_infos().size());
1736 return iopt_function->deopt_infos()[0].deopt_reason; 1776 return iopt_function->deopt_infos()[0].deopt_reason;
1737 } 1777 }
1738 1778
1739 1779
1740 // deopt at top function 1780 // deopt at top function
1741 TEST(CollectDeoptEvents) { 1781 TEST(CollectDeoptEvents) {
1742 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 1782 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
1743 i::FLAG_allow_natives_syntax = true; 1783 i::FLAG_allow_natives_syntax = true;
1744 v8::HandleScope scope(CcTest::isolate()); 1784 v8::HandleScope scope(CcTest::isolate());
1745 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1785 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1746 v8::Context::Scope context_scope(env); 1786 v8::Context::Scope context_scope(env);
1747 v8::Isolate* isolate = env->GetIsolate(); 1787 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1748 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); 1788 i::CpuProfiler* iprofiler =
1749 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 1789 reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler());
1750 1790
1751 const char opt_source[] = 1791 const char opt_source[] =
1752 "function opt_function%d(value, depth) {\n" 1792 "function opt_function%d(value, depth) {\n"
1753 " if (depth) return opt_function%d(value, depth - 1);\n" 1793 " if (depth) return opt_function%d(value, depth - 1);\n"
1754 "\n" 1794 "\n"
1755 " return 10 / value;\n" 1795 " return 10 / value;\n"
1756 "}\n" 1796 "}\n"
1757 "\n"; 1797 "\n";
1758 1798
1759 for (int i = 0; i < 3; ++i) { 1799 for (int i = 0; i < 3; ++i) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 // 0.........1.........2.........3.........4....*....5.........6......*..7 1907 // 0.........1.........2.........3.........4....*....5.........6......*..7
1868 1908
1869 1909
1870 // deopt at the first level inlined function 1910 // deopt at the first level inlined function
1871 TEST(DeoptAtFirstLevelInlinedSource) { 1911 TEST(DeoptAtFirstLevelInlinedSource) {
1872 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 1912 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
1873 i::FLAG_allow_natives_syntax = true; 1913 i::FLAG_allow_natives_syntax = true;
1874 v8::HandleScope scope(CcTest::isolate()); 1914 v8::HandleScope scope(CcTest::isolate());
1875 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1915 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1876 v8::Context::Scope context_scope(env); 1916 v8::Context::Scope context_scope(env);
1877 v8::Isolate* isolate = env->GetIsolate(); 1917 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1878 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); 1918 i::CpuProfiler* iprofiler =
1879 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 1919 reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler());
1880 1920
1881 // 0.........1.........2.........3.........4.........5.........6.........7 1921 // 0.........1.........2.........3.........4.........5.........6.........7
1882 const char* source = 1922 const char* source =
1883 "function test(left, right) { return opt_function(left, right); }\n" 1923 "function test(left, right) { return opt_function(left, right); }\n"
1884 "\n" 1924 "\n"
1885 "startProfiling();\n" 1925 "startProfiling();\n"
1886 "\n" 1926 "\n"
1887 "test(10, 10);\n" 1927 "test(10, 10);\n"
1888 "\n" 1928 "\n"
1889 "%OptimizeFunctionOnNextCall(test)\n" 1929 "%OptimizeFunctionOnNextCall(test)\n"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 } 1976 }
1937 1977
1938 1978
1939 // deopt at the second level inlined function 1979 // deopt at the second level inlined function
1940 TEST(DeoptAtSecondLevelInlinedSource) { 1980 TEST(DeoptAtSecondLevelInlinedSource) {
1941 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 1981 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
1942 i::FLAG_allow_natives_syntax = true; 1982 i::FLAG_allow_natives_syntax = true;
1943 v8::HandleScope scope(CcTest::isolate()); 1983 v8::HandleScope scope(CcTest::isolate());
1944 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 1984 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
1945 v8::Context::Scope context_scope(env); 1985 v8::Context::Scope context_scope(env);
1946 v8::Isolate* isolate = env->GetIsolate(); 1986 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
1947 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); 1987 i::CpuProfiler* iprofiler =
1948 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 1988 reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler());
1949 1989
1950 // 0.........1.........2.........3.........4.........5.........6.........7 1990 // 0.........1.........2.........3.........4.........5.........6.........7
1951 const char* source = 1991 const char* source =
1952 "function test2(left, right) { return opt_function(left, right); }\n" 1992 "function test2(left, right) { return opt_function(left, right); }\n"
1953 "function test1(left, right) { return test2(left, right); }\n" 1993 "function test1(left, right) { return test2(left, right); }\n"
1954 "\n" 1994 "\n"
1955 "startProfiling();\n" 1995 "startProfiling();\n"
1956 "\n" 1996 "\n"
1957 "test1(10, 10);\n" 1997 "test1(10, 10);\n"
1958 "\n" 1998 "\n"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 } 2050 }
2011 2051
2012 2052
2013 // deopt in untracked function 2053 // deopt in untracked function
2014 TEST(DeoptUntrackedFunction) { 2054 TEST(DeoptUntrackedFunction) {
2015 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 2055 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
2016 i::FLAG_allow_natives_syntax = true; 2056 i::FLAG_allow_natives_syntax = true;
2017 v8::HandleScope scope(CcTest::isolate()); 2057 v8::HandleScope scope(CcTest::isolate());
2018 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION); 2058 v8::Local<v8::Context> env = CcTest::NewContext(PROFILER_EXTENSION);
2019 v8::Context::Scope context_scope(env); 2059 v8::Context::Scope context_scope(env);
2020 v8::Isolate* isolate = env->GetIsolate(); 2060 v8::internal::ProfilerExtension::Scope profiler_scope(CcTest::isolate());
2021 v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); 2061 i::CpuProfiler* iprofiler =
2022 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); 2062 reinterpret_cast<i::CpuProfiler*>(profiler_scope.profiler());
2023 2063
2024 // 0.........1.........2.........3.........4.........5.........6.........7 2064 // 0.........1.........2.........3.........4.........5.........6.........7
2025 const char* source = 2065 const char* source =
2026 "function test(left, right) { return opt_function(left, right); }\n" 2066 "function test(left, right) { return opt_function(left, right); }\n"
2027 "\n" 2067 "\n"
2028 "test(10, 10);\n" 2068 "test(10, 10);\n"
2029 "\n" 2069 "\n"
2030 "%OptimizeFunctionOnNextCall(test)\n" 2070 "%OptimizeFunctionOnNextCall(test)\n"
2031 "\n" 2071 "\n"
2032 "test(10, 10);\n" 2072 "test(10, 10);\n"
(...skipping 15 matching lines...) Expand all
2048 iprofile->Print(); 2088 iprofile->Print();
2049 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile); 2089 v8::CpuProfile* profile = reinterpret_cast<v8::CpuProfile*>(iprofile);
2050 2090
2051 const char* branch[] = {"", "test"}; 2091 const char* branch[] = {"", "test"};
2052 const ProfileNode* itest_node = 2092 const ProfileNode* itest_node =
2053 GetSimpleBranch(env, profile, branch, arraysize(branch)); 2093 GetSimpleBranch(env, profile, branch, arraysize(branch));
2054 CHECK_EQ(0U, itest_node->deopt_infos().size()); 2094 CHECK_EQ(0U, itest_node->deopt_infos().size());
2055 2095
2056 iprofiler->DeleteProfile(iprofile); 2096 iprofiler->DeleteProfile(iprofile);
2057 } 2097 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698