File: memory.rb

package info (click to toggle)
ruby-async-io 1.34.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 424 kB
  • sloc: ruby: 3,103; makefile: 4
file content (16 lines) | stat: -rw-r--r-- 382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frozen_string_literal: true

def measure_memory(annotation = "Memory allocated")
	GC.disable
	
	start_memory = `ps -p #{Process::pid} -o rss`.split("\n")[1].chomp.to_i

	yield
	
ensure
	end_memory = `ps -p #{Process::pid} -o rss`.split("\n")[1].chomp.to_i
	memory_usage = (end_memory - start_memory).to_f / 1024
	
	puts "#{memory_usage.round(1)} MB: #{annotation}"
	GC.enable
end