Project

General

Profile

Bug #9629 ยป standalone.rb

benweint (Ben Weintraub), 03/13/2014 12:31 AM

 
1
#!/usr/bin/env ruby
2

    
3
puts "Run this in another terminal:"
4
puts ""
5
puts "  sudo ./trace-gc-standalone.sh #{$$}"
6
puts ""
7
puts "... wait for the 'Ready!' message, switch back here and press enter to start."
8

    
9
GC::Profiler.enable
10
$stdin.gets
11

    
12
GC::Profiler.clear
13
time_before = GC::Profiler.total_time
14

    
15
# Generate some GC stress...
16
300.times do
17
  symbols = (1..1000).to_a.map { |i| "s#{i}".to_sym }.shuffle
18
  10.times { symbols.sort }
19
end
20

    
21
time_after = GC::Profiler.total_time
22
records = GC::Profiler.raw_data
23

    
24
total_gc_time = time_after - time_before
25

    
26
mark_times  = records.map { |r| r[:GC_MARK_TIME] }.compact
27
sweep_times = records.map { |r| r[:GC_SWEEP_TIME] }.compact
28
total_mark_time = mark_times.inject(:+)
29
total_sweep_time = sweep_times.inject(:+)
30

    
31
puts "Total mark time:  %.1f ms" % [total_mark_time * 1000]
32
puts "Total sweep time: %.1f ms" % [total_sweep_time * 1000]
33
puts "Total GC time:    %.1f ms" % [total_gc_time * 1000]