Skip to content

Instantly share code, notes, and snippets.

@cmthakur
Created March 10, 2017 05:34
Show Gist options
  • Save cmthakur/87160faede20e05e795e7eb52c412977 to your computer and use it in GitHub Desktop.
Save cmthakur/87160faede20e05e795e7eb52c412977 to your computer and use it in GitHub Desktop.
def variables
variables = GC.stat.keys.map(&:to_s)
end
variables.each do |name|
instance_variable_set("@#{name.to_s.gsub(' ', '_')}", Array.new())
end
def get_recent_stats
GC.stat.each do |key, value|
variable = "@#{key.to_s.gsub(' ', '_')}"
old_value = instance_variable_get(variable) || []
old_value << value
instance_variable_set(variable, old_value)
end
end
variables.each do |name|
arr_value = instance_variable_get("@#{name.to_s.gsub(' ', '_')}")
stat_value = arr_value
puts "#{name}: (#{arr_value.last})"
end
loop do
puts "\e[H\e[2J"
get_recent_stats
variables.each do |name|
arr_value = instance_variable_get("@#{name.to_s.gsub(' ', '_')}")
if [Float, Fixnum].include? arr_value[-1].class
stat_value = arr_value[-1].to_f - arr_value[0].to_f
changes = arr_value[-1].to_f - arr_value[-2].to_f
end
puts "#{name}: (Diff: #{stat_value}: Recent: #{changes}) #{changes.to_i > 0 ? '!' : ''}"
end
sleep 0.5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment