| 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 // | 27 // |
| 28 // Tests of profiles generator and utilities. | 28 // Tests of profiles generator and utilities. |
| 29 | 29 |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 #include "cpu-profiler-inl.h" | 31 #include "cpu-profiler-inl.h" |
| 32 #include "cctest.h" | 32 #include "cctest.h" |
| 33 #include "platform.h" | 33 #include "platform.h" |
| 34 #include "profiler-extension.h" |
| 34 #include "smart-pointers.h" | 35 #include "smart-pointers.h" |
| 35 #include "utils.h" | 36 #include "utils.h" |
| 36 #include "../include/v8-profiler.h" | 37 #include "../include/v8-profiler.h" |
| 37 using i::CodeEntry; | 38 using i::CodeEntry; |
| 38 using i::CpuProfile; | 39 using i::CpuProfile; |
| 39 using i::CpuProfiler; | 40 using i::CpuProfiler; |
| 40 using i::CpuProfilesCollection; | 41 using i::CpuProfilesCollection; |
| 41 using i::Heap; | 42 using i::Heap; |
| 42 using i::ProfileGenerator; | 43 using i::ProfileGenerator; |
| 43 using i::ProfileNode; | 44 using i::ProfileNode; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 i::Code* aaa_code = CreateCode(&env); | 133 i::Code* aaa_code = CreateCode(&env); |
| 133 i::Code* comment_code = CreateCode(&env); | 134 i::Code* comment_code = CreateCode(&env); |
| 134 i::Code* args5_code = CreateCode(&env); | 135 i::Code* args5_code = CreateCode(&env); |
| 135 i::Code* comment2_code = CreateCode(&env); | 136 i::Code* comment2_code = CreateCode(&env); |
| 136 i::Code* moved_code = CreateCode(&env); | 137 i::Code* moved_code = CreateCode(&env); |
| 137 i::Code* args3_code = CreateCode(&env); | 138 i::Code* args3_code = CreateCode(&env); |
| 138 i::Code* args4_code = CreateCode(&env); | 139 i::Code* args4_code = CreateCode(&env); |
| 139 | 140 |
| 140 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 141 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
| 141 profiles->StartProfiling("", 1, false); | 142 profiles->StartProfiling("", false); |
| 142 ProfileGenerator generator(profiles); | 143 ProfileGenerator generator(profiles); |
| 143 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 144 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
| 144 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 145 &generator, NULL, TimeDelta::FromMicroseconds(100))); |
| 145 processor->Start(); | 146 processor->Start(); |
| 146 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 147 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
| 147 | 148 |
| 148 // Enqueue code creation events. | 149 // Enqueue code creation events. |
| 149 const char* aaa_str = "aaa"; | 150 const char* aaa_str = "aaa"; |
| 150 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( | 151 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( |
| 151 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); | 152 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 TestSetup test_setup; | 194 TestSetup test_setup; |
| 194 LocalContext env; | 195 LocalContext env; |
| 195 i::Isolate* isolate = CcTest::i_isolate(); | 196 i::Isolate* isolate = CcTest::i_isolate(); |
| 196 i::HandleScope scope(isolate); | 197 i::HandleScope scope(isolate); |
| 197 | 198 |
| 198 i::Code* frame1_code = CreateCode(&env); | 199 i::Code* frame1_code = CreateCode(&env); |
| 199 i::Code* frame2_code = CreateCode(&env); | 200 i::Code* frame2_code = CreateCode(&env); |
| 200 i::Code* frame3_code = CreateCode(&env); | 201 i::Code* frame3_code = CreateCode(&env); |
| 201 | 202 |
| 202 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 203 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
| 203 profiles->StartProfiling("", 1, false); | 204 profiles->StartProfiling("", false); |
| 204 ProfileGenerator generator(profiles); | 205 ProfileGenerator generator(profiles); |
| 205 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 206 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
| 206 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 207 &generator, NULL, TimeDelta::FromMicroseconds(100))); |
| 207 processor->Start(); | 208 processor->Start(); |
| 208 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 209 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
| 209 | 210 |
| 210 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); | 211 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); |
| 211 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); | 212 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); |
| 212 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); | 213 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); |
| 213 | 214 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 // Long stacks (exceeding max frames limit) must not be erased. | 263 // Long stacks (exceeding max frames limit) must not be erased. |
| 263 TEST(Issue1398) { | 264 TEST(Issue1398) { |
| 264 TestSetup test_setup; | 265 TestSetup test_setup; |
| 265 LocalContext env; | 266 LocalContext env; |
| 266 i::Isolate* isolate = CcTest::i_isolate(); | 267 i::Isolate* isolate = CcTest::i_isolate(); |
| 267 i::HandleScope scope(isolate); | 268 i::HandleScope scope(isolate); |
| 268 | 269 |
| 269 i::Code* code = CreateCode(&env); | 270 i::Code* code = CreateCode(&env); |
| 270 | 271 |
| 271 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 272 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
| 272 profiles->StartProfiling("", 1, false); | 273 profiles->StartProfiling("", false); |
| 273 ProfileGenerator generator(profiles); | 274 ProfileGenerator generator(profiles); |
| 274 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 275 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
| 275 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 276 &generator, NULL, TimeDelta::FromMicroseconds(100))); |
| 276 processor->Start(); | 277 processor->Start(); |
| 277 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 278 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
| 278 | 279 |
| 279 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); | 280 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); |
| 280 | 281 |
| 281 i::TickSample* sample = processor->StartTickSample(); | 282 i::TickSample* sample = processor->StartTickSample(); |
| 282 sample->pc = code->address(); | 283 sample->pc = code->address(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 326 |
| 326 // Test profiling cancellation by the 'delete' command. | 327 // Test profiling cancellation by the 'delete' command. |
| 327 profiler->StartProfiling("1"); | 328 profiler->StartProfiling("1"); |
| 328 profiler->StartProfiling("2"); | 329 profiler->StartProfiling("2"); |
| 329 CHECK_EQ(0, profiler->GetProfilesCount()); | 330 CHECK_EQ(0, profiler->GetProfilesCount()); |
| 330 profiler->DeleteAllProfiles(); | 331 profiler->DeleteAllProfiles(); |
| 331 CHECK_EQ(0, profiler->GetProfilesCount()); | 332 CHECK_EQ(0, profiler->GetProfilesCount()); |
| 332 } | 333 } |
| 333 | 334 |
| 334 | 335 |
| 335 static const v8::CpuProfile* FindCpuProfile(v8::CpuProfiler* profiler, | 336 static bool FindCpuProfile(v8::CpuProfiler* v8profiler, |
| 336 unsigned uid) { | 337 const v8::CpuProfile* v8profile) { |
| 337 int length = profiler->GetProfileCount(); | 338 i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(v8profiler); |
| 339 const i::CpuProfile* profile = |
| 340 reinterpret_cast<const i::CpuProfile*>(v8profile); |
| 341 int length = profiler->GetProfilesCount(); |
| 338 for (int i = 0; i < length; i++) { | 342 for (int i = 0; i < length; i++) { |
| 339 const v8::CpuProfile* profile = profiler->GetCpuProfile(i); | 343 if (profile == profiler->GetProfile(i)) |
| 340 if (profile->GetUid() == uid) { | 344 return true; |
| 341 return profile; | |
| 342 } | |
| 343 } | 345 } |
| 344 return NULL; | 346 return false; |
| 345 } | 347 } |
| 346 | 348 |
| 347 | 349 |
| 348 TEST(DeleteCpuProfile) { | 350 TEST(DeleteCpuProfile) { |
| 349 LocalContext env; | 351 LocalContext env; |
| 350 v8::HandleScope scope(env->GetIsolate()); | 352 v8::HandleScope scope(env->GetIsolate()); |
| 351 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 353 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 354 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(cpu_profiler); |
| 352 | 355 |
| 353 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 356 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 354 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1"); | 357 v8::Local<v8::String> name1 = v8::String::NewFromUtf8(env->GetIsolate(), "1"); |
| 355 cpu_profiler->StartCpuProfiling(name1); | 358 cpu_profiler->StartCpuProfiling(name1); |
| 356 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); | 359 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); |
| 357 CHECK_NE(NULL, p1); | 360 CHECK_NE(NULL, p1); |
| 358 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | 361 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 359 unsigned uid1 = p1->GetUid(); | 362 CHECK(FindCpuProfile(cpu_profiler, p1)); |
| 360 CHECK_EQ(p1, FindCpuProfile(cpu_profiler, uid1)); | |
| 361 const_cast<v8::CpuProfile*>(p1)->Delete(); | 363 const_cast<v8::CpuProfile*>(p1)->Delete(); |
| 362 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 364 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 363 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | |
| 364 | 365 |
| 365 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2"); | 366 v8::Local<v8::String> name2 = v8::String::NewFromUtf8(env->GetIsolate(), "2"); |
| 366 cpu_profiler->StartCpuProfiling(name2); | 367 cpu_profiler->StartCpuProfiling(name2); |
| 367 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2); | 368 const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2); |
| 368 CHECK_NE(NULL, p2); | 369 CHECK_NE(NULL, p2); |
| 369 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | 370 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 370 unsigned uid2 = p2->GetUid(); | 371 CHECK(FindCpuProfile(cpu_profiler, p2)); |
| 371 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); | |
| 372 CHECK_EQ(p2, FindCpuProfile(cpu_profiler, uid2)); | |
| 373 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | |
| 374 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3"); | 372 v8::Local<v8::String> name3 = v8::String::NewFromUtf8(env->GetIsolate(), "3"); |
| 375 cpu_profiler->StartCpuProfiling(name3); | 373 cpu_profiler->StartCpuProfiling(name3); |
| 376 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); | 374 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); |
| 377 CHECK_NE(NULL, p3); | 375 CHECK_NE(NULL, p3); |
| 378 CHECK_EQ(2, cpu_profiler->GetProfileCount()); | 376 CHECK_EQ(2, iprofiler->GetProfilesCount()); |
| 379 unsigned uid3 = p3->GetUid(); | 377 CHECK_NE(p2, p3); |
| 380 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); | 378 CHECK(FindCpuProfile(cpu_profiler, p3)); |
| 381 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); | 379 CHECK(FindCpuProfile(cpu_profiler, p2)); |
| 382 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | |
| 383 const_cast<v8::CpuProfile*>(p2)->Delete(); | 380 const_cast<v8::CpuProfile*>(p2)->Delete(); |
| 384 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | 381 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 385 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); | 382 CHECK(!FindCpuProfile(cpu_profiler, p2)); |
| 386 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); | 383 CHECK(FindCpuProfile(cpu_profiler, p3)); |
| 387 const_cast<v8::CpuProfile*>(p3)->Delete(); | 384 const_cast<v8::CpuProfile*>(p3)->Delete(); |
| 388 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 385 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 389 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3)); | |
| 390 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); | |
| 391 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | |
| 392 } | 386 } |
| 393 | 387 |
| 394 | 388 |
| 395 TEST(ProfileStartEndTime) { | 389 TEST(ProfileStartEndTime) { |
| 396 LocalContext env; | 390 LocalContext env; |
| 397 v8::HandleScope scope(env->GetIsolate()); | 391 v8::HandleScope scope(env->GetIsolate()); |
| 398 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 392 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 399 | 393 |
| 400 v8::Local<v8::String> profile_name = | 394 v8::Local<v8::String> profile_name = |
| 401 v8::String::NewFromUtf8(env->GetIsolate(), "test"); | 395 v8::String::NewFromUtf8(env->GetIsolate(), "test"); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 const char* barBranch[] = { "bar", "delay", "loop" }; | 576 const char* barBranch[] = { "bar", "delay", "loop" }; |
| 583 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, | 577 CheckSimpleBranch(env->GetIsolate(), fooNode, barBranch, |
| 584 ARRAY_SIZE(barBranch)); | 578 ARRAY_SIZE(barBranch)); |
| 585 const char* bazBranch[] = { "baz", "delay", "loop" }; | 579 const char* bazBranch[] = { "baz", "delay", "loop" }; |
| 586 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, | 580 CheckSimpleBranch(env->GetIsolate(), fooNode, bazBranch, |
| 587 ARRAY_SIZE(bazBranch)); | 581 ARRAY_SIZE(bazBranch)); |
| 588 const char* delayBranch[] = { "delay", "loop" }; | 582 const char* delayBranch[] = { "delay", "loop" }; |
| 589 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, | 583 CheckSimpleBranch(env->GetIsolate(), fooNode, delayBranch, |
| 590 ARRAY_SIZE(delayBranch)); | 584 ARRAY_SIZE(delayBranch)); |
| 591 | 585 |
| 592 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 586 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 593 cpu_profiler->DeleteAllCpuProfiles(); | |
| 594 } | 587 } |
| 595 | 588 |
| 596 | 589 |
| 597 | 590 |
| 598 static const char* cpu_profiler_test_source2 = "function loop() {}\n" | 591 static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
| 599 "function delay() { loop(); }\n" | 592 "function delay() { loop(); }\n" |
| 600 "function start(count) {\n" | 593 "function start(count) {\n" |
| 601 " var k = 0;\n" | 594 " var k = 0;\n" |
| 602 " do {\n" | 595 " do {\n" |
| 603 " delay();\n" | 596 " delay();\n" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 if (startNode && startNode->GetChildrenCount() > 0) { | 643 if (startNode && startNode->GetChildrenCount() > 0) { |
| 651 CHECK_EQ(1, startNode->GetChildrenCount()); | 644 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 652 const v8::CpuProfileNode* delayNode = | 645 const v8::CpuProfileNode* delayNode = |
| 653 GetChild(env->GetIsolate(), startNode, "delay"); | 646 GetChild(env->GetIsolate(), startNode, "delay"); |
| 654 if (delayNode->GetChildrenCount() > 0) { | 647 if (delayNode->GetChildrenCount() > 0) { |
| 655 CHECK_EQ(1, delayNode->GetChildrenCount()); | 648 CHECK_EQ(1, delayNode->GetChildrenCount()); |
| 656 GetChild(env->GetIsolate(), delayNode, "loop"); | 649 GetChild(env->GetIsolate(), delayNode, "loop"); |
| 657 } | 650 } |
| 658 } | 651 } |
| 659 | 652 |
| 660 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 653 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 661 cpu_profiler->DeleteAllCpuProfiles(); | |
| 662 } | 654 } |
| 663 | 655 |
| 664 | 656 |
| 665 static const char* native_accessor_test_source = "function start(count) {\n" | 657 static const char* native_accessor_test_source = "function start(count) {\n" |
| 666 " for (var i = 0; i < count; i++) {\n" | 658 " for (var i = 0; i < count; i++) {\n" |
| 667 " var o = instance.foo;\n" | 659 " var o = instance.foo;\n" |
| 668 " instance.foo = o + 1;\n" | 660 " instance.foo = o + 1;\n" |
| 669 " }\n" | 661 " }\n" |
| 670 "}\n"; | 662 "}\n"; |
| 671 | 663 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 744 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 753 const v8::CpuProfile* profile = | 745 const v8::CpuProfile* profile = |
| 754 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); | 746 RunProfiler(env, function, args, ARRAY_SIZE(args), 180); |
| 755 | 747 |
| 756 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 748 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 757 const v8::CpuProfileNode* startNode = | 749 const v8::CpuProfileNode* startNode = |
| 758 GetChild(env->GetIsolate(), root, "start"); | 750 GetChild(env->GetIsolate(), root, "start"); |
| 759 GetChild(env->GetIsolate(), startNode, "get foo"); | 751 GetChild(env->GetIsolate(), startNode, "get foo"); |
| 760 GetChild(env->GetIsolate(), startNode, "set foo"); | 752 GetChild(env->GetIsolate(), startNode, "set foo"); |
| 761 | 753 |
| 762 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 754 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 763 cpu_profiler->DeleteAllCpuProfiles(); | |
| 764 } | 755 } |
| 765 | 756 |
| 766 | 757 |
| 767 // Test that native accessors are properly reported in the CPU profile. | 758 // Test that native accessors are properly reported in the CPU profile. |
| 768 // This test makes sure that the accessors are called enough times to become | 759 // This test makes sure that the accessors are called enough times to become |
| 769 // hot and to trigger optimizations. | 760 // hot and to trigger optimizations. |
| 770 TEST(NativeAccessorMonomorphicIC) { | 761 TEST(NativeAccessorMonomorphicIC) { |
| 771 LocalContext env; | 762 LocalContext env; |
| 772 v8::HandleScope scope(env->GetIsolate()); | 763 v8::HandleScope scope(env->GetIsolate()); |
| 773 | 764 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 798 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 808 const v8::CpuProfile* profile = | 799 const v8::CpuProfile* profile = |
| 809 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); | 800 RunProfiler(env, function, args, ARRAY_SIZE(args), 200); |
| 810 | 801 |
| 811 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 802 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 812 const v8::CpuProfileNode* startNode = | 803 const v8::CpuProfileNode* startNode = |
| 813 GetChild(env->GetIsolate(), root, "start"); | 804 GetChild(env->GetIsolate(), root, "start"); |
| 814 GetChild(env->GetIsolate(), startNode, "get foo"); | 805 GetChild(env->GetIsolate(), startNode, "get foo"); |
| 815 GetChild(env->GetIsolate(), startNode, "set foo"); | 806 GetChild(env->GetIsolate(), startNode, "set foo"); |
| 816 | 807 |
| 817 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 808 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 818 cpu_profiler->DeleteAllCpuProfiles(); | |
| 819 } | 809 } |
| 820 | 810 |
| 821 | 811 |
| 822 static const char* native_method_test_source = "function start(count) {\n" | 812 static const char* native_method_test_source = "function start(count) {\n" |
| 823 " for (var i = 0; i < count; i++) {\n" | 813 " for (var i = 0; i < count; i++) {\n" |
| 824 " instance.fooMethod();\n" | 814 " instance.fooMethod();\n" |
| 825 " }\n" | 815 " }\n" |
| 826 "}\n"; | 816 "}\n"; |
| 827 | 817 |
| 828 | 818 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 858 int32_t repeat_count = 1; | 848 int32_t repeat_count = 1; |
| 859 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 849 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 860 const v8::CpuProfile* profile = | 850 const v8::CpuProfile* profile = |
| 861 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 851 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 862 | 852 |
| 863 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 853 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 864 const v8::CpuProfileNode* startNode = | 854 const v8::CpuProfileNode* startNode = |
| 865 GetChild(env->GetIsolate(), root, "start"); | 855 GetChild(env->GetIsolate(), root, "start"); |
| 866 GetChild(env->GetIsolate(), startNode, "fooMethod"); | 856 GetChild(env->GetIsolate(), startNode, "fooMethod"); |
| 867 | 857 |
| 868 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 858 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 869 cpu_profiler->DeleteAllCpuProfiles(); | |
| 870 } | 859 } |
| 871 | 860 |
| 872 | 861 |
| 873 TEST(NativeMethodMonomorphicIC) { | 862 TEST(NativeMethodMonomorphicIC) { |
| 874 LocalContext env; | 863 LocalContext env; |
| 875 v8::HandleScope scope(env->GetIsolate()); | 864 v8::HandleScope scope(env->GetIsolate()); |
| 876 | 865 |
| 877 TestApiCallbacks callbacks(1); | 866 TestApiCallbacks callbacks(1); |
| 878 v8::Local<v8::External> data = | 867 v8::Local<v8::External> data = |
| 879 v8::External::New(env->GetIsolate(), &callbacks); | 868 v8::External::New(env->GetIsolate(), &callbacks); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; | 901 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 913 const v8::CpuProfile* profile = | 902 const v8::CpuProfile* profile = |
| 914 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); | 903 RunProfiler(env, function, args, ARRAY_SIZE(args), 100); |
| 915 | 904 |
| 916 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 905 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 917 GetChild(env->GetIsolate(), root, "start"); | 906 GetChild(env->GetIsolate(), root, "start"); |
| 918 const v8::CpuProfileNode* startNode = | 907 const v8::CpuProfileNode* startNode = |
| 919 GetChild(env->GetIsolate(), root, "start"); | 908 GetChild(env->GetIsolate(), root, "start"); |
| 920 GetChild(env->GetIsolate(), startNode, "fooMethod"); | 909 GetChild(env->GetIsolate(), startNode, "fooMethod"); |
| 921 | 910 |
| 922 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 911 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 923 cpu_profiler->DeleteAllCpuProfiles(); | |
| 924 } | 912 } |
| 925 | 913 |
| 926 | 914 |
| 927 static const char* bound_function_test_source = "function foo(iterations) {\n" | 915 static const char* bound_function_test_source = "function foo(iterations) {\n" |
| 928 " var r = 0;\n" | 916 " var r = 0;\n" |
| 929 " for (var i = 0; i < iterations; i++) { r += i; }\n" | 917 " for (var i = 0; i < iterations; i++) { r += i; }\n" |
| 930 " return r;\n" | 918 " return r;\n" |
| 931 "}\n" | 919 "}\n" |
| 932 "function start(duration) {\n" | 920 "function start(duration) {\n" |
| 933 " var callback = foo.bind(this);\n" | 921 " var callback = foo.bind(this);\n" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 960 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), | 948 names[1] = v8::String::NewFromUtf8(env->GetIsolate(), |
| 961 ProfileGenerator::kProgramEntryName); | 949 ProfileGenerator::kProgramEntryName); |
| 962 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); | 950 names[2] = v8::String::NewFromUtf8(env->GetIsolate(), "start"); |
| 963 // Don't allow |foo| node to be at the top level. | 951 // Don't allow |foo| node to be at the top level. |
| 964 CheckChildrenNames(root, names); | 952 CheckChildrenNames(root, names); |
| 965 | 953 |
| 966 const v8::CpuProfileNode* startNode = | 954 const v8::CpuProfileNode* startNode = |
| 967 GetChild(env->GetIsolate(), root, "start"); | 955 GetChild(env->GetIsolate(), root, "start"); |
| 968 GetChild(env->GetIsolate(), startNode, "foo"); | 956 GetChild(env->GetIsolate(), startNode, "foo"); |
| 969 | 957 |
| 970 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 958 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 971 cpu_profiler->DeleteAllCpuProfiles(); | |
| 972 } | 959 } |
| 973 | 960 |
| 974 | 961 |
| 975 static const char* call_function_test_source = "function bar(iterations) {\n" | 962 static const char* call_function_test_source = "function bar(iterations) {\n" |
| 976 "}\n" | 963 "}\n" |
| 977 "function start(duration) {\n" | 964 "function start(duration) {\n" |
| 978 " var start = Date.now();\n" | 965 " var start = Date.now();\n" |
| 979 " while (Date.now() - start < duration) {\n" | 966 " while (Date.now() - start < duration) {\n" |
| 980 " try {\n" | 967 " try {\n" |
| 981 " bar.call(this, 10 * 1000);\n" | 968 " bar.call(this, 10 * 1000);\n" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 } | 1029 } |
| 1043 | 1030 |
| 1044 const v8::CpuProfileNode* unresolvedNode = FindChild( | 1031 const v8::CpuProfileNode* unresolvedNode = FindChild( |
| 1045 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); | 1032 env->GetIsolate(), root, i::ProfileGenerator::kUnresolvedFunctionName); |
| 1046 if (unresolvedNode) { | 1033 if (unresolvedNode) { |
| 1047 ScopedVector<v8::Handle<v8::String> > names(1); | 1034 ScopedVector<v8::Handle<v8::String> > names(1); |
| 1048 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); | 1035 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "call"); |
| 1049 CheckChildrenNames(unresolvedNode, names); | 1036 CheckChildrenNames(unresolvedNode, names); |
| 1050 } | 1037 } |
| 1051 | 1038 |
| 1052 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1039 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 1053 cpu_profiler->DeleteAllCpuProfiles(); | |
| 1054 } | 1040 } |
| 1055 | 1041 |
| 1056 | 1042 |
| 1057 static const char* function_apply_test_source = "function bar(iterations) {\n" | 1043 static const char* function_apply_test_source = "function bar(iterations) {\n" |
| 1058 "}\n" | 1044 "}\n" |
| 1059 "function test() {\n" | 1045 "function test() {\n" |
| 1060 " bar.apply(this, [10 * 1000]);\n" | 1046 " bar.apply(this, [10 * 1000]);\n" |
| 1061 "}\n" | 1047 "}\n" |
| 1062 "function start(duration) {\n" | 1048 "function start(duration) {\n" |
| 1063 " var start = Date.now();\n" | 1049 " var start = Date.now();\n" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 if (const v8::CpuProfileNode* unresolvedNode = | 1116 if (const v8::CpuProfileNode* unresolvedNode = |
| 1131 FindChild(env->GetIsolate(), startNode, | 1117 FindChild(env->GetIsolate(), startNode, |
| 1132 ProfileGenerator::kUnresolvedFunctionName)) { | 1118 ProfileGenerator::kUnresolvedFunctionName)) { |
| 1133 ScopedVector<v8::Handle<v8::String> > names(1); | 1119 ScopedVector<v8::Handle<v8::String> > names(1); |
| 1134 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); | 1120 names[0] = v8::String::NewFromUtf8(env->GetIsolate(), "apply"); |
| 1135 CheckChildrenNames(unresolvedNode, names); | 1121 CheckChildrenNames(unresolvedNode, names); |
| 1136 GetChild(env->GetIsolate(), unresolvedNode, "apply"); | 1122 GetChild(env->GetIsolate(), unresolvedNode, "apply"); |
| 1137 } | 1123 } |
| 1138 } | 1124 } |
| 1139 | 1125 |
| 1140 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1126 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 1141 cpu_profiler->DeleteAllCpuProfiles(); | |
| 1142 } | 1127 } |
| 1143 | 1128 |
| 1144 | 1129 |
| 1145 static const char* js_native_js_test_source = | 1130 static const char* js_native_js_test_source = |
| 1146 "var is_profiling = false;\n" | 1131 "var is_profiling = false;\n" |
| 1147 "function foo(iterations) {\n" | 1132 "function foo(iterations) {\n" |
| 1148 " if (!is_profiling) {\n" | 1133 " if (!is_profiling) {\n" |
| 1149 " is_profiling = true;\n" | 1134 " is_profiling = true;\n" |
| 1150 " startProfiling('my_profile');\n" | 1135 " startProfiling('my_profile');\n" |
| 1151 " }\n" | 1136 " }\n" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 const v8::CpuProfileNode* nativeFunctionNode = | 1204 const v8::CpuProfileNode* nativeFunctionNode = |
| 1220 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); | 1205 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); |
| 1221 | 1206 |
| 1222 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1207 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
| 1223 const v8::CpuProfileNode* barNode = | 1208 const v8::CpuProfileNode* barNode = |
| 1224 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | 1209 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
| 1225 | 1210 |
| 1226 CHECK_EQ(1, barNode->GetChildrenCount()); | 1211 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1227 GetChild(env->GetIsolate(), barNode, "foo"); | 1212 GetChild(env->GetIsolate(), barNode, "foo"); |
| 1228 | 1213 |
| 1229 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1214 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 1230 cpu_profiler->DeleteAllCpuProfiles(); | |
| 1231 } | 1215 } |
| 1232 | 1216 |
| 1233 | 1217 |
| 1234 static const char* js_native_js_runtime_js_test_source = | 1218 static const char* js_native_js_runtime_js_test_source = |
| 1235 "var is_profiling = false;\n" | 1219 "var is_profiling = false;\n" |
| 1236 "function foo(iterations) {\n" | 1220 "function foo(iterations) {\n" |
| 1237 " if (!is_profiling) {\n" | 1221 " if (!is_profiling) {\n" |
| 1238 " is_profiling = true;\n" | 1222 " is_profiling = true;\n" |
| 1239 " startProfiling('my_profile');\n" | 1223 " startProfiling('my_profile');\n" |
| 1240 " }\n" | 1224 " }\n" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 const v8::CpuProfileNode* nativeFunctionNode = | 1286 const v8::CpuProfileNode* nativeFunctionNode = |
| 1303 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); | 1287 GetChild(env->GetIsolate(), startNode, "CallJsFunction"); |
| 1304 | 1288 |
| 1305 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); | 1289 CHECK_EQ(1, nativeFunctionNode->GetChildrenCount()); |
| 1306 const v8::CpuProfileNode* barNode = | 1290 const v8::CpuProfileNode* barNode = |
| 1307 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); | 1291 GetChild(env->GetIsolate(), nativeFunctionNode, "bar"); |
| 1308 | 1292 |
| 1309 CHECK_EQ(1, barNode->GetChildrenCount()); | 1293 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1310 GetChild(env->GetIsolate(), barNode, "foo"); | 1294 GetChild(env->GetIsolate(), barNode, "foo"); |
| 1311 | 1295 |
| 1312 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1296 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 1313 cpu_profiler->DeleteAllCpuProfiles(); | |
| 1314 } | 1297 } |
| 1315 | 1298 |
| 1316 | 1299 |
| 1317 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1300 static void CallJsFunction2(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 1318 CallJsFunction(info); | 1301 CallJsFunction(info); |
| 1319 } | 1302 } |
| 1320 | 1303 |
| 1321 | 1304 |
| 1322 static const char* js_native1_js_native2_js_test_source = | 1305 static const char* js_native1_js_native2_js_test_source = |
| 1323 "var is_profiling = false;\n" | 1306 "var is_profiling = false;\n" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 const v8::CpuProfileNode* barNode = | 1383 const v8::CpuProfileNode* barNode = |
| 1401 GetChild(env->GetIsolate(), nativeNode1, "bar"); | 1384 GetChild(env->GetIsolate(), nativeNode1, "bar"); |
| 1402 | 1385 |
| 1403 CHECK_EQ(1, barNode->GetChildrenCount()); | 1386 CHECK_EQ(1, barNode->GetChildrenCount()); |
| 1404 const v8::CpuProfileNode* nativeNode2 = | 1387 const v8::CpuProfileNode* nativeNode2 = |
| 1405 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); | 1388 GetChild(env->GetIsolate(), barNode, "CallJsFunction2"); |
| 1406 | 1389 |
| 1407 CHECK_EQ(1, nativeNode2->GetChildrenCount()); | 1390 CHECK_EQ(1, nativeNode2->GetChildrenCount()); |
| 1408 GetChild(env->GetIsolate(), nativeNode2, "foo"); | 1391 GetChild(env->GetIsolate(), nativeNode2, "foo"); |
| 1409 | 1392 |
| 1410 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 1393 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 1411 cpu_profiler->DeleteAllCpuProfiles(); | |
| 1412 } | 1394 } |
| 1413 | 1395 |
| 1414 | 1396 |
| 1415 // [Top down]: | 1397 // [Top down]: |
| 1416 // 6 0 (root) #0 1 | 1398 // 6 0 (root) #0 1 |
| 1417 // 3 3 (program) #0 2 | 1399 // 3 3 (program) #0 2 |
| 1418 // 3 3 (idle) #0 3 | 1400 // 3 3 (idle) #0 3 |
| 1419 TEST(IdleTime) { | 1401 TEST(IdleTime) { |
| 1420 LocalContext env; | 1402 LocalContext env; |
| 1421 v8::HandleScope scope(env->GetIsolate()); | 1403 v8::HandleScope scope(env->GetIsolate()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 const v8::CpuProfileNode* programNode = | 1440 const v8::CpuProfileNode* programNode = |
| 1459 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); | 1441 GetChild(env->GetIsolate(), root, ProfileGenerator::kProgramEntryName); |
| 1460 CHECK_EQ(0, programNode->GetChildrenCount()); | 1442 CHECK_EQ(0, programNode->GetChildrenCount()); |
| 1461 CHECK_GE(programNode->GetHitCount(), 3); | 1443 CHECK_GE(programNode->GetHitCount(), 3); |
| 1462 | 1444 |
| 1463 const v8::CpuProfileNode* idleNode = | 1445 const v8::CpuProfileNode* idleNode = |
| 1464 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); | 1446 GetChild(env->GetIsolate(), root, ProfileGenerator::kIdleEntryName); |
| 1465 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1447 CHECK_EQ(0, idleNode->GetChildrenCount()); |
| 1466 CHECK_GE(idleNode->GetHitCount(), 3); | 1448 CHECK_GE(idleNode->GetHitCount(), 3); |
| 1467 | 1449 |
| 1468 cpu_profiler->DeleteAllCpuProfiles(); | 1450 const_cast<v8::CpuProfile*>(profile)->Delete(); |
| 1469 } | 1451 } |
| 1470 | 1452 |
| 1471 | 1453 |
| 1472 static void CheckFunctionDetails(v8::Isolate* isolate, | 1454 static void CheckFunctionDetails(v8::Isolate* isolate, |
| 1473 const v8::CpuProfileNode* node, | 1455 const v8::CpuProfileNode* node, |
| 1474 const char* name, const char* script_name, | 1456 const char* name, const char* script_name, |
| 1475 int script_id, int line, int column) { | 1457 int script_id, int line, int column) { |
| 1476 CHECK_EQ(v8::String::NewFromUtf8(isolate, name), | 1458 CHECK_EQ(v8::String::NewFromUtf8(isolate, name), |
| 1477 node->GetFunctionName()); | 1459 node->GetFunctionName()); |
| 1478 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name), | 1460 CHECK_EQ(v8::String::NewFromUtf8(isolate, script_name), |
| 1479 node->GetScriptResourceName()); | 1461 node->GetScriptResourceName()); |
| 1480 CHECK_EQ(script_id, node->GetScriptId()); | 1462 CHECK_EQ(script_id, node->GetScriptId()); |
| 1481 CHECK_EQ(line, node->GetLineNumber()); | 1463 CHECK_EQ(line, node->GetLineNumber()); |
| 1482 CHECK_EQ(column, node->GetColumnNumber()); | 1464 CHECK_EQ(column, node->GetColumnNumber()); |
| 1483 } | 1465 } |
| 1484 | 1466 |
| 1485 | 1467 |
| 1486 TEST(FunctionDetails) { | 1468 TEST(FunctionDetails) { |
| 1487 const char* extensions[] = { "v8/profiler" }; | 1469 const char* extensions[] = { "v8/profiler" }; |
| 1488 v8::ExtensionConfiguration config(1, extensions); | 1470 v8::ExtensionConfiguration config(1, extensions); |
| 1489 LocalContext env(&config); | 1471 LocalContext env(&config); |
| 1490 v8::HandleScope handleScope(env->GetIsolate()); | 1472 v8::HandleScope handleScope(env->GetIsolate()); |
| 1491 | 1473 |
| 1492 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); | |
| 1493 CHECK_EQ(0, profiler->GetProfileCount()); | |
| 1494 v8::Handle<v8::Script> script_a = v8::Script::Compile( | 1474 v8::Handle<v8::Script> script_a = v8::Script::Compile( |
| 1495 v8::String::NewFromUtf8( | 1475 v8::String::NewFromUtf8( |
| 1496 env->GetIsolate(), | 1476 env->GetIsolate(), |
| 1497 " function foo\n() { try { bar(); } catch(e) {} }\n" | 1477 " function foo\n() { try { bar(); } catch(e) {} }\n" |
| 1498 " function bar() { startProfiling(); }\n"), | 1478 " function bar() { startProfiling(); }\n"), |
| 1499 v8::String::NewFromUtf8(env->GetIsolate(), "script_a")); | 1479 v8::String::NewFromUtf8(env->GetIsolate(), "script_a")); |
| 1500 script_a->Run(); | 1480 script_a->Run(); |
| 1501 v8::Handle<v8::Script> script_b = v8::Script::Compile( | 1481 v8::Handle<v8::Script> script_b = v8::Script::Compile( |
| 1502 v8::String::NewFromUtf8( | 1482 v8::String::NewFromUtf8( |
| 1503 env->GetIsolate(), | 1483 env->GetIsolate(), |
| 1504 "\n\n function baz() { try { foo(); } catch(e) {} }\n" | 1484 "\n\n function baz() { try { foo(); } catch(e) {} }\n" |
| 1505 "\n\nbaz();\n" | 1485 "\n\nbaz();\n" |
| 1506 "stopProfiling();\n"), | 1486 "stopProfiling();\n"), |
| 1507 v8::String::NewFromUtf8(env->GetIsolate(), "script_b")); | 1487 v8::String::NewFromUtf8(env->GetIsolate(), "script_b")); |
| 1508 script_b->Run(); | 1488 script_b->Run(); |
| 1509 CHECK_EQ(1, profiler->GetProfileCount()); | 1489 const v8::CpuProfile* profile = ProfilerExtension::last_profile; |
| 1510 const v8::CpuProfile* profile = profiler->GetCpuProfile(0); | |
| 1511 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); | 1490 const v8::CpuProfileNode* current = profile->GetTopDownRoot(); |
| 1512 reinterpret_cast<ProfileNode*>( | 1491 reinterpret_cast<ProfileNode*>( |
| 1513 const_cast<v8::CpuProfileNode*>(current))->Print(0); | 1492 const_cast<v8::CpuProfileNode*>(current))->Print(0); |
| 1514 // The tree should look like this: | 1493 // The tree should look like this: |
| 1515 // 0 (root) 0 #1 | 1494 // 0 (root) 0 #1 |
| 1516 // 0 (anonymous function) 19 #2 no reason script_b:1 | 1495 // 0 (anonymous function) 19 #2 no reason script_b:1 |
| 1517 // 0 baz 19 #3 TryCatchStatement script_b:3 | 1496 // 0 baz 19 #3 TryCatchStatement script_b:3 |
| 1518 // 0 foo 18 #4 TryCatchStatement script_a:2 | 1497 // 0 foo 18 #4 TryCatchStatement script_a:2 |
| 1519 // 1 bar 18 #5 no reason script_a:3 | 1498 // 1 bar 18 #5 no reason script_a:3 |
| 1520 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); | 1499 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1536 | 1515 |
| 1537 | 1516 |
| 1538 TEST(DontStopOnFinishedProfileDelete) { | 1517 TEST(DontStopOnFinishedProfileDelete) { |
| 1539 const char* extensions[] = { "v8/profiler" }; | 1518 const char* extensions[] = { "v8/profiler" }; |
| 1540 v8::ExtensionConfiguration config(1, extensions); | 1519 v8::ExtensionConfiguration config(1, extensions); |
| 1541 LocalContext env(&config); | 1520 LocalContext env(&config); |
| 1542 v8::Isolate* isolate = env->GetIsolate(); | 1521 v8::Isolate* isolate = env->GetIsolate(); |
| 1543 v8::HandleScope handleScope(isolate); | 1522 v8::HandleScope handleScope(isolate); |
| 1544 | 1523 |
| 1545 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); | 1524 v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler(); |
| 1525 i::CpuProfiler* iprofiler = reinterpret_cast<i::CpuProfiler*>(profiler); |
| 1546 | 1526 |
| 1547 CHECK_EQ(0, profiler->GetProfileCount()); | 1527 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1548 v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer"); | 1528 v8::Handle<v8::String> outer = v8::String::NewFromUtf8(isolate, "outer"); |
| 1549 profiler->StartCpuProfiling(outer); | 1529 profiler->StartCpuProfiling(outer); |
| 1550 CHECK_EQ(0, profiler->GetProfileCount()); | 1530 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1551 | 1531 |
| 1552 v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner"); | 1532 v8::Handle<v8::String> inner = v8::String::NewFromUtf8(isolate, "inner"); |
| 1553 profiler->StartCpuProfiling(inner); | 1533 profiler->StartCpuProfiling(inner); |
| 1554 CHECK_EQ(0, profiler->GetProfileCount()); | 1534 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1555 | 1535 |
| 1556 const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(inner); | 1536 const v8::CpuProfile* inner_profile = profiler->StopCpuProfiling(inner); |
| 1557 CHECK(inner_profile); | 1537 CHECK(inner_profile); |
| 1558 CHECK_EQ(1, profiler->GetProfileCount()); | 1538 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 1559 const_cast<v8::CpuProfile*>(inner_profile)->Delete(); | 1539 const_cast<v8::CpuProfile*>(inner_profile)->Delete(); |
| 1560 inner_profile = NULL; | 1540 inner_profile = NULL; |
| 1561 CHECK_EQ(0, profiler->GetProfileCount()); | 1541 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1562 | 1542 |
| 1563 const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer); | 1543 const v8::CpuProfile* outer_profile = profiler->StopCpuProfiling(outer); |
| 1564 CHECK(outer_profile); | 1544 CHECK(outer_profile); |
| 1565 CHECK_EQ(1, profiler->GetProfileCount()); | 1545 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
| 1566 const_cast<v8::CpuProfile*>(outer_profile)->Delete(); | 1546 const_cast<v8::CpuProfile*>(outer_profile)->Delete(); |
| 1567 outer_profile = NULL; | 1547 outer_profile = NULL; |
| 1568 CHECK_EQ(0, profiler->GetProfileCount()); | 1548 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
| 1569 } | 1549 } |
| OLD | NEW |