@@ -1657,13 +1657,10 @@ def metrics_native_instructions(*args)
1657
1657
end
1658
1658
end
1659
1659
1660
- def metrics_time ( *args )
1661
- use_json = args . delete '--json'
1662
- flamegraph = args . delete '--flamegraph'
1660
+ def metrics_time_measure ( use_json , *args )
1663
1661
native = args . include? '--native'
1664
1662
metrics_time_option = "#{ native ? '--native.D' : '-J-D' } truffleruby.metrics.time=true"
1665
1663
verbose_gc_flag = native ? '--native.XX:+PrintGC' : '-J-verbose:gc' unless use_json
1666
- min_time = Float ( ENV . fetch ( "TRUFFLERUBY_METRICS_MIN_TIME" , "-1" ) )
1667
1664
args = [ metrics_time_option , *verbose_gc_flag , '--no-core-load-path' , *args ]
1668
1665
1669
1666
samples = METRICS_REPS . times . map do
@@ -1674,6 +1671,32 @@ def metrics_time(*args)
1674
1671
get_times ( out , ( finish - start ) * 1000.0 )
1675
1672
end
1676
1673
log "\n " , nil
1674
+ samples
1675
+ end
1676
+ private :metrics_time_measure
1677
+
1678
+ def metrics_time ( *args )
1679
+ use_json = args . delete '--json'
1680
+ flamegraph = args . delete '--flamegraph'
1681
+
1682
+ samples = metrics_time_measure ( use_json , *args )
1683
+ metrics_time_format_results ( samples , use_json , flamegraph )
1684
+ end
1685
+
1686
+ def format_time_metrics ( *args )
1687
+ use_json = args . delete '--json'
1688
+ flamegraph = args . delete '--flamegraph'
1689
+
1690
+ data = STDIN . read
1691
+ times = data . lines . grep ( /^(before|after)\b / )
1692
+ total = times . last . split . last . to_f - times . first . split . last . to_f
1693
+ samples = [ get_times ( data , total ) ]
1694
+
1695
+ metrics_time_format_results ( samples , use_json , flamegraph )
1696
+ end
1697
+
1698
+ def metrics_time_format_results ( samples , use_json , flamegraph )
1699
+ min_time = Float ( ENV . fetch ( "TRUFFLERUBY_METRICS_MIN_TIME" , "-1" ) )
1677
1700
1678
1701
results = { }
1679
1702
mean_by_stack = { }
@@ -1716,6 +1739,7 @@ def metrics_time(*args)
1716
1739
sh "#{ repo } /flamegraph.pl" , "--flamechart" , "--countname" , "ms" , path , out : "time_metrics_flamegraph.svg"
1717
1740
end
1718
1741
end
1742
+ private :metrics_time_format_results
1719
1743
1720
1744
def get_times ( trace , total )
1721
1745
result = Hash . new ( 0 )
@@ -1724,7 +1748,7 @@ def get_times(trace, total)
1724
1748
result [ stack . map ( &:first ) ] = total
1725
1749
result [ %w[ total jvm ] ] = 0
1726
1750
1727
- trace . lines do |line |
1751
+ trace . each_line do |line |
1728
1752
if line =~ /^(.+) (\d +)$/
1729
1753
region = $1
1730
1754
time = Float ( $2)
0 commit comments