Last active
March 2, 2017 03:25
-
-
Save kkismd/64dc7c4e6302dfa1333c1a2375e2a952 to your computer and use it in GitHub Desktop.
ActiveRecordのメモリ使用量を見積もりたい
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
require 'objspace' | |
module MemoryMesureable | |
extend ActiveSupport::Concern | |
included do | |
delegate :memsize_of, to: ObjectSpace | |
end | |
def memsize | |
memsize_of(self) + | |
memsize_of(@attributes) + | |
memsize_of(@association_cache) + | |
memsize_of(@aggregation_cache) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
models/concerns
に置いて、モデル側でinclude MemoryMesureable
する