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