memprof2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70b0b317e5659917d244b780e9c03035c1c06792
4
+ data.tar.gz: 10d94aa32210670aecb272e61fa1264cbde82446
5
+ SHA512:
6
+ metadata.gz: 7605deeb9ea4cbdabdd69c00eeee95e827f3ee138d6618945641a8dd29c5317fcdafc7f8c1307acb88b1543648a8f0355c5cbd83e5aaf6b2e3cd22b0916abf01
7
+ data.tar.gz: 80dfd4f07fe669765e2f983961cae0b517289d69203d64303cb8c3cd68496e5acff0252e26a056f025e595d83d9cc9505fb919fe6676cd04d8e7f1d73c2f5abd
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ example.out
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ script: 'bundle exec rake test'
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.0.1
2
+
3
+ Initial version
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Naotoshi Seo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # memprof2
2
+
3
+ [![Build Status](https://secure.travis-ci.org/sonots/memprof2.png?branch=master)](http://travis-ci.org/sonots/memprof2)
4
+
5
+ Memprof2 is a Ruby memory profiler for >= Ruby 2.1.0.
6
+
7
+ # Installation
8
+
9
+ Execute
10
+
11
+ ```
12
+ $ gem install memprof
13
+ ```
14
+
15
+ or ddd the following to your `Gemfile`:
16
+
17
+ ```ruby
18
+ gem 'memprof2'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```plain
24
+ $ bundle
25
+ ```
26
+
27
+ # API
28
+
29
+ ## Memprof2.report
30
+
31
+ Memprof2.start
32
+ 12.times{ "abc" }
33
+ Memprof2.report(out: "/path/to/file")
34
+ Memprof2.stop
35
+
36
+ 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.
37
+
38
+ 480 file.rb:2:String
39
+
40
+ *Note*: Call `Memprof2.report` again after `GC.start` to see which objects are cleaned up by the garbage collector:
41
+
42
+ Memprof2.start
43
+ 10.times{ $last_str = "abc" }
44
+
45
+ puts '=== Before GC'
46
+ Memprof2.report
47
+
48
+ puts '=== After GC'
49
+ GC.start
50
+ Memprof2.report
51
+
52
+ Memprof2.stop
53
+
54
+ After `GC.start`, only the very last instance of `"abc"` will still exist:
55
+
56
+ === Before GC
57
+ 400 file.rb:2:String
58
+ === After GC
59
+ 40 file.rb:2:String
60
+
61
+ *Note*: Use `Memprof2.report!` to clear out tracking data after printing out results.
62
+
63
+ ## Memprof2.run
64
+
65
+ Simple wrapper for `Memprof2.start/stop` that will start/stop memprof around a given block of ruby code.
66
+
67
+ Memprof2.run do
68
+ 100.times{ "abc" }
69
+ 100.times{ 1.23 + 1 }
70
+ 100.times{ Module.new }
71
+ Memprof2.report(out: "/path/to/file")
72
+ end
73
+
74
+ For the block of ruby code, print out file:line:class pairs for ruby objects created.
75
+
76
+ 4000 file.rb:2:String
77
+ 4000 file.rb:3:Float
78
+ 4000 file.rb:4:Module
79
+
80
+ *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).
81
+
82
+ ## ChangeLog
83
+
84
+ See [CHANGELOG.md](CHANGELOG.md) for details.
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create new [Pull Request](../../pull/new/master)
93
+
94
+ ## Copyright
95
+
96
+ Copyright (c) 2014 Naotoshi Seo. See [LICENSE.txt](LICENSE.txt) for details.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ desc 'Run test'
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = "test/test_*.rb"
8
+ end
9
+ task :default => :test
10
+
11
+ desc 'Open an irb session preloaded with the gem library'
12
+ task :console do
13
+ sh 'irb -rubygems -I lib'
14
+ end
15
+ task :c => :console
data/example.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'memprof2'
2
+
3
+ ##############
4
+ Memprof2.start
5
+ 12.times{ "abc" }
6
+ Memprof2.report
7
+ Memprof2.stop
8
+
9
+
10
+ ##############
11
+ Memprof2.start
12
+ 10.times{ $last_str = "abc" }
13
+
14
+ puts '=== Before GC'
15
+ Memprof2.report
16
+
17
+ puts '=== After GC'
18
+ GC.start
19
+ Memprof2.report
20
+
21
+ Memprof2.stop
22
+
23
+ #############
24
+ Memprof2.run do
25
+ 100.times{ "abc" }
26
+ 100.times{ 1.23 + 1 }
27
+ 100.times{ Module.new }
28
+ Memprof2.report(out: "example.out")
29
+ end
data/lib/memprof2.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'objspace'
2
+
3
+ module Memprof2
4
+ class << self
5
+ def start
6
+ ObjectSpace.trace_object_allocations_start
7
+ end
8
+
9
+ def stop
10
+ ObjectSpace.trace_object_allocations_stop
11
+ ObjectSpace.trace_object_allocations_clear
12
+ end
13
+
14
+ def run(&block)
15
+ ObjectSpace.trace_object_allocations(&block)
16
+ end
17
+
18
+ def report(opts={})
19
+ ObjectSpace.trace_object_allocations_stop
20
+ @rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
21
+ if @trace = opts[:trace]
22
+ raise ArgumentError, "`trace` option must be a Regexp object" unless @trace.is_a?(Regexp)
23
+ end
24
+ if @ignore = opts[:ignore]
25
+ raise ArgumentError, "`trace` option must be a Regexp object" unless @ignore.is_a?(Regexp)
26
+ end
27
+ results = {}
28
+ ObjectSpace.each_object do |o|
29
+ next unless (file = ObjectSpace.allocation_sourcefile(o))
30
+ next if file == __FILE__
31
+ next if (@trace and @trace !~ file)
32
+ next if (@ignore and @ignore =~ file)
33
+ line = ObjectSpace.allocation_sourceline(o)
34
+ memsize = ObjectSpace.memsize_of(o) + @rvalue_size
35
+ memsize = @rvalue_size if memsize > 100_000_000_000 # compensate for API bug
36
+ klass = o.class.name rescue "BasicObject"
37
+ location = "#{file}:#{line}:#{klass}"
38
+ results[location] ||= 0
39
+ results[location] += memsize
40
+ end
41
+ @out = opts[:out] || "/dev/stdout"
42
+ File.open(@out, 'w') do |io|
43
+ results.each do |location, memsize|
44
+ io.puts "#{memsize} #{location}"
45
+ end
46
+ end
47
+ ensure
48
+ ObjectSpace.trace_object_allocations_start
49
+ end
50
+ end
51
+ end
52
+
53
+
data/memprof2.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "memprof2"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Naotoshi Seo"]
5
+ spec.email = ["sonots@gmail.com"]
6
+ spec.description = %q{Ruby memory profiler for >= Ruby 2.1.0}
7
+ spec.summary = %q{Ruby memory profiler for >= Ruby 2.1.0}
8
+ spec.homepage = "https://github.com/sonots/memprof2"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_development_dependency "rake"
17
+ spec.add_development_dependency "test-unit"
18
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memprof2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby memory profiler for >= Ruby 2.1.0
42
+ email:
43
+ - sonots@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - example.rb
56
+ - lib/memprof2.rb
57
+ - memprof2.gemspec
58
+ homepage: https://github.com/sonots/memprof2
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Ruby memory profiler for >= Ruby 2.1.0
82
+ test_files: []