Created
March 31, 2014 08:05
-
-
Save cppforlife/9887480 to your computer and use it in GitHub Desktop.
Quick require debug
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_indent = 0 | |
$require_times = [] | |
$require_abs_start = Time.now.to_f | |
def putz(*args, &blk) | |
puts(*args, &blk) | |
end | |
module Kernel | |
alias_method :old_require, :require | |
def require(*args) | |
t1 = Time.now.to_f | |
indent_marker = "-- " * $require_indent | |
putz "#{"%10.6f" % (t1 - $require_abs_start)} #{indent_marker}#{args.inspect}" | |
$require_indent += 1 | |
old_require(*args) | |
ensure | |
$require_indent -= 1 | |
t2 = Time.now.to_f | |
tt = t2 - t1 | |
$require_times << [tt, args] if $require_indent == 1 | |
importance_marker = "<---" * (tt / 0.1) | |
putz "#{"%10.6f" % (t2 - $require_abs_start)} #{indent_marker}Done in #{tt} for #{args.inspect} #{importance_marker}" | |
end | |
end | |
# ... | |
putz "Slowest requires:" | |
slowest_tt = 0 | |
$require_times.sort_by { |v| -v[0] }.each do |(tt, args)| | |
putz "#{"%10.6f" % tt} Done in #{tt} for #{args}" | |
slowest_tt += tt | |
break if tt < 0.02 | |
end | |
putz "Slowest total: #{slowest_tt}\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment