rails - 为rails消耗的内存做检测 memory leak 检测工具 derailed_benchmarks
访问量: 2023
参考:https://github.com/schneems/derailed_benchmarks
安装:
# 检测内存泄漏 gem 'derailed_benchmarks', group: :development gem 'stackprof', group: :development
然后 $ bundle 就可以
运行:
注意: 默认都是 :default 和 production group下的Gem的情况。
1. 查看各种Gem占用的内存 $ CUT OFF=0 bundle exec derailed bundle:mem ( CUT OFF=0可以只在精确查看的时候使用)
# bundle exec derailed bundle:mem TOP: 117.3281 MiB rails/all: 21.5273 MiB rails: 9.9023 MiB (Also required by: active_record/railtie, active_model/railtie, and 12 others) active_support/railtie: 4.5859 MiB active_support/i18n_railtie: 4.5859 MiB active_support/file_update_checker: 2.6797 MiB (Also required by: rails/application/configuration) active_support/core_ext/time/calculations: 2.6797 MiB (Also required by: active_support/core_ext/time, active_support/core_ext/numeric/time) active_support/core_ext/time/conversions: 2.0195 MiB (Also required by: active_support/core_ext/time, active_support/core_ext/date_time/conversions) active_support/values/time_zone: 1.7695 MiB (Also required by: active_support/time_with_zone, active_support/core_ext/date_time/conversions) tzinfo: 1.7695 MiB tzinfo/timezone: 0.5156 MiB awesome_rails_console: 6.5273 MiB awesome_rails_console/railtie: 6.5078 MiB pry-rails: 6.0273 MiB pry: 6.0273 MiB pry/cli: 2.8281 MiB /root/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/pry-byebug-3.6.0/lib/pry-byebug/cli.rb: 2.8281 MiB pry-byebug/pry_ext: 2.4492 MiB byebug/processors/pry_processor: 2.4492 MiB byebug/core: 2.4492 MiB byebug/commands: 1.8711 MiB byebug/commands/irb: 0.7461 MiB (Also required by: /root/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/byebug-10.0.2/lib/byebug/settings/autoirb.rb) irb: 0.7461 MiB irb/ruby-lex: 0.4922 MiB pry/commands: 1.6602 MiB awesome_print: 0.4805 MiB uglifier: 5.7539 MiB execjs: 4.543 MiB (Also required by: coffee_script) execjs/runtimes: 0.6445 MiB uglifier/version: 0.9922 MiB amoeba: 4.4961 MiB active_record/base: 3.9805 MiB active_record/validations: 0.7734 MiB active_model/validations: 0.5156 MiB active_record/querying: 0.3711 MiB pg: 3.9648 MiB pg_ext: 3.707 MiB
2. 查看生成的对象: $ bundle exec derailed bundle:objects > ~/bundle_objects
Measuring objects created by gems in groups [:default, "production"] Total allocated: 115071535 bytes (947207 objects) Total retained: 17119271 bytes (153423 objects) allocated memory by gem ----------------------------------- 66666792 activesupport-5.0.7 7092878 mime-types-3.1 6425203 sass-3.5.6 5460937 aws-sdk-core-3.48.6 4589682 aws-sdk-s3-1.30.1 2124724 bundler-2.0.1 1940568 set 1669384 pry-0.11.3 1666237 addressable-2.5.2 1281093 aws-sdk-kms-1.17.0