Created
November 16, 2010 15:51
-
-
Save cpetschnig/701959 to your computer and use it in GitHub Desktop.
Custom runtime evaluation/profiling
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
class Array | |
@@caller_counter = {} | |
def include_with_caller?(value) | |
key = caller[0,4].join('|') | |
@@caller_counter[key] = (@@caller_counter[key] || 0) + 1 | |
include_without_caller?(value) | |
end | |
alias_method_chain :include?, :caller | |
def self.callers | |
@@caller_counter | |
end | |
def self.print_callers | |
@@caller_counter.map do |key, value| | |
trace = key.split('|') | |
%{\n#{trace.first.ljust(150)} #{value}\n#{trace[1..-1].join("\n")}} | |
end.join("\n--") + "\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment