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 #ifdef ENABLE_LOGGING_AND_PROFILING | 5 #ifdef ENABLE_LOGGING_AND_PROFILING |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 #include "profile-generator-inl.h" | 8 #include "profile-generator-inl.h" |
9 #include "cctest.h" | 9 #include "cctest.h" |
10 | 10 |
11 namespace i = v8::internal; | 11 namespace i = v8::internal; |
12 | 12 |
13 using i::CodeEntry; | 13 using i::CodeEntry; |
14 using i::CodeMap; | 14 using i::CodeMap; |
15 using i::CpuProfile; | 15 using i::CpuProfile; |
16 using i::CpuProfilesCollection; | 16 using i::CpuProfilesCollection; |
17 using i::ProfileNode; | 17 using i::ProfileNode; |
18 using i::ProfileTree; | 18 using i::ProfileTree; |
19 using i::ProfileGenerator; | 19 using i::ProfileGenerator; |
| 20 using i::SampleRateCalculator; |
20 using i::TickSample; | 21 using i::TickSample; |
21 using i::Vector; | 22 using i::Vector; |
22 | 23 |
23 | 24 |
24 TEST(ProfileNodeFindOrAddChild) { | 25 TEST(ProfileNodeFindOrAddChild) { |
25 ProfileNode node(NULL); | 26 ProfileNode node(NULL, NULL); |
26 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0); | 27 CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0); |
27 ProfileNode* childNode1 = node.FindOrAddChild(&entry1); | 28 ProfileNode* childNode1 = node.FindOrAddChild(&entry1); |
28 CHECK_NE(NULL, childNode1); | 29 CHECK_NE(NULL, childNode1); |
29 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); | 30 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); |
30 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0); | 31 CodeEntry entry2(i::Logger::FUNCTION_TAG, "", "bbb", "", 0); |
31 ProfileNode* childNode2 = node.FindOrAddChild(&entry2); | 32 ProfileNode* childNode2 = node.FindOrAddChild(&entry2); |
32 CHECK_NE(NULL, childNode2); | 33 CHECK_NE(NULL, childNode2); |
33 CHECK_NE(childNode1, childNode2); | 34 CHECK_NE(childNode1, childNode2); |
34 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); | 35 CHECK_EQ(childNode1, node.FindOrAddChild(&entry1)); |
35 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); | 36 CHECK_EQ(childNode2, node.FindOrAddChild(&entry2)); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 sample2.frames_count = 3; | 418 sample2.frames_count = 3; |
418 generator.RecordTickSample(sample2); | 419 generator.RecordTickSample(sample2); |
419 TickSample sample3; | 420 TickSample sample3; |
420 sample3.pc = ToAddress(0x1510); | 421 sample3.pc = ToAddress(0x1510); |
421 sample3.function = ToAddress(0x1500); | 422 sample3.function = ToAddress(0x1500); |
422 sample3.stack[0] = ToAddress(0x1910); | 423 sample3.stack[0] = ToAddress(0x1910); |
423 sample3.stack[1] = ToAddress(0x1610); | 424 sample3.stack[1] = ToAddress(0x1610); |
424 sample3.frames_count = 2; | 425 sample3.frames_count = 2; |
425 generator.RecordTickSample(sample3); | 426 generator.RecordTickSample(sample3); |
426 | 427 |
427 CpuProfile* profile = profiles.StopProfiling(""); | 428 CpuProfile* profile = profiles.StopProfiling("", 1); |
428 CHECK_NE(NULL, profile); | 429 CHECK_NE(NULL, profile); |
429 ProfileTreeTestHelper top_down_test_helper(profile->top_down()); | 430 ProfileTreeTestHelper top_down_test_helper(profile->top_down()); |
430 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); | 431 CHECK_EQ(NULL, top_down_test_helper.Walk(entry2)); |
431 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); | 432 CHECK_EQ(NULL, top_down_test_helper.Walk(entry3)); |
432 ProfileNode* node1 = top_down_test_helper.Walk(entry1); | 433 ProfileNode* node1 = top_down_test_helper.Walk(entry1); |
433 CHECK_NE(NULL, node1); | 434 CHECK_NE(NULL, node1); |
434 CHECK_EQ(entry1, node1->entry()); | 435 CHECK_EQ(entry1, node1->entry()); |
435 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); | 436 ProfileNode* node2 = top_down_test_helper.Walk(entry1, entry1); |
436 CHECK_NE(NULL, node2); | 437 CHECK_NE(NULL, node2); |
437 CHECK_EQ(entry1, node2->entry()); | 438 CHECK_EQ(entry1, node2->entry()); |
438 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); | 439 ProfileNode* node3 = top_down_test_helper.Walk(entry1, entry2, entry3); |
439 CHECK_NE(NULL, node3); | 440 CHECK_NE(NULL, node3); |
440 CHECK_EQ(entry3, node3->entry()); | 441 CHECK_EQ(entry3, node3->entry()); |
441 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); | 442 ProfileNode* node4 = top_down_test_helper.Walk(entry1, entry3, entry1); |
442 CHECK_NE(NULL, node4); | 443 CHECK_NE(NULL, node4); |
443 CHECK_EQ(entry1, node4->entry()); | 444 CHECK_EQ(entry1, node4->entry()); |
444 } | 445 } |
445 | 446 |
| 447 |
| 448 TEST(SampleRateCalculator) { |
| 449 const double kSamplingIntervalMs = i::Logger::kSamplingIntervalMs; |
| 450 |
| 451 // Verify that ticking exactly in query intervals results in the |
| 452 // initial sampling interval. |
| 453 double time = 0.0; |
| 454 SampleRateCalculator calc1; |
| 455 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
| 456 calc1.UpdateMeasurements(time); |
| 457 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
| 458 time += SampleRateCalculator::kWallTimeQueryIntervalMs; |
| 459 calc1.UpdateMeasurements(time); |
| 460 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
| 461 time += SampleRateCalculator::kWallTimeQueryIntervalMs; |
| 462 calc1.UpdateMeasurements(time); |
| 463 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
| 464 time += SampleRateCalculator::kWallTimeQueryIntervalMs; |
| 465 calc1.UpdateMeasurements(time); |
| 466 CHECK_EQ(kSamplingIntervalMs, calc1.ticks_per_ms()); |
| 467 |
| 468 SampleRateCalculator calc2; |
| 469 time = 0.0; |
| 470 CHECK_EQ(kSamplingIntervalMs, calc2.ticks_per_ms()); |
| 471 calc2.UpdateMeasurements(time); |
| 472 CHECK_EQ(kSamplingIntervalMs, calc2.ticks_per_ms()); |
| 473 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 0.5; |
| 474 calc2.UpdateMeasurements(time); |
| 475 // (1.0 + 2.0) / 2 |
| 476 CHECK_EQ(kSamplingIntervalMs * 1.5, calc2.ticks_per_ms()); |
| 477 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 0.75; |
| 478 calc2.UpdateMeasurements(time); |
| 479 // (1.0 + 2.0 + 2.0) / 3 |
| 480 CHECK_EQ(kSamplingIntervalMs * 1.66666, calc2.ticks_per_ms()); |
| 481 |
| 482 SampleRateCalculator calc3; |
| 483 time = 0.0; |
| 484 CHECK_EQ(kSamplingIntervalMs, calc3.ticks_per_ms()); |
| 485 calc3.UpdateMeasurements(time); |
| 486 CHECK_EQ(kSamplingIntervalMs, calc3.ticks_per_ms()); |
| 487 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 2; |
| 488 calc3.UpdateMeasurements(time); |
| 489 // (1.0 + 0.5) / 2 |
| 490 CHECK_EQ(kSamplingIntervalMs * 0.75, calc3.ticks_per_ms()); |
| 491 time += SampleRateCalculator::kWallTimeQueryIntervalMs * 1.5; |
| 492 calc3.UpdateMeasurements(time); |
| 493 // (1.0 + 0.5 + 0.5) / 3 |
| 494 CHECK_EQ(kSamplingIntervalMs * 0.66666, calc3.ticks_per_ms()); |
| 495 } |
| 496 |
446 #endif // ENABLE_LOGGING_AND_PROFILING | 497 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |