Created
February 10, 2013 23:30
-
-
Save JustinLove/4751510 to your computer and use it in GitHub Desktop.
Hack to see why your program is taking so long to load
This file contains 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 'benchmark' | |
$require_depth = 0 | |
module TimedRequire | |
LIMIT = 0.0 | |
def require(path) | |
#puts " #{' '*$require_depth}>>#{path}" | |
begin | |
$require_depth += 1 | |
t = 0.0 | |
t = Benchmark.realtime {super} | |
rescue Exception | |
puts "!!!!!!! exception during #{path} !!!!!!!" | |
raise | |
ensure | |
$require_depth -= 1 | |
if t > LIMIT | |
puts "#{'%1.3f'%t}#{' '*$require_depth}<<#{path}" | |
end | |
end | |
end | |
def load(path) | |
#puts " #{' '*$require_depth}>>#{path}" | |
begin | |
$require_depth += 1 | |
t = 0.01 | |
t = Benchmark.realtime {super} | |
rescue Exception | |
puts "!!!!!!! exception during #{path} !!!!!!!" | |
raise | |
ensure | |
$require_depth -= 1 | |
if t > LIMIT | |
puts "#{'%1.3f'%t}#{' '*$require_depth}<<#{path}" | |
end | |
end | |
end | |
end | |
extend TimedRequire |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment