ruby-prof 1.6.3-x64-mingw-ucrt → 1.7.0-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +7 -0
  3. data/ext/ruby_prof/rp_allocation.c +342 -342
  4. data/ext/ruby_prof/rp_call_tree.c +1 -1
  5. data/ext/ruby_prof/rp_call_tree.h +1 -1
  6. data/ext/ruby_prof/rp_call_trees.c +2 -2
  7. data/ext/ruby_prof/rp_call_trees.h +2 -2
  8. data/ext/ruby_prof/rp_measure_allocations.c +1 -1
  9. data/ext/ruby_prof/rp_measure_memory.c +46 -46
  10. data/ext/ruby_prof/rp_measure_process_time.c +1 -1
  11. data/ext/ruby_prof/rp_measure_wall_time.c +1 -1
  12. data/ext/ruby_prof/rp_measurement.c +364 -364
  13. data/ext/ruby_prof/rp_method.c +24 -12
  14. data/ext/ruby_prof/rp_method.h +5 -2
  15. data/ext/ruby_prof/rp_profile.c +2 -2
  16. data/ext/ruby_prof/rp_profile.h +36 -36
  17. data/ext/ruby_prof/rp_stack.c +1 -1
  18. data/ext/ruby_prof/rp_thread.c +1 -1
  19. data/ext/ruby_prof/ruby_prof.c +1 -1
  20. data/ext/ruby_prof/ruby_prof.h +34 -34
  21. data/ext/ruby_prof/vc/ruby_prof.vcxproj +5 -7
  22. data/lib/3.2/ruby_prof.so +0 -0
  23. data/lib/3.3/ruby_prof.so +0 -0
  24. data/lib/ruby-prof/compatibility.rb +10 -10
  25. data/lib/ruby-prof/exclude_common_methods.rb +9 -3
  26. data/lib/ruby-prof/method_info.rb +87 -85
  27. data/lib/ruby-prof/version.rb +1 -1
  28. data/ruby-prof.gemspec +1 -1
  29. data/test/crash2.rb +144 -0
  30. data/test/enumerable_test.rb +5 -5
  31. data/test/exclude_methods_test.rb +197 -86
  32. data/test/line_number_test.rb +254 -99
  33. data/test/measure_allocations_test.rb +422 -1
  34. data/test/measure_memory_test.rb +433 -1
  35. data/test/measure_process_time_test.rb +882 -15
  36. data/test/measure_wall_time_test.rb +195 -47
  37. data/test/method_info_test.rb +1 -1
  38. data/test/recursive_test.rb +198 -1
  39. data/test/thread_test.rb +0 -4
  40. metadata +7 -6
  41. data/lib/3.1/ruby_prof.so +0 -0
@@ -262,14 +262,14 @@ class MeasureProcessTimeTest < TestCase
262
262
  assert_in_delta(0.0, method.children_time, 0.05)
263
263
 
264
264
  method = methods[2]
265
- assert_equal('Kernel#sleep', method.full_name)
265
+ assert_equal('Class#new', method.full_name)
266
266
  assert_in_delta(0.0, method.total_time, 0.05)
267
267
  assert_in_delta(0.0, method.wait_time, 0.05)
268
268
  assert_in_delta(0.0, method.self_time, 0.05)
269
269
  assert_in_delta(0.0, method.children_time, 0.05)
270
270
 
271
271
  method = methods[3]
272
- assert_equal('Class#new', method.full_name)
272
+ assert_equal('Kernel#sleep', method.full_name)
273
273
  assert_in_delta(0.0, method.total_time, 0.05)
274
274
  assert_in_delta(0.0, method.wait_time, 0.05)
275
275
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -314,14 +314,14 @@ class MeasureProcessTimeTest < TestCase
314
314
  assert_in_delta(0.0, method.children_time, 0.05)
315
315
 
316
316
  method = methods[3]
317
- assert_equal('Kernel#sleep', method.full_name)
317
+ assert_equal('Class#new', method.full_name)
318
318
  assert_in_delta(0.0, method.total_time, 0.05)
319
319
  assert_in_delta(0.0, method.wait_time, 0.05)
320
320
  assert_in_delta(0.0, method.self_time, 0.05)
321
321
  assert_in_delta(0.0, method.children_time, 0.05)
322
322
 
323
323
  method = methods[4]
324
- assert_equal('Class#new', method.full_name)
324
+ assert_equal('Kernel#sleep', method.full_name)
325
325
  assert_in_delta(0.0, method.total_time, 0.05)
326
326
  assert_in_delta(0.0, method.wait_time, 0.05)
327
327
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -405,14 +405,14 @@ class MeasureProcessTimeTest < TestCase
405
405
  assert_in_delta(0.0, method.children_time, 0.05)
406
406
 
407
407
  method = methods[2]
408
- assert_equal('Kernel#sleep', method.full_name)
408
+ assert_equal('Class#new', method.full_name)
409
409
  assert_in_delta(0.0, method.total_time, 0.05)
410
410
  assert_in_delta(0.0, method.wait_time, 0.05)
411
411
  assert_in_delta(0.0, method.self_time, 0.05)
412
412
  assert_in_delta(0.0, method.children_time, 0.05)
413
413
 
414
414
  method = methods[3]
415
- assert_equal('Class#new', method.full_name)
415
+ assert_equal('Kernel#sleep', method.full_name)
416
416
  assert_in_delta(0.0, method.total_time, 0.05)
417
417
  assert_in_delta(0.0, method.wait_time, 0.05)
418
418
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -712,14 +712,14 @@ class MeasureProcessTimeTest < TestCase
712
712
  assert_in_delta(0.0, method.children_time, 0.05)
713
713
 
714
714
  method = methods[2]
715
- assert_equal('Kernel#sleep', method.full_name)
715
+ assert_equal('Class#new', method.full_name)
716
716
  assert_in_delta(0.0, method.total_time, 0.05)
717
717
  assert_in_delta(0.0, method.wait_time, 0.05)
718
718
  assert_in_delta(0.0, method.self_time, 0.05)
719
719
  assert_in_delta(0.0, method.children_time, 0.05)
720
720
 
721
721
  method = methods[3]
722
- assert_equal('Class#new', method.full_name)
722
+ assert_equal('Kernel#sleep', method.full_name)
723
723
  assert_in_delta(0.0, method.total_time, 0.05)
724
724
  assert_in_delta(0.0, method.wait_time, 0.05)
725
725
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -780,7 +780,7 @@ class MeasureProcessTimeTest < TestCase
780
780
  assert_in_delta(0.0, method.self_time, 0.05)
781
781
  assert_in_delta(0.0, method.children_time, 0.05)
782
782
  end
783
- else # Ruby 3.1 and higher
783
+ elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.3')
784
784
  def test_class_methods_sleep
785
785
  result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
786
786
  RubyProf::C1.sleep_wait
@@ -1031,14 +1031,14 @@ class MeasureProcessTimeTest < TestCase
1031
1031
  assert_in_delta(0.0, method.children_time, 0.05)
1032
1032
 
1033
1033
  method = methods[2]
1034
- assert_equal('Kernel#sleep', method.full_name)
1034
+ assert_equal('Class#new', method.full_name)
1035
1035
  assert_in_delta(0.0, method.total_time, 0.05)
1036
1036
  assert_in_delta(0.0, method.wait_time, 0.05)
1037
1037
  assert_in_delta(0.0, method.self_time, 0.05)
1038
1038
  assert_in_delta(0.0, method.children_time, 0.05)
1039
1039
 
1040
1040
  method = methods[3]
1041
- assert_equal('Class#new', method.full_name)
1041
+ assert_equal('Kernel#sleep', method.full_name)
1042
1042
  assert_in_delta(0.0, method.total_time, 0.05)
1043
1043
  assert_in_delta(0.0, method.wait_time, 0.05)
1044
1044
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -1083,14 +1083,14 @@ class MeasureProcessTimeTest < TestCase
1083
1083
  assert_in_delta(0.0, method.children_time, 0.05)
1084
1084
 
1085
1085
  method = methods[3]
1086
- assert_equal('Kernel#sleep', method.full_name)
1086
+ assert_equal('Class#new', method.full_name)
1087
1087
  assert_in_delta(0.0, method.total_time, 0.05)
1088
1088
  assert_in_delta(0.0, method.wait_time, 0.05)
1089
1089
  assert_in_delta(0.0, method.self_time, 0.05)
1090
1090
  assert_in_delta(0.0, method.children_time, 0.05)
1091
1091
 
1092
1092
  method = methods[4]
1093
- assert_equal('Class#new', method.full_name)
1093
+ assert_equal('Kernel#sleep', method.full_name)
1094
1094
  assert_in_delta(0.0, method.total_time, 0.05)
1095
1095
  assert_in_delta(0.0, method.wait_time, 0.05)
1096
1096
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -1174,14 +1174,14 @@ class MeasureProcessTimeTest < TestCase
1174
1174
  assert_in_delta(0.0, method.children_time, 0.05)
1175
1175
 
1176
1176
  method = methods[2]
1177
- assert_equal('Kernel#sleep', method.full_name)
1177
+ assert_equal('Class#new', method.full_name)
1178
1178
  assert_in_delta(0.0, method.total_time, 0.05)
1179
1179
  assert_in_delta(0.0, method.wait_time, 0.05)
1180
1180
  assert_in_delta(0.0, method.self_time, 0.05)
1181
1181
  assert_in_delta(0.0, method.children_time, 0.05)
1182
1182
 
1183
1183
  method = methods[3]
1184
- assert_equal('Class#new', method.full_name)
1184
+ assert_equal('Kernel#sleep', method.full_name)
1185
1185
  assert_in_delta(0.0, method.total_time, 0.05)
1186
1186
  assert_in_delta(0.0, method.wait_time, 0.05)
1187
1187
  assert_in_delta(0.0, method.self_time, 0.05)
@@ -1523,19 +1523,886 @@ class MeasureProcessTimeTest < TestCase
1523
1523
  assert_in_delta(0.0, method.children_time, 0.05)
1524
1524
 
1525
1525
  method = methods[2]
1526
+ assert_equal('Class#new', method.full_name)
1527
+ assert_in_delta(0.0, method.total_time, 0.05)
1528
+ assert_in_delta(0.0, method.wait_time, 0.05)
1529
+ assert_in_delta(0.0, method.self_time, 0.05)
1530
+ assert_in_delta(0.0, method.children_time, 0.05)
1531
+
1532
+ method = methods[3]
1526
1533
  assert_equal('Kernel#sleep', method.full_name)
1527
1534
  assert_in_delta(0.0, method.total_time, 0.05)
1528
1535
  assert_in_delta(0.0, method.wait_time, 0.05)
1529
1536
  assert_in_delta(0.0, method.self_time, 0.05)
1530
1537
  assert_in_delta(0.0, method.children_time, 0.05)
1531
1538
 
1539
+ method = methods[4]
1540
+ assert_equal('BasicObject#initialize', method.full_name)
1541
+ assert_in_delta(0.0, method.total_time, 0.05)
1542
+ assert_in_delta(0.0, method.wait_time, 0.05)
1543
+ assert_in_delta(0.0, method.self_time, 0.05)
1544
+ assert_in_delta(0.0, method.children_time, 0.05)
1545
+ end
1546
+
1547
+ def test_module_instance_methods_busy
1548
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1549
+ RubyProf::C2.new.busy_wait
1550
+ end
1551
+
1552
+ thread = result.threads.first
1553
+ assert_in_delta(0.3, thread.total_time, 0.05)
1554
+
1555
+ methods = result.threads.first.methods.sort.reverse
1556
+ assert_equal(7, methods.length)
1557
+
1558
+ # Check times
1559
+ method = methods[0]
1560
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
1561
+ assert_in_delta(0.3, method.total_time, 0.05)
1562
+ assert_in_delta(0.0, method.wait_time, 0.05)
1563
+ assert_in_delta(0.0, method.self_time, 0.05)
1564
+ assert_in_delta(0.3, method.children_time, 0.05)
1565
+
1566
+ method = methods[1]
1567
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
1568
+ assert_in_delta(0.3, method.total_time, 0.05)
1569
+ assert_in_delta(0.0, method.wait_time, 0.05)
1570
+ assert_in_delta(0.15, method.self_time, 0.05)
1571
+ assert_in_delta(0.15, method.children_time, 0.05)
1572
+
1573
+ method = methods[2]
1574
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1575
+ assert_in_delta(0.05, method.total_time, 0.05)
1576
+ assert_in_delta(0.0, method.wait_time, 0.05)
1577
+ assert_in_delta(0.05, method.self_time, 0.05)
1578
+ assert_in_delta(0.0, method.children_time, 0.05)
1579
+
1532
1580
  method = methods[3]
1581
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1582
+ assert_in_delta(0.0, method.total_time, 0.05)
1583
+ assert_in_delta(0.0, method.wait_time, 0.05)
1584
+ assert_in_delta(0.0, method.self_time, 0.05)
1585
+ assert_in_delta(0.0, method.children_time, 0.05)
1586
+
1587
+ method = methods[4]
1588
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
1589
+ assert_in_delta(0.0, method.total_time, 0.05)
1590
+ assert_in_delta(0.0, method.wait_time, 0.05)
1591
+ assert_in_delta(0.0, method.self_time, 0.05)
1592
+ assert_in_delta(0.0, method.children_time, 0.05)
1593
+
1594
+ method = methods[5]
1533
1595
  assert_equal('Class#new', method.full_name)
1534
1596
  assert_in_delta(0.0, method.total_time, 0.05)
1535
1597
  assert_in_delta(0.0, method.wait_time, 0.05)
1536
1598
  assert_in_delta(0.0, method.self_time, 0.05)
1537
1599
  assert_in_delta(0.0, method.children_time, 0.05)
1538
1600
 
1601
+ method = methods[6]
1602
+ assert_equal('BasicObject#initialize', method.full_name)
1603
+ assert_in_delta(0.0, method.total_time, 0.05)
1604
+ assert_in_delta(0.0, method.wait_time, 0.05)
1605
+ assert_in_delta(0.0, method.self_time, 0.05)
1606
+ assert_in_delta(0.0, method.children_time, 0.05)
1607
+ end
1608
+ else
1609
+ def test_class_methods_sleep
1610
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1611
+ RubyProf::C1.sleep_wait
1612
+ end
1613
+
1614
+ thread = result.threads.first
1615
+ assert_in_delta(0.0, thread.total_time, 0.05)
1616
+
1617
+ methods = result.threads.first.methods.sort.reverse
1618
+ assert_equal(3, methods.length)
1619
+
1620
+ # Check times
1621
+ method = methods[0]
1622
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
1623
+ assert_in_delta(0.0, method.total_time, 0.05)
1624
+ assert_in_delta(0.0, method.wait_time, 0.05)
1625
+ assert_in_delta(0.0, method.self_time, 0.05)
1626
+ assert_in_delta(0.0, method.children_time, 0.05)
1627
+
1628
+ method = methods[1]
1629
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
1630
+ assert_in_delta(0.0, method.total_time, 0.05)
1631
+ assert_in_delta(0.0, method.wait_time, 0.05)
1632
+ assert_in_delta(0.0, method.self_time, 0.05)
1633
+ assert_in_delta(0.0, method.children_time, 0.05)
1634
+
1635
+ method = methods[2]
1636
+ assert_equal('Kernel#sleep', method.full_name)
1637
+ assert_in_delta(0.0, method.total_time, 0.05)
1638
+ assert_in_delta(0.0, method.wait_time, 0.05)
1639
+ assert_in_delta(0.0, method.self_time, 0.05)
1640
+ assert_in_delta(0.0, method.children_time, 0.05)
1641
+ end
1642
+
1643
+ def test_class_methods_sleep_threaded
1644
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1645
+ background_thread = Thread.new do
1646
+ RubyProf::C1.sleep_wait
1647
+ end
1648
+ background_thread.join
1649
+ end
1650
+
1651
+ assert_equal(2, result.threads.count)
1652
+
1653
+ thread = result.threads.first
1654
+ assert_in_delta(0.0, thread.total_time, 0.05)
1655
+
1656
+ methods = result.threads.first.methods.sort.reverse
1657
+ assert_equal(4, methods.length)
1658
+
1659
+ # Check times
1660
+ method = methods[0]
1661
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
1662
+ assert_in_delta(0.0, method.total_time, 0.05)
1663
+ assert_in_delta(0.0, method.wait_time, 0.05)
1664
+ assert_in_delta(0.0, method.self_time, 0.05)
1665
+ assert_in_delta(0.0, method.children_time, 0.05)
1666
+
1667
+ method = methods[1]
1668
+ assert_equal('Thread#join', method.full_name)
1669
+ assert_in_delta(0.0, method.total_time, 0.05)
1670
+ assert_in_delta(0.0, method.wait_time, 0.05)
1671
+ assert_in_delta(0.0, method.self_time, 0.05)
1672
+ assert_in_delta(0.0, method.children_time, 0.05)
1673
+
1674
+ method = methods[2]
1675
+ assert_equal('<Class::Thread>#new', method.full_name)
1676
+ assert_in_delta(0.0, method.total_time, 0.05)
1677
+ assert_in_delta(0.0, method.wait_time, 0.05)
1678
+ assert_in_delta(0.0, method.self_time, 0.05)
1679
+ assert_in_delta(0.0, method.children_time, 0.05)
1680
+
1681
+ method = methods[3]
1682
+ assert_equal('Thread#initialize', method.full_name)
1683
+ assert_in_delta(0.0, method.total_time, 0.05)
1684
+ assert_in_delta(0.0, method.wait_time, 0.05)
1685
+ assert_in_delta(0.0, method.self_time, 0.05)
1686
+ assert_in_delta(0.0, method.children_time, 0.05)
1687
+
1688
+ thread = result.threads.last
1689
+ assert_in_delta(0.0, thread.total_time, 0.05)
1690
+
1691
+ methods = result.threads.first.methods.sort.reverse
1692
+ assert_equal(4, methods.length)
1693
+
1694
+ methods = result.threads.last.methods.sort.reverse
1695
+ assert_equal(3, methods.length)
1696
+
1697
+ # Check times
1698
+ method = methods[0]
1699
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
1700
+ assert_in_delta(0.0, method.total_time, 0.05)
1701
+ assert_in_delta(0.0, method.wait_time, 0.05)
1702
+ assert_in_delta(0.0, method.self_time, 0.05)
1703
+ assert_in_delta(0.0, method.children_time, 0.05)
1704
+
1705
+ method = methods[1]
1706
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
1707
+ assert_in_delta(0.0, method.total_time, 0.05)
1708
+ assert_in_delta(0.0, method.wait_time, 0.05)
1709
+ assert_in_delta(0.0, method.self_time, 0.05)
1710
+ assert_in_delta(0.0, method.children_time, 0.05)
1711
+
1712
+ method = methods[2]
1713
+ assert_equal('Kernel#sleep', method.full_name)
1714
+ assert_in_delta(0.0, method.total_time, 0.05)
1715
+ assert_in_delta(0.0, method.wait_time, 0.05)
1716
+ assert_in_delta(0.0, method.self_time, 0.05)
1717
+ assert_in_delta(0.0, method.children_time, 0.05)
1718
+ end
1719
+
1720
+ def test_class_methods_busy
1721
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1722
+ RubyProf::C1.busy_wait
1723
+ end
1724
+
1725
+ thread = result.threads.first
1726
+ assert_in_delta(0.08, thread.total_time, 0.05)
1727
+
1728
+ methods = result.threads.first.methods.sort.reverse
1729
+ assert_equal(5, methods.length)
1730
+
1731
+ # Check times
1732
+ method = methods[0]
1733
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
1734
+ assert_in_delta(0.1, method.total_time, 0.05)
1735
+ assert_in_delta(0.0, method.wait_time, 0.05)
1736
+ assert_in_delta(0.0, method.self_time, 0.05)
1737
+ assert_in_delta(0.1, method.children_time, 0.05)
1738
+
1739
+ method = methods[1]
1740
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
1741
+ assert_in_delta(0.1, method.total_time, 0.05)
1742
+ assert_in_delta(0.0, method.wait_time, 0.05)
1743
+ assert_in_delta(0.06, method.self_time, 0.05)
1744
+ assert_in_delta(0.07, method.children_time, 0.05)
1745
+
1746
+ method = methods[2]
1747
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
1748
+ assert_in_delta(0.05, method.total_time, 0.05)
1749
+ assert_in_delta(0.0, method.wait_time, 0.05)
1750
+ assert_in_delta(0.05, method.self_time, 0.05)
1751
+ assert_in_delta(0.0, method.children_time, 0.05)
1752
+ end
1753
+
1754
+ def test_class_methods_busy_threaded
1755
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1756
+ background_thread = Thread.new do
1757
+ RubyProf::C1.busy_wait
1758
+ end
1759
+ background_thread.join
1760
+ end
1761
+
1762
+ assert_equal(2, result.threads.count)
1763
+
1764
+ thread = result.threads.first
1765
+ assert_in_delta(0.1, thread.total_time, 0.05)
1766
+
1767
+ methods = result.threads.first.methods.sort.reverse
1768
+ assert_equal(4, methods.length)
1769
+
1770
+ # Check times
1771
+ method = methods[0]
1772
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
1773
+ assert_in_delta(0.1, method.total_time, 0.05)
1774
+ assert_in_delta(0.0, method.wait_time, 0.05)
1775
+ assert_in_delta(0.0, method.self_time, 0.05)
1776
+ assert_in_delta(0.1, method.children_time, 0.05)
1777
+
1778
+ method = methods[1]
1779
+ assert_equal('Thread#join', method.full_name)
1780
+ assert_in_delta(0.1, method.total_time, 0.05)
1781
+ assert_in_delta(0.1, method.wait_time, 0.05)
1782
+ assert_in_delta(0.0, method.self_time, 0.05)
1783
+ assert_in_delta(0.0, method.children_time, 0.05)
1784
+
1785
+ method = methods[2]
1786
+ assert_equal('<Class::Thread>#new', method.full_name)
1787
+ assert_in_delta(0.0, method.total_time, 0.05)
1788
+ assert_in_delta(0.0, method.wait_time, 0.05)
1789
+ assert_in_delta(0.0, method.self_time, 0.05)
1790
+ assert_in_delta(0.0, method.children_time, 0.05)
1791
+
1792
+ method = methods[3]
1793
+ assert_equal('Thread#initialize', method.full_name)
1794
+ assert_in_delta(0.0, method.total_time, 0.05)
1795
+ assert_in_delta(0.0, method.wait_time, 0.05)
1796
+ assert_in_delta(0.0, method.self_time, 0.05)
1797
+ assert_in_delta(0.0, method.children_time, 0.05)
1798
+
1799
+ thread = result.threads.last
1800
+ assert_in_delta(0.1, thread.total_time, 0.05)
1801
+
1802
+ methods = result.threads.first.methods.sort.reverse
1803
+ assert_equal(4, methods.length)
1804
+
1805
+ methods = result.threads.last.methods.sort.reverse
1806
+ assert_equal(5, methods.length)
1807
+
1808
+ # Check times
1809
+ method = methods[0]
1810
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
1811
+ assert_in_delta(0.1, method.total_time, 0.05)
1812
+ assert_in_delta(0.0, method.wait_time, 0.05)
1813
+ assert_in_delta(0.0, method.self_time, 0.05)
1814
+ assert_in_delta(0.1, method.children_time, 0.05)
1815
+
1816
+ method = methods[1]
1817
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
1818
+ assert_in_delta(0.1, method.total_time, 0.05)
1819
+ assert_in_delta(0.0, method.wait_time, 0.05)
1820
+ assert_in_delta(0.05, method.self_time, 0.05)
1821
+ assert_in_delta(0.05, method.children_time, 0.05)
1822
+
1823
+ method = methods[2]
1824
+ assert('<Module::Process>#clock_gettime' == method.full_name ||
1825
+ 'Float#<' == method.full_name)
1826
+ assert_in_delta(0.05, method.total_time, 0.05)
1827
+ assert_in_delta(0.0, method.wait_time, 0.05)
1828
+ assert_in_delta(0.05, method.self_time, 0.05)
1829
+ assert_in_delta(0.0, method.children_time, 0.05)
1830
+ end
1831
+
1832
+ def test_instance_methods_sleep
1833
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1834
+ RubyProf::C1.new.sleep_wait
1835
+ end
1836
+
1837
+ thread = result.threads.first
1838
+ assert_in_delta(0.0, thread.total_time, 0.05)
1839
+
1840
+ methods = result.threads.first.methods.sort.reverse
1841
+ assert_equal(5, methods.length)
1842
+
1843
+ # Check times
1844
+ method = methods[0]
1845
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
1846
+ assert_in_delta(0.0, method.total_time, 0.05)
1847
+ assert_in_delta(0.0, method.wait_time, 0.05)
1848
+ assert_in_delta(0.0, method.self_time, 0.05)
1849
+ assert_in_delta(0.0, method.children_time, 0.05)
1850
+
1851
+ method = methods[1]
1852
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1853
+ assert_in_delta(0.0, method.total_time, 0.05)
1854
+ assert_in_delta(0.0, method.wait_time, 0.05)
1855
+ assert_in_delta(0.0, method.self_time, 0.05)
1856
+ assert_in_delta(0.0, method.children_time, 0.05)
1857
+
1858
+ method = methods[2]
1859
+ assert_equal('Class#new', method.full_name)
1860
+ assert_in_delta(0.0, method.total_time, 0.05)
1861
+ assert_in_delta(0.0, method.wait_time, 0.05)
1862
+ assert_in_delta(0.0, method.self_time, 0.05)
1863
+ assert_in_delta(0.0, method.children_time, 0.05)
1864
+
1865
+ method = methods[3]
1866
+ assert_equal('Kernel#sleep', method.full_name)
1867
+ assert_in_delta(0.0, method.total_time, 0.05)
1868
+ assert_in_delta(0.0, method.wait_time, 0.05)
1869
+ assert_in_delta(0.0, method.self_time, 0.05)
1870
+ assert_in_delta(0.0, method.children_time, 0.05)
1871
+
1872
+ method = methods[4]
1873
+ assert_equal('BasicObject#initialize', method.full_name)
1874
+ assert_in_delta(0.0, method.total_time, 0.05)
1875
+ assert_in_delta(0.0, method.wait_time, 0.05)
1876
+ assert_in_delta(0.0, method.self_time, 0.05)
1877
+ assert_in_delta(0.0, method.children_time, 0.05)
1878
+ end
1879
+
1880
+ def test_instance_methods_sleep_block
1881
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1882
+ 1.times { RubyProf::C1.new.sleep_wait }
1883
+ end
1884
+
1885
+ methods = result.threads.first.methods.sort.reverse
1886
+ assert_equal(9, methods.length)
1887
+
1888
+ # Check times
1889
+ method = methods[0]
1890
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
1891
+ assert_in_delta(0.0, method.total_time, 0.05)
1892
+ assert_in_delta(0.0, method.wait_time, 0.05)
1893
+ assert_in_delta(0.0, method.self_time, 0.05)
1894
+ assert_in_delta(0.0, method.children_time, 0.05)
1895
+
1896
+ method = methods[1]
1897
+ assert_equal('Integer#times', method.full_name)
1898
+ assert_in_delta(0.0, method.total_time, 0.05)
1899
+ assert_in_delta(0.0, method.wait_time, 0.05)
1900
+ assert_in_delta(0.0, method.self_time, 0.05)
1901
+ assert_in_delta(0.0, method.children_time, 0.05)
1902
+
1903
+ method = methods[2]
1904
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
1905
+ assert_in_delta(0.0, method.total_time, 0.05)
1906
+ assert_in_delta(0.0, method.wait_time, 0.05)
1907
+ assert_in_delta(0.0, method.self_time, 0.05)
1908
+ assert_in_delta(0.0, method.children_time, 0.05)
1909
+
1910
+ method = methods[3]
1911
+ assert_equal('Kernel#block_given?', method.full_name)
1912
+ assert_in_delta(0.0, method.total_time, 0.05)
1913
+ assert_in_delta(0.0, method.wait_time, 0.05)
1914
+ assert_in_delta(0.0, method.self_time, 0.05)
1915
+ assert_in_delta(0.0, method.children_time, 0.05)
1916
+
1917
+ method = methods[4]
1918
+ assert_equal('Integer#succ', method.full_name)
1919
+ assert_in_delta(0.0, method.total_time, 0.05)
1920
+ assert_in_delta(0.0, method.wait_time, 0.05)
1921
+ assert_in_delta(0.0, method.self_time, 0.05)
1922
+ assert_in_delta(0.0, method.children_time, 0.05)
1923
+
1924
+ method = methods[5]
1925
+ assert_equal('Integer#<', method.full_name)
1926
+ assert_in_delta(0.0, method.total_time, 0.05)
1927
+ assert_in_delta(0.0, method.wait_time, 0.05)
1928
+ assert_in_delta(0.0, method.self_time, 0.05)
1929
+ assert_in_delta(0.0, method.children_time, 0.05)
1930
+
1931
+ method = methods[6]
1932
+ assert_equal('Class#new', method.full_name)
1933
+ assert_in_delta(0.0, method.total_time, 0.05)
1934
+ assert_in_delta(0.0, method.wait_time, 0.05)
1935
+ assert_in_delta(0.0, method.self_time, 0.05)
1936
+ assert_in_delta(0.0, method.children_time, 0.05)
1937
+
1938
+ method = methods[7]
1939
+ assert_equal('Kernel#sleep', method.full_name)
1940
+ assert_in_delta(0.0, method.total_time, 0.05)
1941
+ assert_in_delta(0.0, method.wait_time, 0.05)
1942
+ assert_in_delta(0.0, method.self_time, 0.05)
1943
+ assert_in_delta(0.0, method.children_time, 0.05)
1944
+
1945
+ method = methods[8]
1946
+ assert_equal('BasicObject#initialize', method.full_name)
1947
+ assert_in_delta(0.0, method.total_time, 0.05)
1948
+ assert_in_delta(0.0, method.wait_time, 0.05)
1949
+ assert_in_delta(0.0, method.self_time, 0.05)
1950
+ assert_in_delta(0.0, method.children_time, 0.05)
1951
+ end
1952
+
1953
+ def test_instance_methods_sleep_threaded
1954
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
1955
+ background_thread = Thread.new do
1956
+ RubyProf::C1.new.sleep_wait
1957
+ end
1958
+ background_thread.join
1959
+ end
1960
+
1961
+ assert_equal(2, result.threads.count)
1962
+
1963
+ thread = result.threads.first
1964
+ assert_in_delta(0.0, thread.total_time, 0.05)
1965
+
1966
+ methods = result.threads.first.methods.sort.reverse
1967
+ assert_equal(4, methods.length)
1968
+
1969
+ # Check times
1970
+ method = methods[0]
1971
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
1972
+ assert_in_delta(0.0, method.total_time, 0.05)
1973
+ assert_in_delta(0.0, method.wait_time, 0.05)
1974
+ assert_in_delta(0.0, method.self_time, 0.05)
1975
+ assert_in_delta(0.0, method.children_time, 0.05)
1976
+
1977
+ method = methods[1]
1978
+ assert_equal('Thread#join', method.full_name)
1979
+ assert_in_delta(0.0, method.total_time, 0.05)
1980
+ assert_in_delta(0.0, method.wait_time, 0.05)
1981
+ assert_in_delta(0.0, method.self_time, 0.05)
1982
+ assert_in_delta(0.0, method.children_time, 0.05)
1983
+
1984
+ method = methods[2]
1985
+ assert_equal('<Class::Thread>#new', method.full_name)
1986
+ assert_in_delta(0.0, method.total_time, 0.05)
1987
+ assert_in_delta(0.0, method.wait_time, 0.05)
1988
+ assert_in_delta(0.0, method.self_time, 0.05)
1989
+ assert_in_delta(0.0, method.children_time, 0.05)
1990
+
1991
+ method = methods[3]
1992
+ assert_equal('Thread#initialize', method.full_name)
1993
+ assert_in_delta(0.0, method.total_time, 0.05)
1994
+ assert_in_delta(0.0, method.wait_time, 0.05)
1995
+ assert_in_delta(0.0, method.self_time, 0.05)
1996
+ assert_in_delta(0.0, method.children_time, 0.05)
1997
+
1998
+ thread = result.threads.last
1999
+ assert_in_delta(0.0, thread.total_time, 0.05)
2000
+
2001
+ methods = result.threads.first.methods.sort.reverse
2002
+ assert_equal(4, methods.length)
2003
+
2004
+ methods = result.threads.last.methods.sort.reverse
2005
+ assert_equal(5, methods.length)
2006
+
2007
+ # Check times
2008
+ method = methods[0]
2009
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
2010
+ assert_in_delta(0.0, method.total_time, 0.05)
2011
+ assert_in_delta(0.0, method.wait_time, 0.05)
2012
+ assert_in_delta(0.0, method.self_time, 0.05)
2013
+ assert_in_delta(0.0, method.children_time, 0.05)
2014
+
2015
+ method = methods[1]
2016
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
2017
+ assert_in_delta(0.0, method.total_time, 0.05)
2018
+ assert_in_delta(0.0, method.wait_time, 0.05)
2019
+ assert_in_delta(0.0, method.self_time, 0.05)
2020
+ assert_in_delta(0.0, method.children_time, 0.05)
2021
+
2022
+ method = methods[2]
2023
+ assert_equal('Class#new', method.full_name)
2024
+ assert_in_delta(0.0, method.total_time, 0.05)
2025
+ assert_in_delta(0.0, method.wait_time, 0.05)
2026
+ assert_in_delta(0.0, method.self_time, 0.05)
2027
+ assert_in_delta(0.0, method.children_time, 0.05)
2028
+
2029
+ method = methods[3]
2030
+ assert_equal('Kernel#sleep', method.full_name)
2031
+ assert_in_delta(0.0, method.total_time, 0.05)
2032
+ assert_in_delta(0.0, method.wait_time, 0.05)
2033
+ assert_in_delta(0.0, method.self_time, 0.05)
2034
+ assert_in_delta(0.0, method.children_time, 0.05)
2035
+
2036
+ method = methods[4]
2037
+ assert_equal('BasicObject#initialize', method.full_name)
2038
+ assert_in_delta(0.0, method.total_time, 0.05)
2039
+ assert_in_delta(0.0, method.wait_time, 0.05)
2040
+ assert_in_delta(0.0, method.self_time, 0.05)
2041
+ assert_in_delta(0.0, method.children_time, 0.05)
2042
+ end
2043
+
2044
+ def test_instance_methods_busy
2045
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2046
+ RubyProf::C1.new.busy_wait
2047
+ end
2048
+
2049
+ thread = result.threads.first
2050
+ assert_in_delta(0.2, thread.total_time, 0.05)
2051
+
2052
+ methods = result.threads.first.methods.sort.reverse
2053
+ assert_equal(7, methods.length)
2054
+
2055
+ # Check times
2056
+ method = methods[0]
2057
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
2058
+ assert_in_delta(0.2, method.total_time, 0.05)
2059
+ assert_in_delta(0.0, method.wait_time, 0.05)
2060
+ assert_in_delta(0.0, method.self_time, 0.05)
2061
+ assert_in_delta(0.2, method.children_time, 0.05)
2062
+
2063
+ method = methods[1]
2064
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2065
+ assert_in_delta(0.2, method.total_time, 0.05)
2066
+ assert_in_delta(0.0, method.wait_time, 0.05)
2067
+ assert_in_delta(0.09, method.self_time, 0.05)
2068
+ assert_in_delta(0.11, method.children_time, 0.05)
2069
+
2070
+ method = methods[2]
2071
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2072
+ assert_in_delta(0.033, method.total_time, 0.05)
2073
+ assert_in_delta(0.0, method.wait_time, 0.05)
2074
+ assert_in_delta(0.033, method.self_time, 0.05)
2075
+ assert_in_delta(0.0, method.children_time, 0.05)
2076
+
2077
+ method = methods[3]
2078
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2079
+ assert_in_delta(0.0, method.total_time, 0.05)
2080
+ assert_in_delta(0.0, method.wait_time, 0.05)
2081
+ assert_in_delta(0.0, method.self_time, 0.05)
2082
+ assert_in_delta(0.0, method.children_time, 0.05)
2083
+
2084
+ method = methods[4]
2085
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2086
+ assert_in_delta(0.0, method.total_time, 0.05)
2087
+ assert_in_delta(0.0, method.wait_time, 0.05)
2088
+ assert_in_delta(0.0, method.self_time, 0.05)
2089
+ assert_in_delta(0.0, method.children_time, 0.05)
2090
+
2091
+ method = methods[5]
2092
+ assert_equal('Class#new', method.full_name)
2093
+ assert_in_delta(0.0, method.total_time, 0.05)
2094
+ assert_in_delta(0.0, method.wait_time, 0.05)
2095
+ assert_in_delta(0.0, method.self_time, 0.05)
2096
+ assert_in_delta(0.0, method.children_time, 0.05)
2097
+
2098
+ method = methods[6]
2099
+ assert_equal('BasicObject#initialize', method.full_name)
2100
+ assert_in_delta(0.0, method.total_time, 0.05)
2101
+ assert_in_delta(0.0, method.wait_time, 0.05)
2102
+ assert_in_delta(0.0, method.self_time, 0.05)
2103
+ assert_in_delta(0.0, method.children_time, 0.05)
2104
+ end
2105
+
2106
+ def test_instance_methods_busy_block
2107
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2108
+ 1.times { RubyProf::C1.new.busy_wait }
2109
+ end
2110
+
2111
+ methods = result.threads.first.methods.sort.reverse
2112
+ assert_equal(11, methods.length)
2113
+
2114
+ # Check times
2115
+ method = methods[0]
2116
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
2117
+ assert_in_delta(0.2, method.total_time, 0.05)
2118
+ assert_in_delta(0.0, method.wait_time, 0.05)
2119
+ assert_in_delta(0.0, method.self_time, 0.05)
2120
+ assert_in_delta(0.2, method.children_time, 0.05)
2121
+
2122
+ method = methods[1]
2123
+ assert_equal('Integer#times', method.full_name)
2124
+ assert_in_delta(0.2, method.total_time, 0.05)
2125
+ assert_in_delta(0.0, method.wait_time, 0.05)
2126
+ assert_in_delta(0.0, method.self_time, 0.05)
2127
+ assert_in_delta(0.2, method.children_time, 0.05)
2128
+
2129
+ method = methods[2]
2130
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2131
+ assert_in_delta(0.2, method.total_time, 0.05)
2132
+ assert_in_delta(0.0, method.wait_time, 0.05)
2133
+ assert_in_delta(0.09, method.self_time, 0.05)
2134
+ assert_in_delta(0.11, method.children_time, 0.05)
2135
+
2136
+ method = methods[3]
2137
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2138
+ assert_in_delta(0.033, method.total_time, 0.05)
2139
+ assert_in_delta(0.0, method.wait_time, 0.05)
2140
+ assert_in_delta(0.033, method.self_time, 0.05)
2141
+ assert_in_delta(0.0, method.children_time, 0.05)
2142
+
2143
+ method = methods[4]
2144
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2145
+ assert_in_delta(0.03, method.total_time, 0.03)
2146
+ assert_in_delta(0.03, method.wait_time, 0.03)
2147
+ assert_in_delta(0.03, method.self_time, 0.03)
2148
+ assert_in_delta(0.03, method.children_time, 0.03)
2149
+
2150
+ method = methods[5]
2151
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2152
+ assert_in_delta(0.03, method.total_time, 0.03)
2153
+ assert_in_delta(0.03, method.wait_time, 0.03)
2154
+ assert_in_delta(0.03, method.self_time, 0.03)
2155
+ assert_in_delta(0.03, method.children_time, 0.03)
2156
+
2157
+ method = methods[6]
2158
+ assert_equal('Kernel#block_given?', method.full_name)
2159
+ assert_in_delta(0.0, method.total_time, 0.05)
2160
+ assert_in_delta(0.0, method.wait_time, 0.05)
2161
+ assert_in_delta(0.0, method.self_time, 0.05)
2162
+ assert_in_delta(0.0, method.children_time, 0.05)
2163
+
2164
+ method = methods[7]
2165
+ assert_equal('Integer#succ', method.full_name)
2166
+ assert_in_delta(0.0, method.total_time, 0.05)
2167
+ assert_in_delta(0.0, method.wait_time, 0.05)
2168
+ assert_in_delta(0.0, method.self_time, 0.05)
2169
+ assert_in_delta(0.0, method.children_time, 0.05)
2170
+
2171
+ method = methods[8]
2172
+ assert_equal('Integer#<', method.full_name)
2173
+ assert_in_delta(0.0, method.total_time, 0.05)
2174
+ assert_in_delta(0.0, method.wait_time, 0.05)
2175
+ assert_in_delta(0.0, method.self_time, 0.05)
2176
+ assert_in_delta(0.0, method.children_time, 0.05)
2177
+
2178
+ method = methods[9]
2179
+ assert_equal('Class#new', method.full_name)
2180
+ assert_in_delta(0.0, method.total_time, 0.01)
2181
+ assert_in_delta(0.0, method.wait_time, 0.01)
2182
+ assert_in_delta(0.0, method.self_time, 0.01)
2183
+ assert_in_delta(0.0, method.children_time, 0.01)
2184
+
2185
+ method = methods[10]
2186
+ assert_equal('BasicObject#initialize', method.full_name)
2187
+ assert_in_delta(0.0, method.total_time, 0.05)
2188
+ assert_in_delta(0.0, method.wait_time, 0.05)
2189
+ assert_in_delta(0.0, method.self_time, 0.05)
2190
+ assert_in_delta(0.0, method.children_time, 0.05)
2191
+ end
2192
+
2193
+ def test_instance_methods_busy_threaded
2194
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2195
+ background_thread = Thread.new do
2196
+ RubyProf::C1.new.busy_wait
2197
+ end
2198
+ background_thread.join
2199
+ end
2200
+
2201
+ assert_equal(2, result.threads.count)
2202
+
2203
+ thread = result.threads.first
2204
+ assert_in_delta(0.2, thread.total_time, 0.05)
2205
+
2206
+ methods = result.threads.first.methods.sort.reverse
2207
+ assert_equal(4, methods.length)
2208
+
2209
+ # Check times
2210
+ method = methods[0]
2211
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
2212
+ assert_in_delta(0.2, method.total_time, 0.05)
2213
+ assert_in_delta(0.0, method.wait_time, 0.05)
2214
+ assert_in_delta(0.0, method.self_time, 0.05)
2215
+ assert_in_delta(0.2, method.children_time, 0.05)
2216
+
2217
+ method = methods[1]
2218
+ assert_equal('Thread#join', method.full_name)
2219
+ assert_in_delta(0.2, method.total_time, 0.05)
2220
+ assert_in_delta(0.2, method.wait_time, 0.05)
2221
+ assert_in_delta(0.0, method.self_time, 0.05)
2222
+ assert_in_delta(0.0, method.children_time, 0.05)
2223
+
2224
+ method = methods[2]
2225
+ assert_equal('<Class::Thread>#new', method.full_name)
2226
+ assert_in_delta(0.0, method.total_time, 0.05)
2227
+ assert_in_delta(0.0, method.wait_time, 0.05)
2228
+ assert_in_delta(0.0, method.self_time, 0.05)
2229
+ assert_in_delta(0.0, method.children_time, 0.05)
2230
+
2231
+ method = methods[3]
2232
+ assert_equal('Thread#initialize', method.full_name)
2233
+ assert_in_delta(0.0, method.total_time, 0.05)
2234
+ assert_in_delta(0.0, method.wait_time, 0.05)
2235
+ assert_in_delta(0.0, method.self_time, 0.05)
2236
+ assert_in_delta(0.0, method.children_time, 0.05)
2237
+
2238
+ thread = result.threads.last
2239
+ assert_in_delta(0.2, thread.total_time, 0.05)
2240
+
2241
+ methods = result.threads.first.methods.sort.reverse
2242
+ assert_equal(4, methods.length)
2243
+
2244
+ methods = result.threads.last.methods.sort.reverse
2245
+ assert_equal(7, methods.length)
2246
+
2247
+ # Check times
2248
+ method = methods[0]
2249
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
2250
+ assert_in_delta(0.2, method.total_time, 0.05)
2251
+ assert_in_delta(0.0, method.wait_time, 0.05)
2252
+ assert_in_delta(0.0, method.self_time, 0.05)
2253
+ assert_in_delta(0.2, method.children_time, 0.05)
2254
+
2255
+ method = methods[1]
2256
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
2257
+ assert_in_delta(0.2, method.total_time, 0.05)
2258
+ assert_in_delta(0.0, method.wait_time, 0.05)
2259
+ assert_in_delta(0.1, method.self_time, 0.05)
2260
+ assert_in_delta(0.1, method.children_time, 0.05)
2261
+
2262
+ method = methods[2]
2263
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2264
+ assert_in_delta(0.03, method.total_time, 0.05)
2265
+ assert_in_delta(0.0, method.wait_time, 0.05)
2266
+ assert_in_delta(0.03, method.self_time, 0.05)
2267
+ assert_in_delta(0.0, method.children_time, 0.05)
2268
+
2269
+ method = methods[3]
2270
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2271
+ assert_in_delta(0.0, method.total_time, 0.05)
2272
+ assert_in_delta(0.0, method.wait_time, 0.05)
2273
+ assert_in_delta(0.0, method.self_time, 0.05)
2274
+ assert_in_delta(0.0, method.children_time, 0.05)
2275
+
2276
+ method = methods[4]
2277
+ assert_includes(['Float#<', 'Float#-'], method.full_name)
2278
+ assert_in_delta(0.0, method.total_time, 0.05)
2279
+ assert_in_delta(0.0, method.wait_time, 0.05)
2280
+ assert_in_delta(0.0, method.self_time, 0.05)
2281
+ assert_in_delta(0.0, method.children_time, 0.05)
2282
+
2283
+ method = methods[5]
2284
+ assert_equal('Class#new', method.full_name)
2285
+ assert_in_delta(0.0, method.total_time, 0.05)
2286
+ assert_in_delta(0.0, method.wait_time, 0.05)
2287
+ assert_in_delta(0.0, method.self_time, 0.05)
2288
+ assert_in_delta(0.0, method.children_time, 0.05)
2289
+
2290
+ method = methods[6]
2291
+ assert_equal('BasicObject#initialize', method.full_name)
2292
+ assert_in_delta(0.0, method.total_time, 0.05)
2293
+ assert_in_delta(0.0, method.wait_time, 0.05)
2294
+ assert_in_delta(0.0, method.self_time, 0.05)
2295
+ assert_in_delta(0.0, method.children_time, 0.05)
2296
+ end
2297
+
2298
+ def test_module_methods_sleep
2299
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2300
+ RubyProf::C2.sleep_wait
2301
+ end
2302
+
2303
+ thread = result.threads.first
2304
+ assert_in_delta(0.0, thread.total_time, 0.05)
2305
+
2306
+ methods = result.threads.first.methods.sort.reverse
2307
+ assert_equal(3, methods.length)
2308
+
2309
+ # Check times
2310
+ method = methods[0]
2311
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
2312
+ assert_in_delta(0.0, method.total_time, 0.05)
2313
+ assert_in_delta(0.0, method.wait_time, 0.05)
2314
+ assert_in_delta(0.0, method.self_time, 0.05)
2315
+ assert_in_delta(0.0, method.children_time, 0.05)
2316
+
2317
+ method = methods[1]
2318
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
2319
+ assert_in_delta(0.0, method.total_time, 0.05)
2320
+ assert_in_delta(0.0, method.wait_time, 0.05)
2321
+ assert_in_delta(0.0, method.self_time, 0.05)
2322
+ assert_in_delta(0.0, method.children_time, 0.05)
2323
+
2324
+ method = methods[2]
2325
+ assert_equal('Kernel#sleep', method.full_name)
2326
+ assert_in_delta(0.0, method.total_time, 0.05)
2327
+ assert_in_delta(0.0, method.wait_time, 0.05)
2328
+ assert_in_delta(0.0, method.self_time, 0.05)
2329
+ assert_in_delta(0.0, method.children_time, 0.05)
2330
+ end
2331
+
2332
+ def test_module_methods_busy
2333
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2334
+ RubyProf::C2.busy_wait
2335
+ end
2336
+
2337
+ thread = result.threads.first
2338
+ assert_in_delta(0.3, thread.total_time, 0.05)
2339
+
2340
+ methods = result.threads.first.methods.sort.reverse
2341
+ assert_equal(5, methods.length)
2342
+
2343
+ # Check times
2344
+ method = methods[0]
2345
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
2346
+ assert_in_delta(0.3, method.total_time, 0.05)
2347
+ assert_in_delta(0.0, method.wait_time, 0.05)
2348
+ assert_in_delta(0.0, method.self_time, 0.05)
2349
+ assert_in_delta(0.3, method.children_time, 0.05)
2350
+
2351
+ method = methods[1]
2352
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
2353
+ assert_in_delta(0.3, method.total_time, 0.05)
2354
+ assert_in_delta(0.0, method.wait_time, 0.05)
2355
+ assert_in_delta(0.15, method.self_time, 0.05)
2356
+ assert_in_delta(0.15, method.children_time, 0.05)
2357
+
2358
+ method = methods[2]
2359
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
2360
+ assert_in_delta(0.05, method.total_time, 0.05)
2361
+ assert_in_delta(0.0, method.wait_time, 0.05)
2362
+ assert_in_delta(0.05, method.self_time, 0.05)
2363
+ assert_in_delta(0.0, method.children_time, 0.05)
2364
+ end
2365
+
2366
+ def test_module_instance_methods_sleep
2367
+ result = RubyProf::Profile.profile(measure_mode: RubyProf::PROCESS_TIME) do
2368
+ RubyProf::C2.new.sleep_wait
2369
+ end
2370
+
2371
+ thread = result.threads.first
2372
+ assert_in_delta(0.0, thread.total_time, 0.05)
2373
+
2374
+ methods = result.threads.first.methods.sort.reverse
2375
+ assert_equal(5, methods.length)
2376
+
2377
+ # Check times
2378
+ method = methods[0]
2379
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
2380
+ assert_in_delta(0.0, method.total_time, 0.05)
2381
+ assert_in_delta(0.0, method.wait_time, 0.05)
2382
+ assert_in_delta(0.0, method.self_time, 0.05)
2383
+ assert_in_delta(0.0, method.children_time, 0.05)
2384
+
2385
+ method = methods[1]
2386
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
2387
+ assert_in_delta(0.0, method.total_time, 0.05)
2388
+ assert_in_delta(0.0, method.wait_time, 0.05)
2389
+ assert_in_delta(0.0, method.self_time, 0.05)
2390
+ assert_in_delta(0.0, method.children_time, 0.05)
2391
+
2392
+ method = methods[2]
2393
+ assert_equal('Class#new', method.full_name)
2394
+ assert_in_delta(0.0, method.total_time, 0.05)
2395
+ assert_in_delta(0.0, method.wait_time, 0.05)
2396
+ assert_in_delta(0.0, method.self_time, 0.05)
2397
+ assert_in_delta(0.0, method.children_time, 0.05)
2398
+
2399
+ method = methods[3]
2400
+ assert_equal('Kernel#sleep', method.full_name)
2401
+ assert_in_delta(0.0, method.total_time, 0.05)
2402
+ assert_in_delta(0.0, method.wait_time, 0.05)
2403
+ assert_in_delta(0.0, method.self_time, 0.05)
2404
+ assert_in_delta(0.0, method.children_time, 0.05)
2405
+
1539
2406
  method = methods[4]
1540
2407
  assert_equal('BasicObject#initialize', method.full_name)
1541
2408
  assert_in_delta(0.0, method.total_time, 0.05)