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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 i::HandleScope scope(isolate); | 115 i::HandleScope scope(isolate); |
116 const char* aaa_str = "aaa"; | 116 const char* aaa_str = "aaa"; |
117 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( | 117 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( |
118 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); | 118 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); |
119 processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, | 119 processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, |
120 *aaa_name, | 120 *aaa_name, |
121 heap->empty_string(), | 121 heap->empty_string(), |
122 0, | 122 0, |
123 ToAddress(0x1000), | 123 ToAddress(0x1000), |
124 0x100, | 124 0x100, |
125 ToAddress(0x10000)); | 125 ToAddress(0x10000), |
| 126 NULL); |
126 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 127 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
127 "bbb", | 128 "bbb", |
128 ToAddress(0x1200), | 129 ToAddress(0x1200), |
129 0x80); | 130 0x80); |
130 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); | 131 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); |
131 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 132 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
132 "ddd", | 133 "ddd", |
133 ToAddress(0x1400), | 134 ToAddress(0x1400), |
134 0x80); | 135 0x80); |
135 processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500)); | 136 processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500)); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 543 |
543 const char* barBranch[] = { "bar", "delay", "loop" }; | 544 const char* barBranch[] = { "bar", "delay", "loop" }; |
544 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); | 545 CheckSimpleBranch(fooNode, barBranch, ARRAY_SIZE(barBranch)); |
545 const char* bazBranch[] = { "baz", "delay", "loop" }; | 546 const char* bazBranch[] = { "baz", "delay", "loop" }; |
546 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); | 547 CheckSimpleBranch(fooNode, bazBranch, ARRAY_SIZE(bazBranch)); |
547 const char* delayBranch[] = { "delay", "loop" }; | 548 const char* delayBranch[] = { "delay", "loop" }; |
548 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); | 549 CheckSimpleBranch(fooNode, delayBranch, ARRAY_SIZE(delayBranch)); |
549 | 550 |
550 cpu_profiler->DeleteAllCpuProfiles(); | 551 cpu_profiler->DeleteAllCpuProfiles(); |
551 } | 552 } |
| 553 |
| 554 |
| 555 |
| 556 static const char* cpu_profiler_test_source2 = "function loop() {}\n" |
| 557 "function delay() { loop(); }\n" |
| 558 "function start(count) {\n" |
| 559 " var k = 0;\n" |
| 560 " do {\n" |
| 561 " delay();\n" |
| 562 " } while (++k < count*100*1000);\n" |
| 563 "}\n"; |
| 564 |
| 565 // Check that the profile tree doesn't contain unexpecte traces: |
| 566 // - 'loop' can be called only by 'delay' |
| 567 // - 'delay' may be called only by 'start' |
| 568 // The profile will look like the following: |
| 569 // |
| 570 // [Top down]: |
| 571 // 135 0 (root) [-1] #1 |
| 572 // 121 72 start [-1] #3 |
| 573 // 49 33 delay [-1] #4 |
| 574 // 16 16 loop [-1] #5 |
| 575 // 14 14 (program) [-1] #2 |
| 576 TEST(SampleWhenFrameIsNotSetup) { |
| 577 LocalContext env; |
| 578 v8::HandleScope scope(env->GetIsolate()); |
| 579 |
| 580 v8::Script::Compile(v8::String::New(cpu_profiler_test_source2))->Run(); |
| 581 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
| 582 env->Global()->Get(v8::String::New("start"))); |
| 583 |
| 584 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
| 585 v8::Local<v8::String> profile_name = v8::String::New("my_profile"); |
| 586 |
| 587 cpu_profiler->StartCpuProfiling(profile_name); |
| 588 int32_t repeat_count = 100; |
| 589 #if defined(USE_SIMULATOR) |
| 590 // Simulators are much slower. |
| 591 repeat_count = 1; |
| 592 #endif |
| 593 v8::Handle<v8::Value> args[] = { v8::Integer::New(repeat_count) }; |
| 594 function->Call(env->Global(), ARRAY_SIZE(args), args); |
| 595 const v8::CpuProfile* profile = cpu_profiler->StopCpuProfiling(profile_name); |
| 596 |
| 597 CHECK_NE(NULL, profile); |
| 598 // Dump collected profile to have a better diagnostic in case of failure. |
| 599 reinterpret_cast<i::CpuProfile*>( |
| 600 const_cast<v8::CpuProfile*>(profile))->Print(); |
| 601 |
| 602 const v8::CpuProfileNode* root = profile->GetTopDownRoot(); |
| 603 |
| 604 ScopedVector<v8::Handle<v8::String> > names(3); |
| 605 names[0] = v8::String::New(ProfileGenerator::kGarbageCollectorEntryName); |
| 606 names[1] = v8::String::New(ProfileGenerator::kProgramEntryName); |
| 607 names[2] = v8::String::New("start"); |
| 608 CheckChildrenNames(root, names); |
| 609 |
| 610 const v8::CpuProfileNode* startNode = FindChild(root, "start"); |
| 611 if (startNode->GetChildrenCount() > 0) { |
| 612 CHECK_EQ(1, startNode->GetChildrenCount()); |
| 613 const v8::CpuProfileNode* delayNode = FindChild(startNode, "delay"); |
| 614 if (delayNode->GetChildrenCount() > 0) { |
| 615 CHECK_EQ(1, delayNode->GetChildrenCount()); |
| 616 FindChild(delayNode, "loop"); |
| 617 } |
| 618 } |
| 619 |
| 620 cpu_profiler->DeleteAllCpuProfiles(); |
| 621 } |
OLD | NEW |