object_space_diff 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: b7ece1a0b46b72de1810ae87694aa881cbcc1312
4
+ data.tar.gz: 8d148a1b4460e87a1114ab9ce5510921a3bdbe72
5
+ SHA512:
6
+ metadata.gz: 80d1261bcb8a669963094efcd706d4c6c3d728739bbabf84b622fe2dea8f3e0abf5474fc2d316580da9fb642ab361ba1dfc28c5505480311d3e80c67f86df72c
7
+ data.tar.gz: 04f3917a0195aa2a39c7b5e314a0380beab7da0ea927dad422d84bf36afa8a0b46e44ee2d80dd323ceadca43ab8c04084256b5f9d6aec5c173068e28cbfce102
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
+ .ruby-version
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ervin Weber
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,36 @@
1
+ # ObjectSpaceDiff
2
+
3
+ Lists new objects left in global ObjectSpace after yielding a block
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'object_space_diff'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install object_space_diff
18
+
19
+ ## Usage
20
+
21
+ use as module method:
22
+ ObjectSpaceDiff.puts_changes(target=$stdout)
23
+ or
24
+
25
+ include ObjectSpaceDiff in your code and use instance methods as needed.
26
+
27
+ * if $DEBUG is set then also internal variables are included in output.
28
+ * if $DEBUG is not set then also block output value is not included in output.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module ObjectSpaceDiff
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "object_space_diff/version"
2
+ # $: << './lib' ; require 'object_space_diff'; ObjectSpaceDiff.puts_changes{}
3
+ module ObjectSpaceDiff
4
+
5
+ def puts_changes(target=$stdout)
6
+ klass = Object
7
+ object_ids = ObjectSpace.each_object(klass).collect(&:object_id)
8
+ data = yield
9
+
10
+
11
+ ObjectSpace.garbage_collect
12
+ sleep 1
13
+ ObjectSpace.garbage_collect
14
+
15
+ new_ids = ObjectSpace.each_object(klass).collect(&:object_id)
16
+ ids_diff = (new_ids - object_ids)
17
+
18
+ (ids_diff).each_with_index do |oid,i|
19
+ if oid == object_ids.object_id ||
20
+ oid == new_ids.object_id ||
21
+ oid == ids_diff.object_id ||
22
+ oid == data.object_id ||
23
+ oid == klass.object_id
24
+ target.puts "#{i+1} #{oid}: junk_collector_internal, skipping" if $DEBUG
25
+ next
26
+ end
27
+ obj = ObjectSpace._id2ref(oid)
28
+ if obj.kind_of?(Array) && obj.first.object_id == klass.object_id
29
+ target.puts "#{i+1} #{oid}: junk_collector_internal, skipping" if $DEBUG
30
+ else
31
+ target.puts "#{i+1} #{oid}:\n\t\t#{obj.class}\n\t\t#{obj}"
32
+ end
33
+ obj = nil
34
+ end
35
+ new_ids = nil
36
+ object_ids = nil
37
+ klass = nil
38
+ data
39
+ end
40
+ module_function :puts_changes
41
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'object_space_diff/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "object_space_diff"
8
+ gem.version = ObjectSpaceDiff::VERSION
9
+ gem.authors = ["Ervin Weber"]
10
+ gem.email = ["webervin@gmail.com"]
11
+ gem.description = "Gem helps analyze object space before and after yielding a block"
12
+ gem.summary = "Gives insight to code leaks or unnecessary string initialization"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_development_dependency 'rake'
20
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: object_space_diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ervin Weber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-18 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
+ description: Gem helps analyze object space before and after yielding a block
28
+ email:
29
+ - webervin@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/object_space_diff.rb
39
+ - lib/object_space_diff/version.rb
40
+ - object_space_diff.gemspec
41
+ homepage: ''
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.0.0
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Gives insight to code leaks or unnecessary string initialization
64
+ test_files: []