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 30 matching lines...) Expand all Loading... | |
41 using i::ProfileGenerator; | 41 using i::ProfileGenerator; |
42 using i::ProfileNode; | 42 using i::ProfileNode; |
43 using i::ProfilerEventsProcessor; | 43 using i::ProfilerEventsProcessor; |
44 using i::ScopedVector; | 44 using i::ScopedVector; |
45 using i::Vector; | 45 using i::Vector; |
46 | 46 |
47 | 47 |
48 TEST(StartStop) { | 48 TEST(StartStop) { |
49 CpuProfilesCollection profiles; | 49 CpuProfilesCollection profiles; |
50 ProfileGenerator generator(&profiles); | 50 ProfileGenerator generator(&profiles); |
51 ProfilerEventsProcessor processor(&generator); | 51 ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(&generator); |
52 processor.Start(); | 52 processor->Start(); |
53 processor.StopSynchronously(); | 53 processor->StopSynchronously(); |
54 processor.Join(); | 54 delete processor; |
Jakob Kummerow
2013/08/23 10:25:39
You could use SmartPointer<ProfilerEventsProcessor
| |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 static inline i::Address ToAddress(int n) { | 58 static inline i::Address ToAddress(int n) { |
59 return reinterpret_cast<i::Address>(n); | 59 return reinterpret_cast<i::Address>(n); |
60 } | 60 } |
61 | 61 |
62 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, | 62 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc, |
63 i::Address frame1, | 63 i::Address frame1, |
64 i::Address frame2 = NULL, | 64 i::Address frame2 = NULL, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 i::Code* comment_code = CreateCode(&env); | 133 i::Code* comment_code = CreateCode(&env); |
134 i::Code* args5_code = CreateCode(&env); | 134 i::Code* args5_code = CreateCode(&env); |
135 i::Code* comment2_code = CreateCode(&env); | 135 i::Code* comment2_code = CreateCode(&env); |
136 i::Code* moved_code = CreateCode(&env); | 136 i::Code* moved_code = CreateCode(&env); |
137 i::Code* args3_code = CreateCode(&env); | 137 i::Code* args3_code = CreateCode(&env); |
138 i::Code* args4_code = CreateCode(&env); | 138 i::Code* args4_code = CreateCode(&env); |
139 | 139 |
140 CpuProfilesCollection* profiles = new CpuProfilesCollection; | 140 CpuProfilesCollection* profiles = new CpuProfilesCollection; |
141 profiles->StartProfiling("", 1, false); | 141 profiles->StartProfiling("", 1, false); |
142 ProfileGenerator generator(profiles); | 142 ProfileGenerator generator(profiles); |
143 ProfilerEventsProcessor processor(&generator); | 143 ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(&generator); |
144 processor.Start(); | 144 processor->Start(); |
145 CpuProfiler profiler(isolate, profiles, &generator, &processor); | 145 CpuProfiler profiler(isolate, profiles, &generator, processor); |
146 | 146 |
147 // Enqueue code creation events. | 147 // Enqueue code creation events. |
148 const char* aaa_str = "aaa"; | 148 const char* aaa_str = "aaa"; |
149 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( | 149 i::Handle<i::String> aaa_name = factory->NewStringFromAscii( |
150 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); | 150 i::Vector<const char>(aaa_str, i::StrLength(aaa_str))); |
151 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); | 151 profiler.CodeCreateEvent(i::Logger::FUNCTION_TAG, aaa_code, *aaa_name); |
152 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); | 152 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment_code, "comment"); |
153 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); | 153 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args5_code, 5); |
154 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); | 154 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, comment2_code, "comment2"); |
155 profiler.CodeMoveEvent(comment2_code->address(), moved_code->address()); | 155 profiler.CodeMoveEvent(comment2_code->address(), moved_code->address()); |
156 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3); | 156 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args3_code, 3); |
157 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4); | 157 profiler.CodeCreateEvent(i::Logger::STUB_TAG, args4_code, 4); |
158 | 158 |
159 // Enqueue a tick event to enable code events processing. | 159 // Enqueue a tick event to enable code events processing. |
160 EnqueueTickSampleEvent(&processor, aaa_code->address()); | 160 EnqueueTickSampleEvent(processor, aaa_code->address()); |
161 | 161 |
162 processor.StopSynchronously(); | 162 processor->StopSynchronously(); |
163 processor.Join(); | |
164 | 163 |
165 // Check the state of profile generator. | 164 // Check the state of profile generator. |
166 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address()); | 165 CodeEntry* aaa = generator.code_map()->FindEntry(aaa_code->address()); |
167 CHECK_NE(NULL, aaa); | 166 CHECK_NE(NULL, aaa); |
168 CHECK_EQ(aaa_str, aaa->name()); | 167 CHECK_EQ(aaa_str, aaa->name()); |
169 | 168 |
170 CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address()); | 169 CodeEntry* comment = generator.code_map()->FindEntry(comment_code->address()); |
171 CHECK_NE(NULL, comment); | 170 CHECK_NE(NULL, comment); |
172 CHECK_EQ("comment", comment->name()); | 171 CHECK_EQ("comment", comment->name()); |
173 | 172 |
174 CodeEntry* args5 = generator.code_map()->FindEntry(args5_code->address()); | 173 CodeEntry* args5 = generator.code_map()->FindEntry(args5_code->address()); |
175 CHECK_NE(NULL, args5); | 174 CHECK_NE(NULL, args5); |
176 CHECK_EQ("5", args5->name()); | 175 CHECK_EQ("5", args5->name()); |
177 | 176 |
178 CHECK_EQ(NULL, generator.code_map()->FindEntry(comment2_code->address())); | 177 CHECK_EQ(NULL, generator.code_map()->FindEntry(comment2_code->address())); |
179 | 178 |
180 CodeEntry* comment2 = generator.code_map()->FindEntry(moved_code->address()); | 179 CodeEntry* comment2 = generator.code_map()->FindEntry(moved_code->address()); |
181 CHECK_NE(NULL, comment2); | 180 CHECK_NE(NULL, comment2); |
182 CHECK_EQ("comment2", comment2->name()); | 181 CHECK_EQ("comment2", comment2->name()); |
182 | |
183 delete processor; | |
183 } | 184 } |
184 | 185 |
185 | 186 |
186 template<typename T> | 187 template<typename T> |
187 static int CompareProfileNodes(const T* p1, const T* p2) { | 188 static int CompareProfileNodes(const T* p1, const T* p2) { |
188 return strcmp((*p1)->entry()->name(), (*p2)->entry()->name()); | 189 return strcmp((*p1)->entry()->name(), (*p2)->entry()->name()); |
189 } | 190 } |
190 | 191 |
191 | 192 |
192 TEST(TickEvents) { | 193 TEST(TickEvents) { |
193 TestSetup test_setup; | 194 TestSetup test_setup; |
194 LocalContext env; | 195 LocalContext env; |
195 i::Isolate* isolate = i::Isolate::Current(); | 196 i::Isolate* isolate = i::Isolate::Current(); |
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; | 203 CpuProfilesCollection* profiles = new CpuProfilesCollection; |
203 profiles->StartProfiling("", 1, false); | 204 profiles->StartProfiling("", 1, false); |
204 ProfileGenerator generator(profiles); | 205 ProfileGenerator generator(profiles); |
205 ProfilerEventsProcessor processor(&generator); | 206 ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(&generator); |
206 processor.Start(); | 207 processor->Start(); |
207 CpuProfiler profiler(isolate, profiles, &generator, &processor); | 208 CpuProfiler profiler(isolate, profiles, &generator, processor); |
208 | 209 |
209 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); | 210 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame1_code, "bbb"); |
210 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); | 211 profiler.CodeCreateEvent(i::Logger::STUB_TAG, frame2_code, 5); |
211 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); | 212 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, frame3_code, "ddd"); |
212 | 213 |
213 EnqueueTickSampleEvent(&processor, frame1_code->instruction_start()); | 214 EnqueueTickSampleEvent(processor, frame1_code->instruction_start()); |
214 EnqueueTickSampleEvent( | 215 EnqueueTickSampleEvent( |
215 &processor, | 216 processor, |
216 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, | 217 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, |
217 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); | 218 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); |
218 EnqueueTickSampleEvent( | 219 EnqueueTickSampleEvent( |
219 &processor, | 220 processor, |
220 frame3_code->instruction_end() - 1, | 221 frame3_code->instruction_end() - 1, |
221 frame2_code->instruction_end() - 1, | 222 frame2_code->instruction_end() - 1, |
222 frame1_code->instruction_end() - 1); | 223 frame1_code->instruction_end() - 1); |
223 | 224 |
224 processor.StopSynchronously(); | 225 processor->StopSynchronously(); |
225 processor.Join(); | |
226 CpuProfile* profile = profiles->StopProfiling(""); | 226 CpuProfile* profile = profiles->StopProfiling(""); |
227 CHECK_NE(NULL, profile); | 227 CHECK_NE(NULL, profile); |
228 | 228 |
229 // Check call trees. | 229 // Check call trees. |
230 const i::List<ProfileNode*>* top_down_root_children = | 230 const i::List<ProfileNode*>* top_down_root_children = |
231 profile->top_down()->root()->children(); | 231 profile->top_down()->root()->children(); |
232 CHECK_EQ(1, top_down_root_children->length()); | 232 CHECK_EQ(1, top_down_root_children->length()); |
233 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name()); | 233 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name()); |
234 const i::List<ProfileNode*>* top_down_bbb_children = | 234 const i::List<ProfileNode*>* top_down_bbb_children = |
235 top_down_root_children->last()->children(); | 235 top_down_root_children->last()->children(); |
236 CHECK_EQ(1, top_down_bbb_children->length()); | 236 CHECK_EQ(1, top_down_bbb_children->length()); |
237 CHECK_EQ("5", top_down_bbb_children->last()->entry()->name()); | 237 CHECK_EQ("5", top_down_bbb_children->last()->entry()->name()); |
238 const i::List<ProfileNode*>* top_down_stub_children = | 238 const i::List<ProfileNode*>* top_down_stub_children = |
239 top_down_bbb_children->last()->children(); | 239 top_down_bbb_children->last()->children(); |
240 CHECK_EQ(1, top_down_stub_children->length()); | 240 CHECK_EQ(1, top_down_stub_children->length()); |
241 CHECK_EQ("ddd", top_down_stub_children->last()->entry()->name()); | 241 CHECK_EQ("ddd", top_down_stub_children->last()->entry()->name()); |
242 const i::List<ProfileNode*>* top_down_ddd_children = | 242 const i::List<ProfileNode*>* top_down_ddd_children = |
243 top_down_stub_children->last()->children(); | 243 top_down_stub_children->last()->children(); |
244 CHECK_EQ(0, top_down_ddd_children->length()); | 244 CHECK_EQ(0, top_down_ddd_children->length()); |
245 | |
246 delete processor; | |
245 } | 247 } |
246 | 248 |
247 | 249 |
248 // http://crbug/51594 | 250 // http://crbug/51594 |
249 // This test must not crash. | 251 // This test must not crash. |
250 TEST(CrashIfStoppingLastNonExistentProfile) { | 252 TEST(CrashIfStoppingLastNonExistentProfile) { |
251 CcTest::InitializeVM(); | 253 CcTest::InitializeVM(); |
252 TestSetup test_setup; | 254 TestSetup test_setup; |
253 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); | 255 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); |
254 profiler->StartProfiling("1"); | 256 profiler->StartProfiling("1"); |
255 profiler->StopProfiling("2"); | 257 profiler->StopProfiling("2"); |
256 profiler->StartProfiling("1"); | 258 profiler->StartProfiling("1"); |
257 profiler->StopProfiling(""); | 259 profiler->StopProfiling(""); |
258 } | 260 } |
259 | 261 |
260 | 262 |
261 // http://code.google.com/p/v8/issues/detail?id=1398 | 263 // http://code.google.com/p/v8/issues/detail?id=1398 |
262 // Long stacks (exceeding max frames limit) must not be erased. | 264 // Long stacks (exceeding max frames limit) must not be erased. |
263 TEST(Issue1398) { | 265 TEST(Issue1398) { |
264 TestSetup test_setup; | 266 TestSetup test_setup; |
265 LocalContext env; | 267 LocalContext env; |
266 i::Isolate* isolate = i::Isolate::Current(); | 268 i::Isolate* isolate = i::Isolate::Current(); |
267 i::HandleScope scope(isolate); | 269 i::HandleScope scope(isolate); |
268 | 270 |
269 i::Code* code = CreateCode(&env); | 271 i::Code* code = CreateCode(&env); |
270 | 272 |
271 CpuProfilesCollection* profiles = new CpuProfilesCollection; | 273 CpuProfilesCollection* profiles = new CpuProfilesCollection; |
272 profiles->StartProfiling("", 1, false); | 274 profiles->StartProfiling("", 1, false); |
273 ProfileGenerator generator(profiles); | 275 ProfileGenerator generator(profiles); |
274 ProfilerEventsProcessor processor(&generator); | 276 ProfilerEventsProcessor* processor = new ProfilerEventsProcessor(&generator); |
275 processor.Start(); | 277 processor->Start(); |
276 CpuProfiler profiler(isolate, profiles, &generator, &processor); | 278 CpuProfiler profiler(isolate, profiles, &generator, processor); |
277 | 279 |
278 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); | 280 profiler.CodeCreateEvent(i::Logger::BUILTIN_TAG, code, "bbb"); |
279 | 281 |
280 i::TickSample* sample = processor.StartTickSample(); | 282 i::TickSample* sample = processor->StartTickSample(); |
281 sample->pc = code->address(); | 283 sample->pc = code->address(); |
282 sample->tos = 0; | 284 sample->tos = 0; |
283 sample->frames_count = i::TickSample::kMaxFramesCount; | 285 sample->frames_count = i::TickSample::kMaxFramesCount; |
284 for (int i = 0; i < sample->frames_count; ++i) { | 286 for (int i = 0; i < sample->frames_count; ++i) { |
285 sample->stack[i] = code->address(); | 287 sample->stack[i] = code->address(); |
286 } | 288 } |
287 processor.FinishTickSample(); | 289 processor->FinishTickSample(); |
288 | 290 |
289 processor.StopSynchronously(); | 291 processor->StopSynchronously(); |
290 processor.Join(); | |
291 CpuProfile* profile = profiles->StopProfiling(""); | 292 CpuProfile* profile = profiles->StopProfiling(""); |
292 CHECK_NE(NULL, profile); | 293 CHECK_NE(NULL, profile); |
293 | 294 |
294 int actual_depth = 0; | 295 int actual_depth = 0; |
295 const ProfileNode* node = profile->top_down()->root(); | 296 const ProfileNode* node = profile->top_down()->root(); |
296 while (node->children()->length() > 0) { | 297 while (node->children()->length() > 0) { |
297 node = node->children()->last(); | 298 node = node->children()->last(); |
298 ++actual_depth; | 299 ++actual_depth; |
299 } | 300 } |
300 | 301 |
301 CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. | 302 CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. |
303 delete processor; | |
302 } | 304 } |
303 | 305 |
304 | 306 |
305 TEST(DeleteAllCpuProfiles) { | 307 TEST(DeleteAllCpuProfiles) { |
306 CcTest::InitializeVM(); | 308 CcTest::InitializeVM(); |
307 TestSetup test_setup; | 309 TestSetup test_setup; |
308 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); | 310 CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler(); |
309 CHECK_EQ(0, profiler->GetProfilesCount()); | 311 CHECK_EQ(0, profiler->GetProfilesCount()); |
310 profiler->DeleteAllProfiles(); | 312 profiler->DeleteAllProfiles(); |
311 CHECK_EQ(0, profiler->GetProfilesCount()); | 313 CHECK_EQ(0, profiler->GetProfilesCount()); |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 CHECK_GE(programNode->GetHitCount(), 3); | 1376 CHECK_GE(programNode->GetHitCount(), 3); |
1375 | 1377 |
1376 const v8::CpuProfileNode* idleNode = | 1378 const v8::CpuProfileNode* idleNode = |
1377 GetChild(root, ProfileGenerator::kIdleEntryName); | 1379 GetChild(root, ProfileGenerator::kIdleEntryName); |
1378 CHECK_EQ(0, idleNode->GetChildrenCount()); | 1380 CHECK_EQ(0, idleNode->GetChildrenCount()); |
1379 CHECK_GE(idleNode->GetSelfSamplesCount(), 3); | 1381 CHECK_GE(idleNode->GetSelfSamplesCount(), 3); |
1380 CHECK_GE(idleNode->GetHitCount(), 3); | 1382 CHECK_GE(idleNode->GetHitCount(), 3); |
1381 | 1383 |
1382 cpu_profiler->DeleteAllCpuProfiles(); | 1384 cpu_profiler->DeleteAllCpuProfiles(); |
1383 } | 1385 } |
OLD | NEW |