Skip to content

Instantly share code, notes, and snippets.

@dariocravero
Created January 30, 2013 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariocravero/44f89cd59a837b4517b0 to your computer and use it in GitHub Desktop.
Save dariocravero/44f89cd59a837b4517b0 to your computer and use it in GitHub Desktop.
class Object
def require(ruby_file)
p "Requiring #{ruby_file} ..."
super
stats
end
def load(ruby_file)
p "Loading #{ruby_file} ..."
super
stats
end
end
$last_memusage = 0
def memusage
`ps -o rss= -p #{$$}`.to_i
end
def shrink
last = memusage
loop do
GC.start
sleep 1
m = memusage
break if m == last
last = m
end
end
def stats
shrink
m = memusage
delta = m - $last_memusage
$last_memusage = m
puts "# #{m}K #{delta >= 0 ? '+' : ''}#{delta}K"
end
@minad
Copy link

minad commented Jan 30, 2013

Yeah, I did something similar to. Overwriting require is not a bad idea. But the shrink slows the loading down a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment