Created
September 25, 2014 08:41
-
-
Save piotrze/e53817ccf9218af22742 to your computer and use it in GitHub Desktop.
Count number of objects created per request
This file contains hidden or 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
#app/controllers/application_controller.rb | |
around_filter :log_objects_creation | |
protected | |
def log_objects_creation | |
started = ObjectSpace.count_objects[:T_OBJECT] | |
yield | |
elapsed = ObjectSpace.count_objects[:T_OBJECT] - started | |
MemoryLogger.info("#{Time.now}| #{elapsed}| #{params}| #{current_user.nil? ? '' : current_user.id}") if elapsed > 2000 | |
end |
This file contains hidden or 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
#config/initializers/memory_logger.rb | |
MemoryLogger = Logger.new("#{Rails.root}/log/ruby_memory.log") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment