Created
November 10, 2013 21:17
-
-
Save xaviershay/7404068 to your computer and use it in GitHub Desktop.
naive jstat proof-of-concept for ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thread.new do | |
GC::Profiler.enable | |
current_message = "" | |
epoch = Time.now | |
total_time = 0 | |
gc_events = 0 | |
heap_use = 0 | |
heap_size = 0 | |
fmt = "%7s %5s %15s %15s %10s" | |
Thread.new do | |
loop do | |
# TODO: Could drop GC events added between accessing them and clearing. | |
total_time += GC::Profiler.total_time | |
GC::Profiler.raw_data.each do |gc_event| | |
heap_use = gc_event[:HEAP_USE_SIZE] | |
heap_size = gc_event[:HEAP_TOTAL_SIZE] | |
gc_events += 1 | |
end | |
GC::Profiler.clear | |
current_message = fmt % [ | |
"%.2f" % (Time.now - epoch), | |
gc_events, | |
"%.2f" % (heap_use / 1024.0 / 1024), | |
"%.2f" % (heap_size / 1024.0 / 1024), | |
"%.3f" % total_time | |
] | |
sleep 0.5 | |
end | |
end | |
server = TCPServer.new 8787 | |
loop do | |
Thread.start(server.accept) do |client| | |
begin | |
client.puts fmt % [ | |
"Time", | |
"#", | |
"Heap Use (mb)", | |
"Heap Size (mb)", | |
"GC Time (s)" | |
] | |
loop do | |
client.puts current_message | |
sleep 0.5 | |
end | |
rescue Errno::EPIPE | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> telnet localhost 8787 | |
Time # Heap Use (mb) Heap Size (mb) GC Time (s) | |
0.50 7 2.22 2.25 0.002 | |
1.00 61 3.06 3.09 0.003 | |
1.50 139 3.91 3.94 0.006 | |
2.00 194 4.76 4.80 0.007 | |
2.50 248 5.60 5.64 0.008 | |
3.01 302 6.44 6.47 0.009 | |
3.51 390 7.11 7.14 0.012 | |
4.01 445 7.96 8.00 0.013 | |
4.51 500 8.81 8.85 0.014 | |
5.01 554 9.65 9.69 0.015 | |
5.51 608 10.49 10.53 0.016 | |
6.02 662 11.34 11.38 0.018 | |
6.52 717 12.20 12.23 0.019 | |
7.02 834 12.43 12.45 0.021 | |
7.52 943 12.43 12.45 0.022 | |
8.02 1052 12.43 12.45 0.023 | |
8.52 1162 12.43 12.45 0.024 | |
9.02 1271 12.43 12.45 0.025 | |
9.52 1399 9.22 12.45 0.026 | |
10.03 1513 9.22 12.45 0.028 | |
10.53 1622 9.22 12.45 0.029 | |
11.03 1733 9.22 12.45 0.030 | |
11.53 1841 9.22 12.45 0.031 | |
12.03 1957 9.20 12.45 0.032 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
require './ruby_live_gc_stats' | |
loop do | |
1000.times do | |
Object.new | |
end | |
sleep 0.01 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment