| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 return NULL; | 348 return NULL; |
| 349 } | 349 } |
| 350 | 350 |
| 351 | 351 |
| 352 TEST(DeleteCpuProfile) { | 352 TEST(DeleteCpuProfile) { |
| 353 LocalContext env; | 353 LocalContext env; |
| 354 v8::HandleScope scope(env->GetIsolate()); | 354 v8::HandleScope scope(env->GetIsolate()); |
| 355 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 355 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 356 | 356 |
| 357 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 357 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
| 358 v8::Local<v8::String> name1 = v8::String::New("1"); | 358 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1"); |
| 359 cpu_profiler->StartCpuProfiling(name1); | 359 cpu_profiler->StartCpuProfiling(name1); |
| 360 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); | 360 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); |
| 361 CHECK_NE(NULL, p1); | 361 CHECK_NE(NULL, p1); |
| 362 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | 362 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 363 unsigned uid1 = p1->GetUid(); | 363 unsigned uid1 = p1->GetUid(); |
| 364 CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1)); | 364 CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1)); |
| 365 const_cast<v8::CpuProfile*>(p1)->Delete(); | 365 const_cast<v8::CpuProfile*>(p1)->Delete(); |
| 366 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 366 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
| 367 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | 367 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); |
| 368 | 368 |
| 369 v8::Local<v8::String> name2 = v8::String::New("2"); | 369 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2"); |
| 370 cpu_profiler->StartCpuProfiling(name2); | 370 cpu_profiler->StartCpuProfiling(name2); |
| 371 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2); | 371 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2); |
| 372 CHECK_NE(NULL, p2); | 372 CHECK_NE(NULL, p2); |
| 373 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | 373 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 374 unsigned uid2 = p2->GetUid(); | 374 unsigned uid2 = p2->GetUid(); |
| 375 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); | 375 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); |
| 376 CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2)); | 376 CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2)); |
| 377 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | 377 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); |
| 378 v8::Local<v8::String> name3 = v8::String::New("3"); | 378 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3"); |
| 379 cpu_profiler->StartCpuProfiling(name3); | 379 cpu_profiler->StartCpuProfiling(name3); |
| 380 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); | 380 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); |
| 381 CHECK_NE(NULL, p3); | 381 CHECK_NE(NULL, p3); |
| 382 CHECK_EQ(2, cpu_profiler->GetProfileCount()); | 382 CHECK_EQ(2, cpu_profiler->GetProfileCount()); |
| 383 unsigned uid3 = p3->GetUid(); | 383 unsigned uid3 = p3->GetUid(); |
| 384 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); | 384 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); |
| 385 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); | 385 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); |
| 386 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | 386 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); |
| 387 const_cast<v8::CpuProfile*>(p2)->Delete(); | 387 const_cast<v8::CpuProfile*>(p2)->Delete(); |
| 388 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | 388 CHECK_EQ(1, cpu_profiler->GetProfileCount()); |
| 389 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); | 389 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); |
| 390 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); | 390 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); |
| 391 const_cast<v8::CpuProfile*>(p3)->Delete(); | 391 const_cast<v8::CpuProfile*>(p3)->Delete(); |
| 392 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 392 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
| 393 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3)); | 393 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3)); |
| 394 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); | 394 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); |
| 395 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | 395 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); |
| 396 } | 396 } |
| 397 | 397 |
| 398 | 398 |
| 399 TEST(ProfileStartEndTime) { | 399 TEST(ProfileStartEndTime) { |
| 400 LocalContext env; | 400 LocalContext env; |
| 401 v8::HandleScope scope(env->GetIsolate()); | 401 v8::HandleScope scope(env->GetIsolate()); |
| 402 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 402 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 403 | 403 |
| 404 v8::Local<v8::String> profile_name = v8::String::New("test"); | 404 v8::Local<v8::String> profile_name = |
| 405 v8::String::NewFromUtf8(env->GetIsolate(), "test"); |
| 405 cpu_profiler->StartCpuProfiling(profile_name); | 406 cpu_profiler->StartCpuProfiling(profile_name); |
| 406 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 407 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 407 CHECK(profile->GetStartTime() <= profile->GetEndTime()); | 408 CHECK(profile->GetStartTime() <= profile->GetEndTime()); |
| 408 } | 409 } |
| 409 | 410 |
| 410 | 411 |
| 411 static const v8::CpuProfile* RunProfiler( | 412 static const v8::CpuProfile* RunProfiler( |
| 412 LocalContext& env, v8::Handle<v8::Function> function, | 413 LocalContext& env, v8::Handle<v8::Function> function, |
| 413 v8::Handle<v8::Value> argv[], int argc, | 414 v8::Handle<v8::Value> argv[], int argc, |
| 414 unsigned min_js_samples) { | 415 unsigned min_js_samples) { |
| 415 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 416 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 416 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 417 v8::Local<v8::String> profile_name = |
| 418 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
| 417 | 419 |
| 418 cpu_profiler->StartCpuProfiling(profile_name); | 420 cpu_profiler->StartCpuProfiling(profile_name); |
| 419 | 421 |
| 420 i::Sampler* sampler = | 422 i::Sampler* sampler = |
| 421 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); | 423 reinterpret_cast<i::Isolate*>(env->GetIsolate())->logger()->sampler(); |
| 422 sampler->StartCountingSamples(); | 424 sampler->StartCountingSamples(); |
| 423 do { | 425 do { |
| 424 function->Call(env->Global(), argc, argv); | 426 function->Call(env->Global(), argc, argv); |
| 425 } while (sampler->js_and_external_sample_count() < min_js_samples); | 427 } while (sampler->js_and_external_sample_count() < min_js_samples); |
| 426 | 428 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 453 CHECK(ContainsString(name, names)); | 455 CHECK(ContainsString(name, names)); |
| 454 // Check that there are no duplicates. | 456 // Check that there are no duplicates. |
| 455 for (int j = 0; j < count; j++) { | 457 for (int j = 0; j < count; j++) { |
| 456 if (j == i) continue; | 458 if (j == i) continue; |
| 457 CHECK_NE(name, node->GetChild(j)->GetFunctionName()); | 459 CHECK_NE(name, node->GetChild(j)->GetFunctionName()); |
| 458 } | 460 } |
| 459 } | 461 } |
| 460 } | 462 } |
| 461 | 463 |
| 462 | 464 |
| 463 static const v8::CpuProfileNode* FindChild(const v8::CpuProfileNode* node, | 465 static const v8::CpuProfileNode* FindChild(v8::Isolate* isolate, |
| 466 const v8::CpuProfileNode* node, |
| 464 const char* name) { | 467 const char* name) { |
| 465 int count = node->GetChildrenCount(); | 468 int count = node->GetChildrenCount(); |
| 466 v8::Handle<v8::String> nameHandle = v8::String::New(name); | 469 v8::Handle<v8::String> nameHandle = v8::String::NewFromUtf8(isolate, name); |
| 467 for (int i = 0; i < count; i++) { | 470 for (int i = 0; i < count; i++) { |
| 468 const v8::CpuProfileNode* child = node->GetChild(i); | 471 const v8::CpuProfileNode* child = node->GetChild(i); |
| 469 if (nameHandle->Equals(child->GetFunctionName())) return child; | 472 if (nameHandle->Equals(child->GetFunctionName())) return child; |
| 470 } | 473 } |
| 471 return NULL; | 474 return NULL; |
| 472 } | 475 } |
| 473 | 476 |
| 474 | 477 |
| 475 static const v8::CpuProfileNode* GetChild(const v8::CpuProfileNode* node, | 478 static const v8::CpuProfileNode* GetChild(v8::Isolate* isolate, |
| 479 const v8::CpuProfileNode* node, |
| 476 const char* name) { | 480 const char* name) { |
| 477 const v8::CpuProfileNode* result = FindChild(node, name); | 481 const v8::CpuProfileNode* result = FindChild(isolate, node, name); |
| 478 if (!result) { | 482 if (!result) { |
| 479 char buffer[100]; | 483 char buffer[100]; |
| 480 i::OS::SNPrintF(Vector<char>(buffer, ARRAY_SIZE(buffer)), | 484 i::OS::SNPrintF(Vector<char>(buffer, ARRAY_SIZE(buffer)), |
| 481 "Failed to GetChild: %s", name); | 485 "Failed to GetChild: %s", name); |
| 482 FATAL(buffer); | 486 FATAL(buffer); |
| 483 } | 487 } |
| 484 return result; | 488 return result; |
| 485 } | 489 } |
| 486 | 490 |
| 487 | 491 |
| 488 static void CheckSimpleBranch(const v8::CpuProfileNode* node, | 492 static void CheckSimpleBranch(v8::Isolate* isolate, |
| 493 const v8::CpuProfileNode* node, |
| 489 const char* names[], int length) { | 494 const char* names[], int length) { |
| 490 for (int i = 0; i < length; i++) { | 495 for (int i = 0; i < length; i++) { |
| 491 const char* name = names[i]; | 496 const char* name = names[i]; |
| 492 node = GetChild(node, name); | 497 node = GetChild(isolate, node, name); |
| 493 int expectedChildrenCount = (i == length - 1) ? 0 : 1; | 498 int expectedChildrenCount = (i == length - 1) ? 0 : 1; |
| 494 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); | 499 CHECK_EQ(expectedChildrenCount, node->GetChildrenCount()); |
| 495 } | 500 } |
| 496 } | 501 } |
| 497 | 502 |
| 498 | 503 |
| 499 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" | 504 static const char* cpu_profiler_test_source = "function loop(timeout) {\n" |
| 500 " this.mmm = 0;\n" | 505 " this.mmm = 0;\n" |
| 501 " var start = Date.now();\n" | 506 " var start = Date.now();\n" |
| 502 " while (Date.now() - start < timeout) {\n" | 507 " while (Date.now() - start < timeout) {\n" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 // 522 522 loop [-1] | 547 // 522 522 loop [-1] |
| 543 // 263 0 bar [-1] | 548 // 263 0 bar [-1] |
| 544 // 263 1 delay [-1] | 549 // 263 1 delay [-1] |
| 545 // 262 262 loop [-1] | 550 // 262 262 loop [-1] |
| 546 // 2 2 (program) [-1] | 551 // 2 2 (program) [-1] |
| 547 // 6 6 (garbage collector) [-1] | 552 // 6 6 (garbage collector) [-1] |
| 548 TEST(CollectCpuProfile) { | 553 TEST(CollectCpuProfile) { |
| 549 LocalContext env; | 554 LocalContext env; |
| 550 v8::HandleScope scope(env->GetIsolate()); | 555 v8::HandleScope scope(env->GetIsolate()); |
| 551 | 556 |
| 552 v8::Script::Compile(v8::String::New(cpu_profiler_test_source))->Run(); | 557 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
| 558 cpu_profiler_test_source))->Run(); |
| 553 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 559 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 554 env->Global()->Get(v8::String::New("start"))); | 560 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 555 | 561 |
| 556 int32_t profiling_interval_ms = 200; | 562 int32_t profiling_interval_ms = 200; |
| 557 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; | 563 v8::Handle<v8::Value> args[] = { v8::Integer::New(profiling_interval_ms) }; |
| 558 const v8::CpuProfile* profile = | 564 const v8::CpuProfile* profile = |
| 559 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); | 565 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); |
| 560 function->Call(env->Global(), ARRAY_SIZE(args), args); | 566 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 561 | 567 |
| 562 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 568 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 563 | 569 |
| 564 ScopedVector<v8::Handle<v8::String> > names(3); | 570 ScopedVector<v8::Handle<v8::String> > names(3); |
| 565 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 571 names[0] = v8::String::NewFromUtf8( |
| 566 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 572 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 567 names[2] = v8::String::New("start"); | 573 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 574 ProfileGenerator::kProgramEntryName); |
| 575 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 568 CheckChildrenNames(root, names); | 576 CheckChildrenNames(root, names); |
| 569 | 577 |
| 570 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 578 const v8::CpuProfileNode* startNode = |
| 579 GetChild(env->GetIsolate(), root, "start"); |
| 571 CHECK_EQ(1, startNode->GetChildrenCount()); | 580 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 572 | 581 |
| 573 const v8::CpuProfileNode* fooNode = GetChild(startNode, "foo"); | 582 const v8::CpuProfileNode* fooNode = |
| 583 GetChild(env->GetIsolate(), startNode, "foo"); |
| 574 CHECK_EQ(3, fooNode->GetChildrenCount()); | 584 CHECK_EQ(3, fooNode->GetChildrenCount()); |
| 575 | 585 |
| 576 const char* barBranch[] = { "bar", "delay", "loop" }; | 586 const char* barBranch[] = { "bar", "delay", "loop" }; |
| 577 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); | 587 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, |
| 588 ARRAY_SIZE(barBranch)); |
| 578 const char* bazBranch[] = { "baz", "delay", "loop" }; | 589 const char* bazBranch[] = { "baz", "delay", "loop" }; |
| 579 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); | 590 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, |
| 591 ARRAY_SIZE(bazBranch)); |
| 580 const char* delayBranch[] = { "delay", "loop" }; | 592 const char* delayBranch[] = { "delay", "loop" }; |
| 581 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); | 593 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, |
| 594 ARRAY_SIZE(delayBranch)); |
| 582 | 595 |
| 583 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 596 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 584 cpu_profiler->DeleteAllCpuProfiles(); | 597 cpu_profiler->DeleteAllCpuProfiles(); |
| 585 } | 598 } |
| 586 | 599 |
| 587 | 600 |
| 588 | 601 |
| 589 static const char* cpu_profiler_test_source2 = "function loop() {}\n" | 602 static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
| 590 "function delay() { loop(); }\n" | 603 "function delay() { loop(); }\n" |
| 591 "function start(count) {\n" | 604 "function start(count) {\n" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 603 // [Top down]: | 616 // [Top down]: |
| 604 // 135 0 (root) [-1] #1 | 617 // 135 0 (root) [-1] #1 |
| 605 // 121 72 start [-1] #3 | 618 // 121 72 start [-1] #3 |
| 606 // 49 33 delay [-1] #4 | 619 // 49 33 delay [-1] #4 |
| 607 // 16 16 loop [-1] #5 | 620 // 16 16 loop [-1] #5 |
| 608 // 14 14 (program) [-1] #2 | 621 // 14 14 (program) [-1] #2 |
| 609 TEST(SampleWhenFrameIsNotSetup) { | 622 TEST(SampleWhenFrameIsNotSetup) { |
| 610 LocalContext env; | 623 LocalContext env; |
| 611 v8::HandleScope scope(env->GetIsolate()); | 624 v8::HandleScope scope(env->GetIsolate()); |
| 612 | 625 |
| 613 v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run(); | 626 v8::Script::Compile(v8::String::NewFromUtf8( |
| 627 env->GetIsolate(), cpu_profiler_test_source2))->Run(); |
| 614 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 628 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 615 env->Global()->Get(v8::String::New("start"))); | 629 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 616 | 630 |
| 617 int32_t repeat_count = 100; | 631 int32_t repeat_count = 100; |
| 618 #if defined(USE_SIMULATOR) | 632 #if defined(USE_SIMULATOR) |
| 619 // Simulators are much slower. | 633 // Simulators are much slower. |
| 620 repeat_count = 1; | 634 repeat_count = 1; |
| 621 #endif | 635 #endif |
| 622 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 636 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 623 const v8::CpuProfile* profile = | 637 const v8::CpuProfile* profile = |
| 624 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 638 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 625 | 639 |
| 626 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 640 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 627 | 641 |
| 628 ScopedVector<v8::Handle<v8::String> > names(3); | 642 ScopedVector<v8::Handle<v8::String> > names(3); |
| 629 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 643 names[0] = v8::String::NewFromUtf8( |
| 630 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 644 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 631 names[2] = v8::String::New("start"); | 645 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 646 ProfileGenerator::kProgramEntryName); |
| 647 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 632 CheckChildrenNames(root, names); | 648 CheckChildrenNames(root, names); |
| 633 | 649 |
| 634 const v8::CpuProfileNode* startNode = FindChild(root, "start"); | 650 const v8::CpuProfileNode* startNode = |
| 651 FindChild(env->GetIsolate(), root, "start"); |
| 635 // On slow machines there may be no meaningfull samples at all, skip the | 652 // On slow machines there may be no meaningfull samples at all, skip the |
| 636 // check there. | 653 // check there. |
| 637 if (startNode && startNode->GetChildrenCount() > 0) { | 654 if (startNode && startNode->GetChildrenCount() > 0) { |
| 638 CHECK_EQ(1, startNode->GetChildrenCount()); | 655 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 639 const v8::CpuProfileNode* delayNode = GetChild(startNode, "delay"); | 656 const v8::CpuProfileNode* delayNode = |
| 657 GetChild(env->GetIsolate(), startNode, "delay"); |
| 640 if (delayNode->GetChildrenCount() > 0) { | 658 if (delayNode->GetChildrenCount() > 0) { |
| 641 CHECK_EQ(1, delayNode->GetChildrenCount()); | 659 CHECK_EQ(1, delayNode->GetChildrenCount()); |
| 642 GetChild(delayNode, "loop"); | 660 GetChild(env->GetIsolate(), delayNode, "loop"); |
| 643 } | 661 } |
| 644 } | 662 } |
| 645 | 663 |
| 646 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 664 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 647 cpu_profiler->DeleteAllCpuProfiles(); | 665 cpu_profiler->DeleteAllCpuProfiles(); |
| 648 } | 666 } |
| 649 | 667 |
| 650 | 668 |
| 651 static const char* native_accessor_test_source = "function start(count) {\n" | 669 static const char* native_accessor_test_source = "function start(count) {\n" |
| 652 " for (var i = 0; i < count; i++) {\n" | 670 " for (var i = 0; i < count; i++) {\n" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 732 |
| 715 | 733 |
| 716 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 734 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); |
| 717 v8::Local<v8::ObjectTemplate> instance_template = | 735 v8::Local<v8::ObjectTemplate> instance_template = |
| 718 func_template->InstanceTemplate(); | 736 func_template->InstanceTemplate(); |
| 719 | 737 |
| 720 TestApiCallbacks accessors(100); | 738 TestApiCallbacks accessors(100); |
| 721 v8::Local<v8::External> data = | 739 v8::Local<v8::External> data = |
| 722 v8::External::New(env->GetIsolate(), &accessors); | 740 v8::External::New(env->GetIsolate(), &accessors); |
| 723 instance_template->SetAccessor( | 741 instance_template->SetAccessor( |
| 724 v8::String::New("foo"), &TestApiCallbacks::Getter, | 742 v8::String::NewFromUtf8(env->GetIsolate(), "foo"), |
| 725 &TestApiCallbacks::Setter, data); | 743 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); |
| 726 v8::Local<v8::Function> func = func_template->GetFunction(); | 744 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 727 v8::Local<v8::Object> instance = func->NewInstance(); | 745 v8::Local<v8::Object> instance = func->NewInstance(); |
| 728 env->Global()->Set(v8::String::New("instance"), instance); | 746 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), |
| 747 instance); |
| 729 | 748 |
| 730 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run(); | 749 v8::Script::Compile( |
| 750 v8::String::NewFromUtf8(env->GetIsolate(), native_accessor_test_source)) |
| 751 ->Run(); |
| 731 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 752 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 732 env->Global()->Get(v8::String::New("start"))); | 753 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 733 | 754 |
| 734 int32_t repeat_count = 1; | 755 int32_t repeat_count = 1; |
| 735 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 756 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 736 const v8::CpuProfile* profile = | 757 const v8::CpuProfile* profile = |
| 737 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); | 758 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); |
| 738 | 759 |
| 739 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 760 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 740 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 761 const v8::CpuProfileNode* startNode = |
| 741 GetChild(startNode, "get foo"); | 762 GetChild(env->GetIsolate(), root, "start"); |
| 742 GetChild(startNode, "set foo"); | 763 GetChild(env->GetIsolate(), startNode, "get foo"); |
| 764 GetChild(env->GetIsolate(), startNode, "set foo"); |
| 743 | 765 |
| 744 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 766 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 745 cpu_profiler->DeleteAllCpuProfiles(); | 767 cpu_profiler->DeleteAllCpuProfiles(); |
| 746 } | 768 } |
| 747 | 769 |
| 748 | 770 |
| 749 // Test that native accessors are properly reported in the CPU profile. | 771 // Test that native accessors are properly reported in the CPU profile. |
| 750 // This test makes sure that the accessors are called enough times to become | 772 // This test makes sure that the accessors are called enough times to become |
| 751 // hot and to trigger optimizations. | 773 // hot and to trigger optimizations. |
| 752 TEST(NativeAccessorMonomorphicIC) { | 774 TEST(NativeAccessorMonomorphicIC) { |
| 753 LocalContext env; | 775 LocalContext env; |
| 754 v8::HandleScope scope(env->GetIsolate()); | 776 v8::HandleScope scope(env->GetIsolate()); |
| 755 | 777 |
| 756 | 778 |
| 757 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 779 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); |
| 758 v8::Local<v8::ObjectTemplate> instance_template = | 780 v8::Local<v8::ObjectTemplate> instance_template = |
| 759 func_template->InstanceTemplate(); | 781 func_template->InstanceTemplate(); |
| 760 | 782 |
| 761 TestApiCallbacks accessors(1); | 783 TestApiCallbacks accessors(1); |
| 762 v8::Local<v8::External> data = | 784 v8::Local<v8::External> data = |
| 763 v8::External::New(env->GetIsolate(), &accessors); | 785 v8::External::New(env->GetIsolate(), &accessors); |
| 764 instance_template->SetAccessor( | 786 instance_template->SetAccessor( |
| 765 v8::String::New("foo"), &TestApiCallbacks::Getter, | 787 v8::String::NewFromUtf8(env->GetIsolate(), "foo"), |
| 766 &TestApiCallbacks::Setter, data); | 788 &TestApiCallbacks::Getter, &TestApiCallbacks::Setter, data); |
| 767 v8::Local<v8::Function> func = func_template->GetFunction(); | 789 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 768 v8::Local<v8::Object> instance = func->NewInstance(); | 790 v8::Local<v8::Object> instance = func->NewInstance(); |
| 769 env->Global()->Set(v8::String::New("instance"), instance); | 791 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), |
| 792 instance); |
| 770 | 793 |
| 771 v8::Script::Compile(v8::String::New(native_accessor_test_source))->Run(); | 794 v8::Script::Compile( |
| 795 v8::String::NewFromUtf8(env->GetIsolate(), native_accessor_test_source)) |
| 796 ->Run(); |
| 772 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 797 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 773 env->Global()->Get(v8::String::New("start"))); | 798 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 774 | 799 |
| 775 { | 800 { |
| 776 // Make sure accessors ICs are in monomorphic state before starting | 801 // Make sure accessors ICs are in monomorphic state before starting |
| 777 // profiling. | 802 // profiling. |
| 778 accessors.set_warming_up(true); | 803 accessors.set_warming_up(true); |
| 779 int32_t warm_up_iterations = 3; | 804 int32_t warm_up_iterations = 3; |
| 780 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; | 805 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; |
| 781 function->Call(env->Global(), ARRAY_SIZE(args), args); | 806 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 782 accessors.set_warming_up(false); | 807 accessors.set_warming_up(false); |
| 783 } | 808 } |
| 784 | 809 |
| 785 int32_t repeat_count = 100; | 810 int32_t repeat_count = 100; |
| 786 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 811 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 787 const v8::CpuProfile* profile = | 812 const v8::CpuProfile* profile = |
| 788 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); | 813 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); |
| 789 | 814 |
| 790 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 815 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 791 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 816 const v8::CpuProfileNode* startNode = |
| 792 GetChild(startNode, "get foo"); | 817 GetChild(env->GetIsolate(), root, "start"); |
| 793 GetChild(startNode, "set foo"); | 818 GetChild(env->GetIsolate(), startNode, "get foo"); |
| 819 GetChild(env->GetIsolate(), startNode, "set foo"); |
| 794 | 820 |
| 795 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 821 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 796 cpu_profiler->DeleteAllCpuProfiles(); | 822 cpu_profiler->DeleteAllCpuProfiles(); |
| 797 } | 823 } |
| 798 | 824 |
| 799 | 825 |
| 800 static const char* native_method_test_source = "function start(count) {\n" | 826 static const char* native_method_test_source = "function start(count) {\n" |
| 801 " for (var i = 0; i < count; i++) {\n" | 827 " for (var i = 0; i < count; i++) {\n" |
| 802 " instance.fooMethod();\n" | 828 " instance.fooMethod();\n" |
| 803 " }\n" | 829 " }\n" |
| 804 "}\n"; | 830 "}\n"; |
| 805 | 831 |
| 806 | 832 |
| 807 TEST(NativeMethodUninitializedIC) { | 833 TEST(NativeMethodUninitializedIC) { |
| 808 LocalContext env; | 834 LocalContext env; |
| 809 v8::HandleScope scope(env->GetIsolate()); | 835 v8::HandleScope scope(env->GetIsolate()); |
| 810 | 836 |
| 811 TestApiCallbacks callbacks(100); | 837 TestApiCallbacks callbacks(100); |
| 812 v8::Local<v8::External> data = | 838 v8::Local<v8::External> data = |
| 813 v8::External::New(env->GetIsolate(), &callbacks); | 839 v8::External::New(env->GetIsolate(), &callbacks); |
| 814 | 840 |
| 815 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 841 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); |
| 816 func_template->SetClassName(v8::String::New("Test_InstanceCostructor")); | 842 func_template->SetClassName( |
| 843 v8::String::NewFromUtf8(env->GetIsolate(), "Test_InstanceCostructor")); |
| 817 v8::Local<v8::ObjectTemplate> proto_template = | 844 v8::Local<v8::ObjectTemplate> proto_template = |
| 818 func_template->PrototypeTemplate(); | 845 func_template->PrototypeTemplate(); |
| 819 v8::Local<v8::Signature> signature = v8::Signature::New(func_template); | 846 v8::Local<v8::Signature> signature = v8::Signature::New(func_template); |
| 820 proto_template->Set(v8::String::New("fooMethod"), v8::FunctionTemplate::New( | 847 proto_template->Set(v8::String::NewFromUtf8(env->GetIsolate(), "fooMethod"), |
| 821 &TestApiCallbacks::Callback, data, signature, 0)); | 848 v8::FunctionTemplate::New(&TestApiCallbacks::Callback, |
| 849 data, signature, 0)); |
| 822 | 850 |
| 823 v8::Local<v8::Function> func = func_template->GetFunction(); | 851 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 824 v8::Local<v8::Object> instance = func->NewInstance(); | 852 v8::Local<v8::Object> instance = func->NewInstance(); |
| 825 env->Global()->Set(v8::String::New("instance"), instance); | 853 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), |
| 854 instance); |
| 826 | 855 |
| 827 v8::Script::Compile(v8::String::New(native_method_test_source))->Run(); | 856 v8::Script::Compile(v8::String::NewFromUtf8( |
| 857 env->GetIsolate(), native_method_test_source))->Run(); |
| 828 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 858 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 829 env->Global()->Get(v8::String::New("start"))); | 859 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 830 | 860 |
| 831 int32_t repeat_count = 1; | 861 int32_t repeat_count = 1; |
| 832 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 862 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 833 const v8::CpuProfile* profile = | 863 const v8::CpuProfile* profile = |
| 834 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 864 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 835 | 865 |
| 836 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 866 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 837 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 867 const v8::CpuProfileNode* startNode = |
| 838 GetChild(startNode, "fooMethod"); | 868 GetChild(env->GetIsolate(), root, "start"); |
| 869 GetChild(env->GetIsolate(), startNode, "fooMethod"); |
| 839 | 870 |
| 840 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 871 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 841 cpu_profiler->DeleteAllCpuProfiles(); | 872 cpu_profiler->DeleteAllCpuProfiles(); |
| 842 } | 873 } |
| 843 | 874 |
| 844 | 875 |
| 845 TEST(NativeMethodMonomorphicIC) { | 876 TEST(NativeMethodMonomorphicIC) { |
| 846 LocalContext env; | 877 LocalContext env; |
| 847 v8::HandleScope scope(env->GetIsolate()); | 878 v8::HandleScope scope(env->GetIsolate()); |
| 848 | 879 |
| 849 TestApiCallbacks callbacks(1); | 880 TestApiCallbacks callbacks(1); |
| 850 v8::Local<v8::External> data = | 881 v8::Local<v8::External> data = |
| 851 v8::External::New(env->GetIsolate(), &callbacks); | 882 v8::External::New(env->GetIsolate(), &callbacks); |
| 852 | 883 |
| 853 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); | 884 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); |
| 854 func_template->SetClassName(v8::String::New("Test_InstanceCostructor")); | 885 func_template->SetClassName( |
| 886 v8::String::NewFromUtf8(env->GetIsolate(), "Test_InstanceCostructor")); |
| 855 v8::Local<v8::ObjectTemplate> proto_template = | 887 v8::Local<v8::ObjectTemplate> proto_template = |
| 856 func_template->PrototypeTemplate(); | 888 func_template->PrototypeTemplate(); |
| 857 v8::Local<v8::Signature> signature = v8::Signature::New(func_template); | 889 v8::Local<v8::Signature> signature = v8::Signature::New(func_template); |
| 858 proto_template->Set(v8::String::New("fooMethod"), v8::FunctionTemplate::New( | 890 proto_template->Set(v8::String::NewFromUtf8(env->GetIsolate(), "fooMethod"), |
| 859 &TestApiCallbacks::Callback, data, signature, 0)); | 891 v8::FunctionTemplate::New(&TestApiCallbacks::Callback, |
| 892 data, signature, 0)); |
| 860 | 893 |
| 861 v8::Local<v8::Function> func = func_template->GetFunction(); | 894 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 862 v8::Local<v8::Object> instance = func->NewInstance(); | 895 v8::Local<v8::Object> instance = func->NewInstance(); |
| 863 env->Global()->Set(v8::String::New("instance"), instance); | 896 env->Global()->Set(v8::String::NewFromUtf8(env->GetIsolate(), "instance"), |
| 897 instance); |
| 864 | 898 |
| 865 v8::Script::Compile(v8::String::New(native_method_test_source))->Run(); | 899 v8::Script::Compile(v8::String::NewFromUtf8( |
| 900 env->GetIsolate(), native_method_test_source))->Run(); |
| 866 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 901 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 867 env->Global()->Get(v8::String::New("start"))); | 902 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 868 { | 903 { |
| 869 // Make sure method ICs are in monomorphic state before starting | 904 // Make sure method ICs are in monomorphic state before starting |
| 870 // profiling. | 905 // profiling. |
| 871 callbacks.set_warming_up(true); | 906 callbacks.set_warming_up(true); |
| 872 int32_t warm_up_iterations = 3; | 907 int32_t warm_up_iterations = 3; |
| 873 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; | 908 v8::Handle<v8::Value> args[] = { v8::Integer::New(warm_up_iterations) }; |
| 874 function->Call(env->Global(), ARRAY_SIZE(args), args); | 909 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 875 callbacks.set_warming_up(false); | 910 callbacks.set_warming_up(false); |
| 876 } | 911 } |
| 877 | 912 |
| 878 int32_t repeat_count = 100; | 913 int32_t repeat_count = 100; |
| 879 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 914 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 880 const v8::CpuProfile* profile = | 915 const v8::CpuProfile* profile = |
| 881 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 916 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 882 | 917 |
| 883 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 918 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 884 GetChild(root, "start"); | 919 GetChild(env->GetIsolate(), root, "start"); |
| 885 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 920 const v8::CpuProfileNode* startNode = |
| 886 GetChild(startNode, "fooMethod"); | 921 GetChild(env->GetIsolate(), root, "start"); |
| 922 GetChild(env->GetIsolate(), startNode, "fooMethod"); |
| 887 | 923 |
| 888 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 924 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 889 cpu_profiler->DeleteAllCpuProfiles(); | 925 cpu_profiler->DeleteAllCpuProfiles(); |
| 890 } | 926 } |
| 891 | 927 |
| 892 | 928 |
| 893 static const char* bound_function_test_source = "function foo(iterations) {\n" | 929 static const char* bound_function_test_source = "function foo(iterations) {\n" |
| 894 " var r = 0;\n" | 930 " var r = 0;\n" |
| 895 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 931 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 896 " return r;\n" | 932 " return r;\n" |
| 897 "}\n" | 933 "}\n" |
| 898 "function start(duration) {\n" | 934 "function start(duration) {\n" |
| 899 " var callback = foo.bind(this);\n" | 935 " var callback = foo.bind(this);\n" |
| 900 " var start = Date.now();\n" | 936 " var start = Date.now();\n" |
| 901 " while (Date.now() - start < duration) {\n" | 937 " while (Date.now() - start < duration) {\n" |
| 902 " callback(10 * 1000);\n" | 938 " callback(10 * 1000);\n" |
| 903 " }\n" | 939 " }\n" |
| 904 "}"; | 940 "}"; |
| 905 | 941 |
| 906 | 942 |
| 907 TEST(BoundFunctionCall) { | 943 TEST(BoundFunctionCall) { |
| 908 LocalContext env; | 944 LocalContext env; |
| 909 v8::HandleScope scope(env->GetIsolate()); | 945 v8::HandleScope scope(env->GetIsolate()); |
| 910 | 946 |
| 911 v8::Script::Compile(v8::String::New(bound_function_test_source))->Run(); | 947 v8::Script::Compile( |
| 948 v8::String::NewFromUtf8(env->GetIsolate(), bound_function_test_source)) |
| 949 ->Run(); |
| 912 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 950 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 913 env->Global()->Get(v8::String::New("start"))); | 951 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 914 | 952 |
| 915 int32_t duration_ms = 100; | 953 int32_t duration_ms = 100; |
| 916 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 954 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 917 const v8::CpuProfile* profile = | 955 const v8::CpuProfile* profile = |
| 918 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 956 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 919 | 957 |
| 920 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 958 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 921 ScopedVector<v8::Handle<v8::String> > names(3); | 959 ScopedVector<v8::Handle<v8::String> > names(3); |
| 922 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 960 names[0] = v8::String::NewFromUtf8( |
| 923 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 961 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 924 names[2] = v8::String::New("start"); | 962 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 963 ProfileGenerator::kProgramEntryName); |
| 964 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 925 // Don't allow |foo| node to be at the top level. | 965 // Don't allow |foo| node to be at the top level. |
| 926 CheckChildrenNames(root, names); | 966 CheckChildrenNames(root, names); |
| 927 | 967 |
| 928 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 968 const v8::CpuProfileNode* startNode = |
| 929 GetChild(startNode, "foo"); | 969 GetChild(env->GetIsolate(), root, "start"); |
| 970 GetChild(env->GetIsolate(), startNode, "foo"); |
| 930 | 971 |
| 931 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 972 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 932 cpu_profiler->DeleteAllCpuProfiles(); | 973 cpu_profiler->DeleteAllCpuProfiles(); |
| 933 } | 974 } |
| 934 | 975 |
| 935 | 976 |
| 936 static const char* call_function_test_source = "function bar(iterations) {\n" | 977 static const char* call_function_test_source = "function bar(iterations) {\n" |
| 937 "}\n" | 978 "}\n" |
| 938 "function start(duration) {\n" | 979 "function start(duration) {\n" |
| 939 " var start = Date.now();\n" | 980 " var start = Date.now();\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 957 // 71 70 start [-1] #3 | 998 // 71 70 start [-1] #3 |
| 958 // 1 1 bar [-1] #7 | 999 // 1 1 bar [-1] #7 |
| 959 // 19 19 (program) [-1] #2 | 1000 // 19 19 (program) [-1] #2 |
| 960 TEST(FunctionCallSample) { | 1001 TEST(FunctionCallSample) { |
| 961 LocalContext env; | 1002 LocalContext env; |
| 962 v8::HandleScope scope(env->GetIsolate()); | 1003 v8::HandleScope scope(env->GetIsolate()); |
| 963 | 1004 |
| 964 // Collect garbage that might have be generated while installing extensions. | 1005 // Collect garbage that might have be generated while installing extensions. |
| 965 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); | 1006 CcTest::heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 966 | 1007 |
| 967 v8::Script::Compile(v8::String::New(call_function_test_source))->Run(); | 1008 v8::Script::Compile(v8::String::NewFromUtf8( |
| 1009 env->GetIsolate(), call_function_test_source))->Run(); |
| 968 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1010 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 969 env->Global()->Get(v8::String::New("start"))); | 1011 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 970 | 1012 |
| 971 int32_t duration_ms = 100; | 1013 int32_t duration_ms = 100; |
| 972 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1014 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 973 const v8::CpuProfile* profile = | 1015 const v8::CpuProfile* profile = |
| 974 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 1016 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 975 | 1017 |
| 976 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1018 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 977 { | 1019 { |
| 978 ScopedVector<v8::Handle<v8::String> > names(4); | 1020 ScopedVector<v8::Handle<v8::String> > names(4); |
| 979 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1021 names[0] = v8::String::NewFromUtf8( |
| 980 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1022 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 981 names[2] = v8::String::New("start"); | 1023 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 982 names[3] = v8::String::New(i::ProfileGenerator::kUnresolvedFunctionName); | 1024 ProfileGenerator::kProgramEntryName); |
| 1025 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1026 names[3] = v8::String::NewFromUtf8( |
| 1027 env->GetIsolate(), i::ProfileGenerator::kUnresolvedFunctionName); |
| 983 // Don't allow |bar| and |call| nodes to be at the top level. | 1028 // Don't allow |bar| and |call| nodes to be at the top level. |
| 984 CheckChildrenNames(root, names); | 1029 CheckChildrenNames(root, names); |
| 985 } | 1030 } |
| 986 | 1031 |
| 987 // In case of GC stress tests all samples may be in GC phase and there | 1032 // In case of GC stress tests all samples may be in GC phase and there |
| 988 // won't be |start| node in the profiles. | 1033 // won't be |start| node in the profiles. |
| 989 bool is_gc_stress_testing = | 1034 bool is_gc_stress_testing = |
| 990 (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction; | 1035 (i::FLAG_gc_interval != -1) || i::FLAG_stress_compaction; |
| 991 const v8::CpuProfileNode* startNode = FindChild(root, "start"); | 1036 const v8::CpuProfileNode* startNode = |
| 1037 FindChild(env->GetIsolate(), root, "start"); |
| 992 CHECK(is_gc_stress_testing || startNode); | 1038 CHECK(is_gc_stress_testing || startNode); |
| 993 if (startNode) { | 1039 if (startNode) { |
| 994 ScopedVector<v8::Handle<v8::String> > names(2); | 1040 ScopedVector<v8::Handle<v8::String> > names(2); |
| 995 names[0] = v8::String::New("bar"); | 1041 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "bar"); |
| 996 names[1] = v8::String::New("call"); | 1042 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); |
| 997 CheckChildrenNames(startNode, names); | 1043 CheckChildrenNames(startNode, names); |
| 998 } | 1044 } |
| 999 | 1045 |
| 1000 const v8::CpuProfileNode* unresolvedNode = | 1046 const v8::CpuProfileNode* unresolvedNode = FindChild( |
| 1001 FindChild(root, i::ProfileGenerator::kUnresolvedFunctionName); | 1047 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); |
| 1002 if (unresolvedNode) { | 1048 if (unresolvedNode) { |
| 1003 ScopedVector<v8::Handle<v8::String> > names(1); | 1049 ScopedVector<v8::Handle<v8::String> > names(1); |
| 1004 names[0] = v8::String::New("call"); | 1050 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); |
| 1005 CheckChildrenNames(unresolvedNode, names); | 1051 CheckChildrenNames(unresolvedNode, names); |
| 1006 } | 1052 } |
| 1007 | 1053 |
| 1008 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1054 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1009 cpu_profiler->DeleteAllCpuProfiles(); | 1055 cpu_profiler->DeleteAllCpuProfiles(); |
| 1010 } | 1056 } |
| 1011 | 1057 |
| 1012 | 1058 |
| 1013 static const char* function_apply_test_source = "function bar(iterations) {\n" | 1059 static const char* function_apply_test_source = "function bar(iterations) {\n" |
| 1014 "}\n" | 1060 "}\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1032 // 1 0 (unresolved function) [-1] #0 8 | 1078 // 1 0 (unresolved function) [-1] #0 8 |
| 1033 // 1 1 apply [-1] #0 9 | 1079 // 1 1 apply [-1] #0 9 |
| 1034 // 32 21 test [-1] #16 4 | 1080 // 32 21 test [-1] #16 4 |
| 1035 // 2 2 bar [-1] #16 6 | 1081 // 2 2 bar [-1] #16 6 |
| 1036 // 9 9 apply [-1] #0 5 | 1082 // 9 9 apply [-1] #0 5 |
| 1037 // 10 10 (program) [-1] #0 2 | 1083 // 10 10 (program) [-1] #0 2 |
| 1038 TEST(FunctionApplySample) { | 1084 TEST(FunctionApplySample) { |
| 1039 LocalContext env; | 1085 LocalContext env; |
| 1040 v8::HandleScope scope(env->GetIsolate()); | 1086 v8::HandleScope scope(env->GetIsolate()); |
| 1041 | 1087 |
| 1042 v8::Script::Compile(v8::String::New(function_apply_test_source))->Run(); | 1088 v8::Script::Compile( |
| 1089 v8::String::NewFromUtf8(env->GetIsolate(), function_apply_test_source)) |
| 1090 ->Run(); |
| 1043 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1091 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1044 env->Global()->Get(v8::String::New("start"))); | 1092 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1045 | 1093 |
| 1046 int32_t duration_ms = 100; | 1094 int32_t duration_ms = 100; |
| 1047 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1095 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1048 | 1096 |
| 1049 const v8::CpuProfile* profile = | 1097 const v8::CpuProfile* profile = |
| 1050 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 1098 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 1051 | 1099 |
| 1052 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1100 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1053 { | 1101 { |
| 1054 ScopedVector<v8::Handle<v8::String> > names(3); | 1102 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1055 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1103 names[0] = v8::String::NewFromUtf8( |
| 1056 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1104 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1057 names[2] = v8::String::New("start"); | 1105 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1106 ProfileGenerator::kProgramEntryName); |
| 1107 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1058 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. | 1108 // Don't allow |test|, |bar| and |apply| nodes to be at the top level. |
| 1059 CheckChildrenNames(root, names); | 1109 CheckChildrenNames(root, names); |
| 1060 } | 1110 } |
| 1061 | 1111 |
| 1062 const v8::CpuProfileNode* startNode = FindChild(root, "start"); | 1112 const v8::CpuProfileNode* startNode = |
| 1113 FindChild(env->GetIsolate(), root, "start"); |
| 1063 if (startNode) { | 1114 if (startNode) { |
| 1064 { | 1115 { |
| 1065 ScopedVector<v8::Handle<v8::String> > names(2); | 1116 ScopedVector<v8::Handle<v8::String> > names(2); |
| 1066 names[0] = v8::String::New("test"); | 1117 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "test"); |
| 1067 names[1] = v8::String::New(ProfileGenerator::kUnresolvedFunctionName); | 1118 names[1] = v8::String::NewFromUtf8( |
| 1119 env->GetIsolate(), ProfileGenerator::kUnresolvedFunctionName); |
| 1068 CheckChildrenNames(startNode, names); | 1120 CheckChildrenNames(startNode, names); |
| 1069 } | 1121 } |
| 1070 | 1122 |
| 1071 const v8::CpuProfileNode* testNode = FindChild(startNode, "test"); | 1123 const v8::CpuProfileNode* testNode = |
| 1124 FindChild(env->GetIsolate(), startNode, "test"); |
| 1072 if (testNode) { | 1125 if (testNode) { |
| 1073 ScopedVector<v8::Handle<v8::String> > names(2); | 1126 ScopedVector<v8::Handle<v8::String> > names(2); |
| 1074 names[0] = v8::String::New("bar"); | 1127 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "bar"); |
| 1075 names[1] = v8::String::New("apply"); | 1128 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); |
| 1076 CheckChildrenNames(testNode, names); | 1129 CheckChildrenNames(testNode, names); |
| 1077 } | 1130 } |
| 1078 | 1131 |
| 1079 if (const v8::CpuProfileNode* unresolvedNode = | 1132 if (const v8::CpuProfileNode* unresolvedNode = |
| 1080 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { | 1133 FindChild(env->GetIsolate(), startNode, |
| 1134 ProfileGenerator::kUnresolvedFunctionName)) { |
| 1081 ScopedVector<v8::Handle<v8::String> > names(1); | 1135 ScopedVector<v8::Handle<v8::String> > names(1); |
| 1082 names[0] = v8::String::New("apply"); | 1136 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); |
| 1083 CheckChildrenNames(unresolvedNode, names); | 1137 CheckChildrenNames(unresolvedNode, names); |
| 1084 GetChild(unresolvedNode, "apply"); | 1138 GetChild(env->GetIsolate(), unresolvedNode, "apply"); |
| 1085 } | 1139 } |
| 1086 } | 1140 } |
| 1087 | 1141 |
| 1088 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1142 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1089 cpu_profiler->DeleteAllCpuProfiles(); | 1143 cpu_profiler->DeleteAllCpuProfiles(); |
| 1090 } | 1144 } |
| 1091 | 1145 |
| 1092 | 1146 |
| 1093 static const char* js_native_js_test_source = | 1147 static const char* js_native_js_test_source = |
| 1094 "var is_profiling = false;\n" | 1148 "var is_profiling = false;\n" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 // 54 54 foo #16 6 | 1183 // 54 54 foo #16 6 |
| 1130 TEST(JsNativeJsSample) { | 1184 TEST(JsNativeJsSample) { |
| 1131 const char* extensions[] = { "v8/profiler" }; | 1185 const char* extensions[] = { "v8/profiler" }; |
| 1132 v8::ExtensionConfiguration config(1, extensions); | 1186 v8::ExtensionConfiguration config(1, extensions); |
| 1133 LocalContext env(&config); | 1187 LocalContext env(&config); |
| 1134 v8::HandleScope scope(env->GetIsolate()); | 1188 v8::HandleScope scope(env->GetIsolate()); |
| 1135 | 1189 |
| 1136 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1190 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1137 CallJsFunction); | 1191 CallJsFunction); |
| 1138 v8::Local<v8::Function> func = func_template->GetFunction(); | 1192 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 1139 func->SetName(v8::String::New("CallJsFunction")); | 1193 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); |
| 1140 env->Global()->Set(v8::String::New("CallJsFunction"), func); | 1194 env->Global()->Set( |
| 1195 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); |
| 1141 | 1196 |
| 1142 v8::Script::Compile(v8::String::New(js_native_js_test_source))->Run(); | 1197 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), |
| 1198 js_native_js_test_source))->Run(); |
| 1143 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1199 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1144 env->Global()->Get(v8::String::New("start"))); | 1200 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1145 | 1201 |
| 1146 int32_t duration_ms = 20; | 1202 int32_t duration_ms = 20; |
| 1147 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1203 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1148 const v8::CpuProfile* profile = | 1204 const v8::CpuProfile* profile = |
| 1149 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | 1205 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
| 1150 | 1206 |
| 1151 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1207 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1152 { | 1208 { |
| 1153 ScopedVector<v8::Handle<v8::String> > names(3); | 1209 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1154 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1210 names[0] = v8::String::NewFromUtf8( |
| 1155 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1211 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1156 names[2] = v8::String::New("start"); | 1212 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1213 ProfileGenerator::kProgramEntryName); |
| 1214 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1157 CheckChildrenNames(root, names); | 1215 CheckChildrenNames(root, names); |
| 1158 } | 1216 } |
| 1159 | 1217 |
| 1160 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1218 const v8::CpuProfileNode* startNode = |
| 1219 GetChild(env->GetIsolate(), root, "start"); |
| 1161 CHECK_EQ(1, startNode->GetChildrenCount()); | 1220 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 1162 const v8::CpuProfileNode* nativeFunctionNode = | 1221 const v8::CpuProfileNode* nativeFunctionNode = |
| 1163 GetChild(startNode, "CallJsFunction"); | 1222 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); |
| 1164 | 1223 |
| 1165 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1224 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
| 1166 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar"); | 1225 const v8::CpuProfileNode* barNode = |
| 1226 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
| 1167 | 1227 |
| 1168 CHECK_EQ(1, barNode->GetChildrenCount()); | 1228 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1169 GetChild(barNode, "foo"); | 1229 GetChild(env->GetIsolate(), barNode, "foo"); |
| 1170 | 1230 |
| 1171 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1231 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1172 cpu_profiler->DeleteAllCpuProfiles(); | 1232 cpu_profiler->DeleteAllCpuProfiles(); |
| 1173 } | 1233 } |
| 1174 | 1234 |
| 1175 | 1235 |
| 1176 static const char* js_native_js_runtime_js_test_source = | 1236 static const char* js_native_js_runtime_js_test_source = |
| 1177 "var is_profiling = false;\n" | 1237 "var is_profiling = false;\n" |
| 1178 "function foo(iterations) {\n" | 1238 "function foo(iterations) {\n" |
| 1179 " if (!is_profiling) {\n" | 1239 " if (!is_profiling) {\n" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1207 // 2 2 (program) #0 2 | 1267 // 2 2 (program) #0 2 |
| 1208 TEST(JsNativeJsRuntimeJsSample) { | 1268 TEST(JsNativeJsRuntimeJsSample) { |
| 1209 const char* extensions[] = { "v8/profiler" }; | 1269 const char* extensions[] = { "v8/profiler" }; |
| 1210 v8::ExtensionConfiguration config(1, extensions); | 1270 v8::ExtensionConfiguration config(1, extensions); |
| 1211 LocalContext env(&config); | 1271 LocalContext env(&config); |
| 1212 v8::HandleScope scope(env->GetIsolate()); | 1272 v8::HandleScope scope(env->GetIsolate()); |
| 1213 | 1273 |
| 1214 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1274 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1215 CallJsFunction); | 1275 CallJsFunction); |
| 1216 v8::Local<v8::Function> func = func_template->GetFunction(); | 1276 v8::Local<v8::Function> func = func_template->GetFunction(); |
| 1217 func->SetName(v8::String::New("CallJsFunction")); | 1277 func->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction")); |
| 1218 env->Global()->Set(v8::String::New("CallJsFunction"), func); | 1278 env->Global()->Set( |
| 1279 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction"), func); |
| 1219 | 1280 |
| 1220 v8::Script::Compile(v8::String::New(js_native_js_runtime_js_test_source))-> | 1281 v8::Script::Compile( |
| 1221 Run(); | 1282 v8::String::NewFromUtf8(env->GetIsolate(), |
| 1283 js_native_js_runtime_js_test_source))->Run(); |
| 1222 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1284 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1223 env->Global()->Get(v8::String::New("start"))); | 1285 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1224 | 1286 |
| 1225 int32_t duration_ms = 20; | 1287 int32_t duration_ms = 20; |
| 1226 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1288 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1227 const v8::CpuProfile* profile = | 1289 const v8::CpuProfile* profile = |
| 1228 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | 1290 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
| 1229 | 1291 |
| 1230 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1292 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1231 ScopedVector<v8::Handle<v8::String> > names(3); | 1293 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1232 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1294 names[0] = v8::String::NewFromUtf8( |
| 1233 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1295 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1234 names[2] = v8::String::New("start"); | 1296 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1297 ProfileGenerator::kProgramEntryName); |
| 1298 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1235 CheckChildrenNames(root, names); | 1299 CheckChildrenNames(root, names); |
| 1236 | 1300 |
| 1237 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1301 const v8::CpuProfileNode* startNode = |
| 1302 GetChild(env->GetIsolate(), root, "start"); |
| 1238 CHECK_EQ(1, startNode->GetChildrenCount()); | 1303 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 1239 const v8::CpuProfileNode* nativeFunctionNode = | 1304 const v8::CpuProfileNode* nativeFunctionNode = |
| 1240 GetChild(startNode, "CallJsFunction"); | 1305 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); |
| 1241 | 1306 |
| 1242 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1307 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
| 1243 const v8::CpuProfileNode* barNode = GetChild(nativeFunctionNode, "bar"); | 1308 const v8::CpuProfileNode* barNode = |
| 1309 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
| 1244 | 1310 |
| 1245 CHECK_EQ(1, barNode->GetChildrenCount()); | 1311 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1246 GetChild(barNode, "foo"); | 1312 GetChild(env->GetIsolate(), barNode, "foo"); |
| 1247 | 1313 |
| 1248 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1314 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1249 cpu_profiler->DeleteAllCpuProfiles(); | 1315 cpu_profiler->DeleteAllCpuProfiles(); |
| 1250 } | 1316 } |
| 1251 | 1317 |
| 1252 | 1318 |
| 1253 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1319 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1254 CallJsFunction(info); | 1320 CallJsFunction(info); |
| 1255 } | 1321 } |
| 1256 | 1322 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 // 2 2 (program) #0 2 | 1355 // 2 2 (program) #0 2 |
| 1290 TEST(JsNative1JsNative2JsSample) { | 1356 TEST(JsNative1JsNative2JsSample) { |
| 1291 const char* extensions[] = { "v8/profiler" }; | 1357 const char* extensions[] = { "v8/profiler" }; |
| 1292 v8::ExtensionConfiguration config(1, extensions); | 1358 v8::ExtensionConfiguration config(1, extensions); |
| 1293 LocalContext env(&config); | 1359 LocalContext env(&config); |
| 1294 v8::HandleScope scope(env->GetIsolate()); | 1360 v8::HandleScope scope(env->GetIsolate()); |
| 1295 | 1361 |
| 1296 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( | 1362 v8::Local<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New( |
| 1297 CallJsFunction); | 1363 CallJsFunction); |
| 1298 v8::Local<v8::Function> func1 = func_template->GetFunction(); | 1364 v8::Local<v8::Function> func1 = func_template->GetFunction(); |
| 1299 func1->SetName(v8::String::New("CallJsFunction1")); | 1365 func1->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1")); |
| 1300 env->Global()->Set(v8::String::New("CallJsFunction1"), func1); | 1366 env->Global()->Set( |
| 1367 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction1"), func1); |
| 1301 | 1368 |
| 1302 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( | 1369 v8::Local<v8::Function> func2 = v8::FunctionTemplate::New( |
| 1303 CallJsFunction2)->GetFunction(); | 1370 CallJsFunction2)->GetFunction(); |
| 1304 func2->SetName(v8::String::New("CallJsFunction2")); | 1371 func2->SetName(v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2")); |
| 1305 env->Global()->Set(v8::String::New("CallJsFunction2"), func2); | 1372 env->Global()->Set( |
| 1373 v8::String::NewFromUtf8(env->GetIsolate(), "CallJsFunction2"), func2); |
| 1306 | 1374 |
| 1307 v8::Script::Compile(v8::String::New(js_native1_js_native2_js_test_source))-> | 1375 v8::Script::Compile( |
| 1308 Run(); | 1376 v8::String::NewFromUtf8(env->GetIsolate(), |
| 1377 js_native1_js_native2_js_test_source))->Run(); |
| 1309 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 1378 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 1310 env->Global()->Get(v8::String::New("start"))); | 1379 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "start"))); |
| 1311 | 1380 |
| 1312 int32_t duration_ms = 20; | 1381 int32_t duration_ms = 20; |
| 1313 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; | 1382 v8::Handle<v8::Value> args[] = { v8::Integer::New(duration_ms) }; |
| 1314 const v8::CpuProfile* profile = | 1383 const v8::CpuProfile* profile = |
| 1315 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); | 1384 RunProfiler(env, function, args, ARRAY_SIZE(args), 10); |
| 1316 | 1385 |
| 1317 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1386 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1318 ScopedVector<v8::Handle<v8::String> > names(3); | 1387 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1319 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1388 names[0] = v8::String::NewFromUtf8( |
| 1320 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1389 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1321 names[2] = v8::String::New("start"); | 1390 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1391 ProfileGenerator::kProgramEntryName); |
| 1392 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 1322 CheckChildrenNames(root, names); | 1393 CheckChildrenNames(root, names); |
| 1323 | 1394 |
| 1324 const v8::CpuProfileNode* startNode = GetChild(root, "start"); | 1395 const v8::CpuProfileNode* startNode = |
| 1396 GetChild(env->GetIsolate(), root, "start"); |
| 1325 CHECK_EQ(1, startNode->GetChildrenCount()); | 1397 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 1326 const v8::CpuProfileNode* nativeNode1 = | 1398 const v8::CpuProfileNode* nativeNode1 = |
| 1327 GetChild(startNode, "CallJsFunction1"); | 1399 GetChild(env->GetIsolate(), startNode, "CallJsFunction1"); |
| 1328 | 1400 |
| 1329 CHECK_EQ(1, nativeNode1->GetChildrenCount()); | 1401 CHECK_EQ(1, nativeNode1->GetChildrenCount()); |
| 1330 const v8::CpuProfileNode* barNode = GetChild(nativeNode1, "bar"); | 1402 const v8::CpuProfileNode* barNode = |
| 1403 GetChild(env->GetIsolate(), nativeNode1, "bar"); |
| 1331 | 1404 |
| 1332 CHECK_EQ(1, barNode->GetChildrenCount()); | 1405 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1333 const v8::CpuProfileNode* nativeNode2 = GetChild(barNode, "CallJsFunction2"); | 1406 const v8::CpuProfileNode* nativeNode2 = |
| 1407 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); |
| 1334 | 1408 |
| 1335 CHECK_EQ(1, nativeNode2->GetChildrenCount()); | 1409 CHECK_EQ(1, nativeNode2->GetChildrenCount()); |
| 1336 GetChild(nativeNode2, "foo"); | 1410 GetChild(env->GetIsolate(), nativeNode2, "foo"); |
| 1337 | 1411 |
| 1338 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1412 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1339 cpu_profiler->DeleteAllCpuProfiles(); | 1413 cpu_profiler->DeleteAllCpuProfiles(); |
| 1340 } | 1414 } |
| 1341 | 1415 |
| 1342 | 1416 |
| 1343 // [Top down]: | 1417 // [Top down]: |
| 1344 // 6 0 (root) #0 1 | 1418 // 6 0 (root) #0 1 |
| 1345 // 3 3 (program) #0 2 | 1419 // 3 3 (program) #0 2 |
| 1346 // 3 3 (idle) #0 3 | 1420 // 3 3 (idle) #0 3 |
| 1347 TEST(IdleTime) { | 1421 TEST(IdleTime) { |
| 1348 LocalContext env; | 1422 LocalContext env; |
| 1349 v8::HandleScope scope(env->GetIsolate()); | 1423 v8::HandleScope scope(env->GetIsolate()); |
| 1350 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1424 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1351 | 1425 |
| 1352 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); | 1426 v8::Local<v8::String> profile_name = |
| 1427 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile"); |
| 1353 cpu_profiler->StartCpuProfiling(profile_name); | 1428 cpu_profiler->StartCpuProfiling(profile_name); |
| 1354 | 1429 |
| 1355 i::Isolate* isolate = CcTest::i_isolate(); | 1430 i::Isolate* isolate = CcTest::i_isolate(); |
| 1356 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); | 1431 i::ProfilerEventsProcessor* processor = isolate->cpu_profiler()->processor(); |
| 1357 processor->AddCurrentStack(isolate); | 1432 processor->AddCurrentStack(isolate); |
| 1358 | 1433 |
| 1359 cpu_profiler->SetIdle(true); | 1434 cpu_profiler->SetIdle(true); |
| 1360 | 1435 |
| 1361 for (int i = 0; i < 3; i++) { | 1436 for (int i = 0; i < 3; i++) { |
| 1362 processor->AddCurrentStack(isolate); | 1437 processor->AddCurrentStack(isolate); |
| 1363 } | 1438 } |
| 1364 | 1439 |
| 1365 cpu_profiler->SetIdle(false); | 1440 cpu_profiler->SetIdle(false); |
| 1366 processor->AddCurrentStack(isolate); | 1441 processor->AddCurrentStack(isolate); |
| 1367 | 1442 |
| 1368 | 1443 |
| 1369 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); | 1444 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 1370 CHECK_NE(NULL, profile); | 1445 CHECK_NE(NULL, profile); |
| 1371 // Dump collected profile to have a better diagnostic in case of failure. | 1446 // Dump collected profile to have a better diagnostic in case of failure. |
| 1372 reinterpret_cast<i::CpuProfile*>( | 1447 reinterpret_cast<i::CpuProfile*>( |
| 1373 const_cast<v8::CpuProfile*>(profile))->Print(); | 1448 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 1374 | 1449 |
| 1375 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1450 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1376 ScopedVector<v8::Handle<v8::String> > names(3); | 1451 ScopedVector<v8::Handle<v8::String> > names(3); |
| 1377 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); | 1452 names[0] = v8::String::NewFromUtf8( |
| 1378 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); | 1453 env->GetIsolate(), ProfileGenerator::kGarbageCollectorEntryName); |
| 1379 names[2] = v8::String::New(ProfileGenerator::kIdleEntryName); | 1454 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1455 ProfileGenerator::kProgramEntryName); |
| 1456 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 1457 ProfileGenerator::kIdleEntryName); |
| 1380 CheckChildrenNames(root, names); | 1458 CheckChildrenNames(root, names); |
| 1381 | 1459 |
| 1382 const v8::CpuProfileNode* programNode = | 1460 const v8::CpuProfileNode* programNode = |
| 1383 GetChild(root, ProfileGenerator::kProgramEntryName); | 1461 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); |
| 1384 CHECK_EQ(0, programNode->GetChildrenCount()); | 1462 CHECK_EQ(0, programNode->GetChildrenCount()); |
| 1385 CHECK_GE(programNode->GetHitCount(), 3); | 1463 CHECK_GE(programNode->GetHitCount(), 3); |
| 1386 | 1464 |
| 1387 const v8::CpuProfileNode* idleNode = | 1465 const v8::CpuProfileNode* idleNode = |
| 1388 GetChild(root, ProfileGenerator::kIdleEntryName); | 1466 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); |
| 1389 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1467 CHECK_EQ(0, idleNode->GetChildrenCount()); |
| 1390 CHECK_GE(idleNode->GetHitCount(), 3); | 1468 CHECK_GE(idleNode->GetHitCount(), 3); |
| 1391 | 1469 |
| 1392 cpu_profiler->DeleteAllCpuProfiles(); | 1470 cpu_profiler->DeleteAllCpuProfiles(); |
| 1393 } | 1471 } |
| 1394 | 1472 |
| 1395 | 1473 |
| 1396 static void CheckFunctionDetails(const v8::CpuProfileNode* node, | 1474 static void CheckFunctionDetails(v8::Isolate* isolate, |
| 1397 const char* name, const char* script_name, int script_id, | 1475 const v8::CpuProfileNode* node, |
| 1398 int line, int column) { | 1476 const char* name, const char* script_name, |
| 1399 CHECK_EQ(v8::String::New(name), node->GetFunctionName()); | 1477 int script_id, int line, int column) { |
| 1400 CHECK_EQ(v8::String::New(script_name), node->GetScriptResourceName()); | 1478 CHECK_EQ(v8::String::NewFromUtf8(isolate, name), |
| 1479 node->GetFunctionName()); |
| 1480 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name), |
| 1481 node->GetScriptResourceName()); |
| 1401 CHECK_EQ(script_id, node->GetScriptId()); | 1482 CHECK_EQ(script_id, node->GetScriptId()); |
| 1402 CHECK_EQ(line, node->GetLineNumber()); | 1483 CHECK_EQ(line, node->GetLineNumber()); |
| 1403 CHECK_EQ(column, node->GetColumnNumber()); | 1484 CHECK_EQ(column, node->GetColumnNumber()); |
| 1404 } | 1485 } |
| 1405 | 1486 |
| 1406 | 1487 |
| 1407 TEST(FunctionDetails) { | 1488 TEST(FunctionDetails) { |
| 1408 const char* extensions[] = { "v8/profiler" }; | 1489 const char* extensions[] = { "v8/profiler" }; |
| 1409 v8::ExtensionConfiguration config(1, extensions); | 1490 v8::ExtensionConfiguration config(1, extensions); |
| 1410 LocalContext env(&config); | 1491 LocalContext env(&config); |
| 1411 v8::HandleScope handleScope(env->GetIsolate()); | 1492 v8::HandleScope handleScope(env->GetIsolate()); |
| 1412 | 1493 |
| 1413 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); | 1494 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1414 CHECK_EQ(0, profiler->GetProfileCount()); | 1495 CHECK_EQ(0, profiler->GetProfileCount()); |
| 1415 v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::New( | 1496 v8::Handle<v8::Script> script_a = v8::Script::Compile( |
| 1416 " function foo\n() { try { bar(); } catch(e) {} }\n" | 1497 v8::String::NewFromUtf8( |
| 1417 " function bar() { startProfiling(); }\n"), v8::String::New("script_a")); | 1498 env->GetIsolate(), |
| 1499 " function foo\n() { try { bar(); } catch(e) {} }\n" |
| 1500 " function bar() { startProfiling(); }\n"), |
| 1501 v8::String::NewFromUtf8(env->GetIsolate(), "script_a")); |
| 1418 script_a->Run(); | 1502 script_a->Run(); |
| 1419 v8::Handle<v8::Script> script_b = v8::Script::Compile(v8::String::New( | 1503 v8::Handle<v8::Script> script_b = v8::Script::Compile( |
| 1420 "\n\n function baz() { try { foo(); } catch(e) {} }\n" | 1504 v8::String::NewFromUtf8( |
| 1421 "\n\nbaz();\n" | 1505 env->GetIsolate(), |
| 1422 "stopProfiling();\n"), v8::String::New("script_b")); | 1506 "\n\n function baz() { try { foo(); } catch(e) {} }\n" |
| 1507 "\n\nbaz();\n" |
| 1508 "stopProfiling();\n"), |
| 1509 v8::String::NewFromUtf8(env->GetIsolate(), "script_b")); |
| 1423 script_b->Run(); | 1510 script_b->Run(); |
| 1424 CHECK_EQ(1, profiler->GetProfileCount()); | 1511 CHECK_EQ(1, profiler->GetProfileCount()); |
| 1425 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); | 1512 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); |
| 1426 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); | 1513 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
| 1427 reinterpret_cast<ProfileNode*>( | 1514 reinterpret_cast<ProfileNode*>( |
| 1428 const_cast<v8::CpuProfileNode*>(current))->Print(0); | 1515 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
| 1429 // The tree should look like this: | 1516 // The tree should look like this: |
| 1430 // 0 (root) 0 #1 | 1517 // 0 (root) 0 #1 |
| 1431 // 0 (anonymous function) 19 #2 no reason script_b:1 | 1518 // 0 (anonymous function) 19 #2 no reason script_b:1 |
| 1432 // 0 baz 19 #3 TryCatchStatement script_b:3 | 1519 // 0 baz 19 #3 TryCatchStatement script_b:3 |
| 1433 // 0 foo 18 #4 TryCatchStatement script_a:2 | 1520 // 0 foo 18 #4 TryCatchStatement script_a:2 |
| 1434 // 1 bar 18 #5 no reason script_a:3 | 1521 // 1 bar 18 #5 no reason script_a:3 |
| 1435 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1522 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 1436 const v8::CpuProfileNode* script = GetChild(root, | 1523 const v8::CpuProfileNode* script = GetChild(env->GetIsolate(), root, |
| 1437 ProfileGenerator::kAnonymousFunctionName); | 1524 ProfileGenerator::kAnonymousFunctionName); |
| 1438 CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName, | 1525 CheckFunctionDetails(env->GetIsolate(), script, |
| 1439 "script_b", script_b->GetId(), 1, 1); | 1526 ProfileGenerator::kAnonymousFunctionName, "script_b", |
| 1440 const v8::CpuProfileNode* baz = GetChild(script, "baz"); | 1527 script_b->GetId(), 1, 1); |
| 1441 CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16); | 1528 const v8::CpuProfileNode* baz = GetChild(env->GetIsolate(), script, "baz"); |
| 1442 const v8::CpuProfileNode* foo = GetChild(baz, "foo"); | 1529 CheckFunctionDetails(env->GetIsolate(), baz, "baz", "script_b", |
| 1443 CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1); | 1530 script_b->GetId(), 3, 16); |
| 1444 const v8::CpuProfileNode* bar = GetChild(foo, "bar"); | 1531 const v8::CpuProfileNode* foo = GetChild(env->GetIsolate(), baz, "foo"); |
| 1445 CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14); | 1532 CheckFunctionDetails(env->GetIsolate(), foo, "foo", "script_a", |
| 1533 script_a->GetId(), 2, 1); |
| 1534 const v8::CpuProfileNode* bar = GetChild(env->GetIsolate(), foo, "bar"); |
| 1535 CheckFunctionDetails(env->GetIsolate(), bar, "bar", "script_a", |
| 1536 script_a->GetId(), 3, 14); |
| 1446 } | 1537 } |
| OLD | NEW |