Skip to content

βœ… How to measure with a graph output the memory and CPU ?

Benoit Tigeot edited this page Jan 4, 2019 · 3 revisions

Sometimes it's good to display memory and CPU consumption over time. There is a nice tool for that called psrecord + matplotlib.

Here is an example:

child_pid = spawn "psrecord #{Process.pid} --plot plot_#{Time.now.strftime('%H_%M_%S')}.png"

a = []
10_000_000.times { |i| a << i.to_s }

puts Process.kill('SIGINT', child_pid)
puts "continue scripting"

graph

On OSX you can also use malloc_history then process the result with R. See https://github.com/ruby/ruby/pull/2029#issuecomment-442204121

Clone this wiki locally