OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // | 2 // |
3 // Tests of profiles generator and utilities. | 3 // Tests of profiles generator and utilities. |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 #include "cpu-profiler-inl.h" | 6 #include "cpu-profiler-inl.h" |
7 #include "cctest.h" | 7 #include "cctest.h" |
8 #include "../include/v8-profiler.h" | 8 #include "../include/v8-profiler.h" |
9 | 9 |
10 using i::CodeEntry; | 10 using i::CodeEntry; |
11 using i::CpuProfile; | 11 using i::CpuProfile; |
12 using i::CpuProfiler; | 12 using i::CpuProfiler; |
13 using i::CpuProfilesCollection; | 13 using i::CpuProfilesCollection; |
14 using i::ProfileGenerator; | 14 using i::ProfileGenerator; |
15 using i::ProfileNode; | 15 using i::ProfileNode; |
16 using i::ProfilerEventsProcessor; | 16 using i::ProfilerEventsProcessor; |
17 using i::TokenEnumerator; | 17 using i::TokenEnumerator; |
18 | 18 |
19 | 19 |
20 TEST(StartStop) { | 20 TEST(StartStop) { |
21 CpuProfilesCollection profiles; | 21 CpuProfilesCollection profiles; |
22 ProfileGenerator generator(&profiles); | 22 ProfileGenerator generator(&profiles); |
23 ProfilerEventsProcessor processor(&generator); | 23 ProfilerEventsProcessor processor(&generator, NULL, 1000); |
24 processor.Start(); | 24 processor.Start(); |
25 processor.Stop(); | 25 processor.Stop(); |
26 processor.Join(); | 26 processor.Join(); |
27 } | 27 } |
28 | 28 |
29 static v8::Persistent<v8::Context> env; | 29 static v8::Persistent<v8::Context> env; |
30 | 30 |
31 static void InitializeVM() { | 31 static void InitializeVM() { |
32 if (env.IsEmpty()) env = v8::Context::New(); | 32 if (env.IsEmpty()) env = v8::Context::New(); |
33 v8::HandleScope scope; | 33 v8::HandleScope scope; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 }; | 74 }; |
75 | 75 |
76 } // namespace | 76 } // namespace |
77 | 77 |
78 TEST(CodeEvents) { | 78 TEST(CodeEvents) { |
79 InitializeVM(); | 79 InitializeVM(); |
80 TestSetup test_setup; | 80 TestSetup test_setup; |
81 CpuProfilesCollection profiles; | 81 CpuProfilesCollection profiles; |
82 profiles.StartProfiling("", 1); | 82 profiles.StartProfiling("", 1); |
83 ProfileGenerator generator(&profiles); | 83 ProfileGenerator generator(&profiles); |
84 ProfilerEventsProcessor processor(&generator); | 84 ProfilerEventsProcessor processor(&generator, NULL, 1000); |
85 processor.Start(); | 85 processor.Start(); |
86 | 86 |
87 // Enqueue code creation events. | 87 // Enqueue code creation events. |
88 i::HandleScope scope; | 88 i::HandleScope scope; |
89 const char* aaa_str = "aaa"; | 89 const char* aaa_str = "aaa"; |
90 i::Handle<i::String> aaa_name = FACTORY->NewStringFromAscii( | 90 i::Handle<i::String> aaa_name = FACTORY->NewStringFromAscii( |
91 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); | 91 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); |
92 processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, | 92 processor.CodeCreateEvent(i::Logger::FUNCTION_TAG, |
93 *aaa_name, | 93 *aaa_name, |
94 HEAP->empty_string(), | 94 HEAP->empty_string(), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 template<typename T> | 135 template<typename T> |
136 static int CompareProfileNodes(const T* p1, const T* p2) { | 136 static int CompareProfileNodes(const T* p1, const T* p2) { |
137 return strcmp((*p1)->entry()->name(), (*p2)->entry()->name()); | 137 return strcmp((*p1)->entry()->name(), (*p2)->entry()->name()); |
138 } | 138 } |
139 | 139 |
140 TEST(TickEvents) { | 140 TEST(TickEvents) { |
141 TestSetup test_setup; | 141 TestSetup test_setup; |
142 CpuProfilesCollection profiles; | 142 CpuProfilesCollection profiles; |
143 profiles.StartProfiling("", 1); | 143 profiles.StartProfiling("", 1); |
144 ProfileGenerator generator(&profiles); | 144 ProfileGenerator generator(&profiles); |
145 ProfilerEventsProcessor processor(&generator); | 145 ProfilerEventsProcessor processor(&generator, NULL, 1000); |
146 processor.Start(); | 146 processor.Start(); |
147 | 147 |
148 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 148 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
149 "bbb", | 149 "bbb", |
150 ToAddress(0x1200), | 150 ToAddress(0x1200), |
151 0x80); | 151 0x80); |
152 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); | 152 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10); |
153 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 153 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
154 "ddd", | 154 "ddd", |
155 ToAddress(0x1400), | 155 ToAddress(0x1400), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 // http://code.google.com/p/v8/issues/detail?id=1398 | 228 // http://code.google.com/p/v8/issues/detail?id=1398 |
229 // Long stacks (exceeding max frames limit) must not be erased. | 229 // Long stacks (exceeding max frames limit) must not be erased. |
230 TEST(Issue1398) { | 230 TEST(Issue1398) { |
231 TestSetup test_setup; | 231 TestSetup test_setup; |
232 CpuProfilesCollection profiles; | 232 CpuProfilesCollection profiles; |
233 profiles.StartProfiling("", 1); | 233 profiles.StartProfiling("", 1); |
234 ProfileGenerator generator(&profiles); | 234 ProfileGenerator generator(&profiles); |
235 ProfilerEventsProcessor processor(&generator); | 235 ProfilerEventsProcessor processor(&generator, NULL, 1000); |
236 processor.Start(); | 236 processor.Start(); |
237 | 237 |
238 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, | 238 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG, |
239 "bbb", | 239 "bbb", |
240 ToAddress(0x1200), | 240 ToAddress(0x1200), |
241 0x80); | 241 0x80); |
242 | 242 |
243 i::TickSample* sample = processor.TickSampleEvent(); | 243 i::TickSample* sample = processor.TickSampleEvent(); |
244 sample->pc = ToAddress(0x1200); | 244 sample->pc = ToAddress(0x1200); |
245 sample->tos = 0; | 245 sample->tos = 0; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); | 390 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
391 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); | 391 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
392 const_cast<v8::CpuProfile*>(p2)->Delete(); | 392 const_cast<v8::CpuProfile*>(p2)->Delete(); |
393 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); | 393 CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount()); |
394 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); | 394 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2)); |
395 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); | 395 CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3)); |
396 const_cast<v8::CpuProfile*>(p3)->Delete(); | 396 const_cast<v8::CpuProfile*>(p3)->Delete(); |
397 CHECK_EQ(0, CpuProfiler::GetProfilesCount()); | 397 CHECK_EQ(0, CpuProfiler::GetProfilesCount()); |
398 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); | 398 CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3)); |
399 } | 399 } |
OLD | NEW |