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 26 matching lines...) Expand all Loading... |
37 #undef V8_DISABLE_DEPRECATIONS | 37 #undef V8_DISABLE_DEPRECATIONS |
38 | 38 |
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::ProfileGenerator; | 43 using i::ProfileGenerator; |
44 using i::ProfileNode; | 44 using i::ProfileNode; |
45 using i::ProfilerEventsProcessor; | 45 using i::ProfilerEventsProcessor; |
46 using i::ScopedVector; | 46 using i::ScopedVector; |
47 using i::TokenEnumerator; | |
48 using i::Vector; | 47 using i::Vector; |
49 | 48 |
50 | 49 |
51 TEST(StartStop) { | 50 TEST(StartStop) { |
52 CpuProfilesCollection profiles; | 51 CpuProfilesCollection profiles; |
53 ProfileGenerator generator(&profiles); | 52 ProfileGenerator generator(&profiles); |
54 ProfilerEventsProcessor processor(&generator); | 53 ProfilerEventsProcessor processor(&generator); |
55 processor.Start(); | 54 processor.Start(); |
56 processor.Stop(); | 55 processor.Stop(); |
57 processor.Join(); | 56 processor.Join(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, | 215 frame2_code->instruction_start() + frame2_code->ExecutableSize() / 2, |
217 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); | 216 frame1_code->instruction_start() + frame2_code->ExecutableSize() / 2); |
218 EnqueueTickSampleEvent( | 217 EnqueueTickSampleEvent( |
219 &processor, | 218 &processor, |
220 frame3_code->instruction_end() - 1, | 219 frame3_code->instruction_end() - 1, |
221 frame2_code->instruction_end() - 1, | 220 frame2_code->instruction_end() - 1, |
222 frame1_code->instruction_end() - 1); | 221 frame1_code->instruction_end() - 1); |
223 | 222 |
224 processor.Stop(); | 223 processor.Stop(); |
225 processor.Join(); | 224 processor.Join(); |
226 CpuProfile* profile = | 225 CpuProfile* profile = profiles->StopProfiling("", 1); |
227 profiles->StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); | |
228 CHECK_NE(NULL, profile); | 226 CHECK_NE(NULL, profile); |
229 | 227 |
230 // Check call trees. | 228 // Check call trees. |
231 const i::List<ProfileNode*>* top_down_root_children = | 229 const i::List<ProfileNode*>* top_down_root_children = |
232 profile->top_down()->root()->children(); | 230 profile->top_down()->root()->children(); |
233 CHECK_EQ(1, top_down_root_children->length()); | 231 CHECK_EQ(1, top_down_root_children->length()); |
234 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name()); | 232 CHECK_EQ("bbb", top_down_root_children->last()->entry()->name()); |
235 const i::List<ProfileNode*>* top_down_bbb_children = | 233 const i::List<ProfileNode*>* top_down_bbb_children = |
236 top_down_root_children->last()->children(); | 234 top_down_root_children->last()->children(); |
237 CHECK_EQ(1, top_down_bbb_children->length()); | 235 CHECK_EQ(1, top_down_bbb_children->length()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 i::TickSample* sample = processor.TickSampleEvent(); | 279 i::TickSample* sample = processor.TickSampleEvent(); |
282 sample->pc = code->address(); | 280 sample->pc = code->address(); |
283 sample->tos = 0; | 281 sample->tos = 0; |
284 sample->frames_count = i::TickSample::kMaxFramesCount; | 282 sample->frames_count = i::TickSample::kMaxFramesCount; |
285 for (int i = 0; i < sample->frames_count; ++i) { | 283 for (int i = 0; i < sample->frames_count; ++i) { |
286 sample->stack[i] = code->address(); | 284 sample->stack[i] = code->address(); |
287 } | 285 } |
288 | 286 |
289 processor.Stop(); | 287 processor.Stop(); |
290 processor.Join(); | 288 processor.Join(); |
291 CpuProfile* profile = | 289 CpuProfile* profile = profiles->StopProfiling("", 1); |
292 profiles->StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1); | |
293 CHECK_NE(NULL, profile); | 290 CHECK_NE(NULL, profile); |
294 | 291 |
295 int actual_depth = 0; | 292 int actual_depth = 0; |
296 const ProfileNode* node = profile->top_down()->root(); | 293 const ProfileNode* node = profile->top_down()->root(); |
297 while (node->children()->length() > 0) { | 294 while (node->children()->length() > 0) { |
298 node = node->children()->last(); | 295 node = node->children()->last(); |
299 ++actual_depth; | 296 ++actual_depth; |
300 } | 297 } |
301 | 298 |
302 CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. | 299 CHECK_EQ(1 + i::TickSample::kMaxFramesCount, actual_depth); // +1 for PC. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); | 383 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); |
387 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); | 384 CHECK_EQ(p3, FindCpuProfile(cpu_profiler, uid3)); |
388 const_cast<v8::CpuProfile*>(p3)->Delete(); | 385 const_cast<v8::CpuProfile*>(p3)->Delete(); |
389 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | 386 CHECK_EQ(0, cpu_profiler->GetProfileCount()); |
390 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3)); | 387 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid3)); |
391 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); | 388 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid2)); |
392 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); | 389 CHECK_EQ(NULL, FindCpuProfile(cpu_profiler, uid1)); |
393 } | 390 } |
394 | 391 |
395 | 392 |
396 TEST(DeleteCpuProfileDifferentTokens) { | |
397 LocalContext env; | |
398 v8::HandleScope scope(env->GetIsolate()); | |
399 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | |
400 | |
401 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
402 v8::Local<v8::String> name1 = v8::String::New("1"); | |
403 cpu_profiler->StartCpuProfiling(name1); | |
404 const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1); | |
405 CHECK_NE(NULL, p1); | |
406 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | |
407 unsigned uid1 = p1->GetUid(); | |
408 CHECK_EQ(p1, cpu_profiler->FindCpuProfile(uid1)); | |
409 v8::Local<v8::String> token1 = v8::String::New("token1"); | |
410 const v8::CpuProfile* p1_t1 = cpu_profiler->FindCpuProfile(uid1, token1); | |
411 CHECK_NE(NULL, p1_t1); | |
412 CHECK_NE(p1, p1_t1); | |
413 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | |
414 const_cast<v8::CpuProfile*>(p1)->Delete(); | |
415 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
416 CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1)); | |
417 CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1, token1)); | |
418 const_cast<v8::CpuProfile*>(p1_t1)->Delete(); | |
419 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
420 | |
421 v8::Local<v8::String> name2 = v8::String::New("2"); | |
422 cpu_profiler->StartCpuProfiling(name2); | |
423 v8::Local<v8::String> token2 = v8::String::New("token2"); | |
424 const v8::CpuProfile* p2_t2 = cpu_profiler->StopCpuProfiling(name2, token2); | |
425 CHECK_NE(NULL, p2_t2); | |
426 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | |
427 unsigned uid2 = p2_t2->GetUid(); | |
428 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2)); | |
429 const v8::CpuProfile* p2 = cpu_profiler->FindCpuProfile(uid2); | |
430 CHECK_NE(p2_t2, p2); | |
431 v8::Local<v8::String> name3 = v8::String::New("3"); | |
432 cpu_profiler->StartCpuProfiling(name3); | |
433 const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3); | |
434 CHECK_NE(NULL, p3); | |
435 CHECK_EQ(2, cpu_profiler->GetProfileCount()); | |
436 unsigned uid3 = p3->GetUid(); | |
437 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3)); | |
438 CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3)); | |
439 const_cast<v8::CpuProfile*>(p2_t2)->Delete(); | |
440 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | |
441 CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2)); | |
442 CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3)); | |
443 const_cast<v8::CpuProfile*>(p2)->Delete(); | |
444 CHECK_EQ(1, cpu_profiler->GetProfileCount()); | |
445 CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2)); | |
446 CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3)); | |
447 const_cast<v8::CpuProfile*>(p3)->Delete(); | |
448 CHECK_EQ(0, cpu_profiler->GetProfileCount()); | |
449 CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid3)); | |
450 } | |
451 | |
452 | |
453 TEST(GetProfilerWhenIsolateIsNotInitialized) { | 393 TEST(GetProfilerWhenIsolateIsNotInitialized) { |
454 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 394 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
455 CHECK(i::Isolate::Current()->IsDefaultIsolate()); | 395 CHECK(i::Isolate::Current()->IsDefaultIsolate()); |
456 CHECK(!i::Isolate::Current()->IsInitialized()); | 396 CHECK(!i::Isolate::Current()->IsInitialized()); |
457 CHECK_EQ(NULL, isolate->GetCpuProfiler()); | 397 CHECK_EQ(NULL, isolate->GetCpuProfiler()); |
458 { | 398 { |
459 v8::Isolate::Scope isolateScope(isolate); | 399 v8::Isolate::Scope isolateScope(isolate); |
460 LocalContext env; | 400 LocalContext env; |
461 v8::HandleScope scope(isolate); | 401 v8::HandleScope scope(isolate); |
462 CHECK_NE(NULL, isolate->GetCpuProfiler()); | 402 CHECK_NE(NULL, isolate->GetCpuProfiler()); |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { | 1135 FindChild(startNode, ProfileGenerator::kUnresolvedFunctionName)) { |
1196 ScopedVector<v8::Handle<v8::String> > names(1); | 1136 ScopedVector<v8::Handle<v8::String> > names(1); |
1197 names[0] = v8::String::New("apply"); | 1137 names[0] = v8::String::New("apply"); |
1198 CheckChildrenNames(unresolvedNode, names); | 1138 CheckChildrenNames(unresolvedNode, names); |
1199 GetChild(unresolvedNode, "apply"); | 1139 GetChild(unresolvedNode, "apply"); |
1200 } | 1140 } |
1201 } | 1141 } |
1202 | 1142 |
1203 cpu_profiler->DeleteAllCpuProfiles(); | 1143 cpu_profiler->DeleteAllCpuProfiles(); |
1204 } | 1144 } |
OLD | NEW |