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 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 "src/v8.h" | 30 #include "src/v8.h" |
31 | 31 |
32 #include "include/v8-profiler.h" | 32 #include "include/v8-profiler.h" |
| 33 #include "src/base/platform/platform.h" |
33 #include "src/cpu-profiler-inl.h" | 34 #include "src/cpu-profiler-inl.h" |
34 #include "src/platform.h" | |
35 #include "src/smart-pointers.h" | 35 #include "src/smart-pointers.h" |
36 #include "src/utils.h" | 36 #include "src/utils.h" |
37 #include "test/cctest/cctest.h" | 37 #include "test/cctest/cctest.h" |
38 #include "test/cctest/profiler-extension.h" | 38 #include "test/cctest/profiler-extension.h" |
39 using i::CodeEntry; | 39 using i::CodeEntry; |
40 using i::CpuProfile; | 40 using i::CpuProfile; |
41 using i::CpuProfiler; | 41 using i::CpuProfiler; |
42 using i::CpuProfilesCollection; | 42 using i::CpuProfilesCollection; |
43 using i::Heap; | 43 using i::Heap; |
44 using i::ProfileGenerator; | 44 using i::ProfileGenerator; |
45 using i::ProfileNode; | 45 using i::ProfileNode; |
46 using i::ProfilerEventsProcessor; | 46 using i::ProfilerEventsProcessor; |
47 using i::ScopedVector; | 47 using i::ScopedVector; |
48 using i::SmartPointer; | 48 using i::SmartPointer; |
49 using i::TimeDelta; | |
50 using i::Vector; | 49 using i::Vector; |
51 | 50 |
52 | 51 |
53 TEST(StartStop) { | 52 TEST(StartStop) { |
54 i::Isolate* isolate = CcTest::i_isolate(); | 53 i::Isolate* isolate = CcTest::i_isolate(); |
55 CpuProfilesCollection profiles(isolate->heap()); | 54 CpuProfilesCollection profiles(isolate->heap()); |
56 ProfileGenerator generator(&profiles); | 55 ProfileGenerator generator(&profiles); |
57 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 56 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
58 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 57 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); |
59 processor->Start(); | 58 processor->Start(); |
60 processor->StopSynchronously(); | 59 processor->StopSynchronously(); |
61 } | 60 } |
62 | 61 |
63 | 62 |
64 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, | 63 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, |
65 i::Address frame1, | 64 i::Address frame1, |
66 i::Address frame2 = NULL, | 65 i::Address frame2 = NULL, |
67 i::Address frame3 = NULL) { | 66 i::Address frame3 = NULL) { |
68 i::TickSample* sample = proc->StartTickSample(); | 67 i::TickSample* sample = proc->StartTickSample(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 i::Code* args5_code = CreateCode(&env); | 135 i::Code* args5_code = CreateCode(&env); |
137 i::Code* comment2_code = CreateCode(&env); | 136 i::Code* comment2_code = CreateCode(&env); |
138 i::Code* moved_code = CreateCode(&env); | 137 i::Code* moved_code = CreateCode(&env); |
139 i::Code* args3_code = CreateCode(&env); | 138 i::Code* args3_code = CreateCode(&env); |
140 i::Code* args4_code = CreateCode(&env); | 139 i::Code* args4_code = CreateCode(&env); |
141 | 140 |
142 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 141 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
143 profiles->StartProfiling("", false); | 142 profiles->StartProfiling("", false); |
144 ProfileGenerator generator(profiles); | 143 ProfileGenerator generator(profiles); |
145 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 144 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
146 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 145 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); |
147 processor->Start(); | 146 processor->Start(); |
148 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 147 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
149 | 148 |
150 // Enqueue code creation events. | 149 // Enqueue code creation events. |
151 const char* aaa_str = "aaa"; | 150 const char* aaa_str = "aaa"; |
152 i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str); | 151 i::Handle<i::String> aaa_name = factory->NewStringFromAsciiChecked(aaa_str); |
153 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); | 152 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); |
154 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); | 153 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); |
155 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); | 154 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); |
156 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); | 155 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 i::HandleScope scope(isolate); | 196 i::HandleScope scope(isolate); |
198 | 197 |
199 i::Code* frame1_code = CreateCode(&env); | 198 i::Code* frame1_code = CreateCode(&env); |
200 i::Code* frame2_code = CreateCode(&env); | 199 i::Code* frame2_code = CreateCode(&env); |
201 i::Code* frame3_code = CreateCode(&env); | 200 i::Code* frame3_code = CreateCode(&env); |
202 | 201 |
203 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 202 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
204 profiles->StartProfiling("", false); | 203 profiles->StartProfiling("", false); |
205 ProfileGenerator generator(profiles); | 204 ProfileGenerator generator(profiles); |
206 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 205 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
207 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 206 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); |
208 processor->Start(); | 207 processor->Start(); |
209 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 208 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
210 | 209 |
211 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); | 210 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); |
212 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); | 211 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); |
213 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); | 212 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); |
214 | 213 |
215 EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start()); | 214 EnqueueTickSampleEvent(processor.get(), frame1_code->instruction_start()); |
216 EnqueueTickSampleEvent( | 215 EnqueueTickSampleEvent( |
217 processor.get(), | 216 processor.get(), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 LocalContext env; | 265 LocalContext env; |
267 i::Isolate* isolate = CcTest::i_isolate(); | 266 i::Isolate* isolate = CcTest::i_isolate(); |
268 i::HandleScope scope(isolate); | 267 i::HandleScope scope(isolate); |
269 | 268 |
270 i::Code* code = CreateCode(&env); | 269 i::Code* code = CreateCode(&env); |
271 | 270 |
272 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); | 271 CpuProfilesCollection* profiles = new CpuProfilesCollection(isolate->heap()); |
273 profiles->StartProfiling("", false); | 272 profiles->StartProfiling("", false); |
274 ProfileGenerator generator(profiles); | 273 ProfileGenerator generator(profiles); |
275 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( | 274 SmartPointer<ProfilerEventsProcessor> processor(new ProfilerEventsProcessor( |
276 &generator, NULL, TimeDelta::FromMicroseconds(100))); | 275 &generator, NULL, v8::base::TimeDelta::FromMicroseconds(100))); |
277 processor->Start(); | 276 processor->Start(); |
278 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); | 277 CpuProfiler profiler(isolate, profiles, &generator, processor.get()); |
279 | 278 |
280 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); | 279 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); |
281 | 280 |
282 i::TickSample* sample = processor->StartTickSample(); | 281 i::TickSample* sample = processor->StartTickSample(); |
283 sample->pc = code->address(); | 282 sample->pc = code->address(); |
284 sample->tos = 0; | 283 sample->tos = 0; |
285 sample->frames_count = i::TickSample::kMaxFramesCount; | 284 sample->frames_count = i::TickSample::kMaxFramesCount; |
286 for (unsigned i = 0; i < sample->frames_count; ++i) { | 285 for (unsigned i = 0; i < sample->frames_count; ++i) { |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 static void Callback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 783 static void Callback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
785 TestApiCallbacks* data = fromInfo(info); | 784 TestApiCallbacks* data = fromInfo(info); |
786 data->Wait(); | 785 data->Wait(); |
787 } | 786 } |
788 | 787 |
789 void set_warming_up(bool value) { is_warming_up_ = value; } | 788 void set_warming_up(bool value) { is_warming_up_ = value; } |
790 | 789 |
791 private: | 790 private: |
792 void Wait() { | 791 void Wait() { |
793 if (is_warming_up_) return; | 792 if (is_warming_up_) return; |
794 double start = i::OS::TimeCurrentMillis(); | 793 double start = v8::base::OS::TimeCurrentMillis(); |
795 double duration = 0; | 794 double duration = 0; |
796 while (duration < min_duration_ms_) { | 795 while (duration < min_duration_ms_) { |
797 i::OS::Sleep(1); | 796 v8::base::OS::Sleep(1); |
798 duration = i::OS::TimeCurrentMillis() - start; | 797 duration = v8::base::OS::TimeCurrentMillis() - start; |
799 } | 798 } |
800 } | 799 } |
801 | 800 |
802 template<typename T> | 801 template<typename T> |
803 static TestApiCallbacks* fromInfo(const T& info) { | 802 static TestApiCallbacks* fromInfo(const T& info) { |
804 void* data = v8::External::Cast(*info.Data())->Value(); | 803 void* data = v8::External::Cast(*info.Data())->Value(); |
805 return reinterpret_cast<TestApiCallbacks*>(data); | 804 return reinterpret_cast<TestApiCallbacks*>(data); |
806 } | 805 } |
807 | 806 |
808 int min_duration_ms_; | 807 int min_duration_ms_; |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 inner_profile = NULL; | 1726 inner_profile = NULL; |
1728 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1727 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1729 | 1728 |
1730 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); | 1729 v8::CpuProfile* outer_profile = profiler->StopProfiling(outer); |
1731 CHECK(outer_profile); | 1730 CHECK(outer_profile); |
1732 CHECK_EQ(1, iprofiler->GetProfilesCount()); | 1731 CHECK_EQ(1, iprofiler->GetProfilesCount()); |
1733 outer_profile->Delete(); | 1732 outer_profile->Delete(); |
1734 outer_profile = NULL; | 1733 outer_profile = NULL; |
1735 CHECK_EQ(0, iprofiler->GetProfilesCount()); | 1734 CHECK_EQ(0, iprofiler->GetProfilesCount()); |
1736 } | 1735 } |
OLD | NEW |