Code Monkey home page Code Monkey logo

memprof2's Introduction

memprof2

Build Status

Memprof2 is a Ruby memory profiler for >= Ruby 2.1.0.

Installation

Execute

$ gem install memprof2

or ddd the following to your Gemfile:

gem 'memprof2'

And then execute:

$ bundle

API

Memprof2.report

Memprof2.start
12.times{ "abc" }
Memprof2.report(out: "/path/to/file")
Memprof2.stop

Start tracking file/line memory size (bytes) information for objects created after calling Memprof2.start, and print out a summary of file:line:class pairs created.

480 file.rb:2:String

Note: Call Memprof2.report again after GC.start to see which objects are cleaned up by the garbage collector:

Memprof2.start
10.times{ $last_str = "abc" }

puts '=== Before GC'
Memprof2.report

puts '=== After GC'
GC.start
Memprof2.report

Memprof2.stop

After GC.start, only the very last instance of "abc" will still exist:

=== Before GC
400 file.rb:2:String
=== After GC
40 file.rb:2:String

Note: Use Memprof2.report! to clear out tracking data after printing out results.

Use trace and ignore options to restrict files to report. You can write patterns by regular expressions:

Memprof2.start
10.times{ $last_str = "abc" }
GC.start
Memprof2.report!(trace: /file\.rb/, ignore: /ignore_me/, out: "/path/to/file")
Memprof2.stop

Memprof2.run

Simple wrapper for Memprof2.start/stop that will start/stop memprof around a given block of ruby code.

Memprof2.run do
  100.times{ "abc" }
  100.times{ 1.23 + 1 }
  100.times{ Module.new }
  Memprof2.report(out: "/path/to/file")
end

For the block of ruby code, print out file:line:class pairs for ruby objects created.

4000  file.rb:2:String
4000  file.rb:3:Float
4000  file.rb:4:Module

Note: You can call GC.start at the end of the block to print out only objects that are 'leaking' (i.e. objects that still have inbound references).

ChangeLog

See CHANGELOG.md for details.

See Also

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2014 Naotoshi Seo. See LICENSE.txt for details.

memprof2's People

Contributors

sonots avatar robwillison avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.