quick_mem 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.ruby_version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +5 -0
- data/lib/quick_mem/gc_constants.rb +13 -0
- data/lib/quick_mem/quick_mem.rb +41 -0
- data/lib/quick_mem/version.rb +3 -0
- data/quick_mem.gemspec +41 -0
- data/quick_mem.sublime-project +15 -0
- data/quick_mem.txt +29 -0
- data/spec/quick_mem/quick_mem_spec.rb +76 -0
- data/spec/spec_helper.rb +5 -0
- data/tasks/rspec.rake +3 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7565407689659edeb05b71cb00b50be51f9c618a
|
4
|
+
data.tar.gz: f22618bf4aa69405e9815161034e467d306a73cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 066525a7fa05e68c01216377908442be8f0cf6f20cecf2f0d2a6e6f0e06caeb893662a4b1485dca38af80a38d808fe964b98aa087e433711ebb17083250c6fb5
|
7
|
+
data.tar.gz: bc53aec114d2ea8d0ec65cd3dcc24ba92a938759bcbede18f410259a3320ccf6c4ac897590fd348ff1b9ebe6411d92ddf33c62348b73f8df04987d62a74685e2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby_version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rajiv Nair
|
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,48 @@
|
|
1
|
+
# QuickMem
|
2
|
+
|
3
|
+
A simple gem to dump memory stats. Primarily written to tick off the "I wrote a gem" box.
|
4
|
+
I'll probably improve it to be some kind of analyzer/profiler if time permits.
|
5
|
+
Suggestions welcome!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'quick_mem'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install quick_mem
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/rajivrnair/quick_mem/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
34
|
+
|
35
|
+
|
36
|
+
## Useful Reading
|
37
|
+
http://www.atdot.net/~ko1/activities/rubyconf2013-ko1_pub.pdf
|
38
|
+
http://www.omniref.com/blog/blog/2014/03/27/ruby-garbage-collection-still-not-ready-for-production/
|
39
|
+
http://samsaffron.com/archive/2014/04/08/ruby-2-1-garbage-collection-ready-for-production
|
40
|
+
http://samsaffron.com/archive/2013/11/22/demystifying-the-ruby-gc
|
41
|
+
http://thorstenball.com/blog/2014/03/12/watching-understanding-ruby-2.1-garbage-collector/
|
42
|
+
http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning
|
43
|
+
http://stackoverflow.com/questions/16850551/ruby-gcprofiler-use-size-is-greater-than-total-size
|
44
|
+
https://github.com/ko1/gc_tracer/
|
45
|
+
|
46
|
+
https://quickleft.com/blog/engineering-lunch-series-step-by-step-guide-to-building-your-first-ruby-gem/
|
47
|
+
http://www.smashingmagazine.com/2014/04/08/how-to-build-a-ruby-gem-with-bundler-test-driven-development-travis-ci-and-coveralls-oh-my/
|
48
|
+
http://recipes.sinatrarb.com/p/development/bundler
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'quick_mem/version'
|
2
|
+
require 'quick_mem/gc_constants'
|
3
|
+
|
4
|
+
module QuickMem
|
5
|
+
class QuickMemory
|
6
|
+
|
7
|
+
def self.version
|
8
|
+
QuickMem::VERSION
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.show_config
|
12
|
+
gc_stat = GC.stat
|
13
|
+
config = Hash.new
|
14
|
+
gc_counts(config, gc_stat)
|
15
|
+
heap_statistics(config, gc_stat)
|
16
|
+
config
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.heap_statistics(config, gc_stat)
|
22
|
+
config[:heap_allocated] = gc_stat[:heap_length] * slot_size * slots_per_page
|
23
|
+
config[:heap_used] = gc_stat[:heap_eden_page_length] * slot_size * slots_per_page
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.gc_counts(config, gc_stat)
|
27
|
+
config[:major_gc_count] = gc_stat[:major_gc_count]
|
28
|
+
config[:minor_gc_count] = gc_stat[:minor_gc_count]
|
29
|
+
config[:total_gc_count] = gc_stat[:count]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.slot_size
|
33
|
+
QuickMem::GCConstants.slot_size
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.slots_per_page
|
37
|
+
QuickMem::GCConstants.slots_per_page
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/quick_mem.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quick_mem/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quick_mem"
|
8
|
+
spec.version = QuickMem::VERSION
|
9
|
+
spec.authors = ["Rajiv Nair"]
|
10
|
+
spec.email = ["rajivrnair@gmail.com"]
|
11
|
+
spec.summary = %q{Quickly look at GC stats}
|
12
|
+
spec.description = %q{A simple gem to dump memory stats}
|
13
|
+
spec.homepage = "https://github.com/rajivrnair/quick_mem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~>3.1.0'
|
24
|
+
end
|
25
|
+
|
26
|
+
# group :test do
|
27
|
+
# gem 'rspec', '3.1.0'
|
28
|
+
# gem 'json_spec', '1.1.2'
|
29
|
+
# gem 'shoulda-matchers', '2.6.1'
|
30
|
+
# gem 'webmock', '1.17.4'
|
31
|
+
# gem 'rubocop', '0.19.1', require: false
|
32
|
+
# gem 'timecop', '0.7.1'
|
33
|
+
# gem 'capybara', '2.3.0'
|
34
|
+
# gem 'cane', '2.6.1'
|
35
|
+
# gem 'reek', '1.3.6'
|
36
|
+
# gem 'flay', '2.4.0'
|
37
|
+
# gem 'flog', '4.2.0'
|
38
|
+
# gem 'simplecov', '~> 0.7.1'
|
39
|
+
# gem 'rack-test', '0.6.2', require: 'rack/test'
|
40
|
+
# gem 'faker', '1.3.0'
|
41
|
+
# end
|
data/quick_mem.txt
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Total Heap size/ Heap size used / % used / % free
|
2
|
+
Total number of objects
|
3
|
+
Total Allocated slots / slots used
|
4
|
+
|
5
|
+
RUBY_GC_MALLOC_LIMIT
|
6
|
+
RUBY_GC_HEAP_INIT_SLOTS
|
7
|
+
RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR
|
8
|
+
RUBY_HEAP_MIN_SLOTS
|
9
|
+
RUBY_HEAP_SLOTS_INCREMENT
|
10
|
+
RUBY_HEAP_SLOTS_GROWTH_FACTOR
|
11
|
+
RUBY_HEAP_FREE_MIN
|
12
|
+
|
13
|
+
|
14
|
+
GC.allocated_size
|
15
|
+
GC.num_allocations
|
16
|
+
|
17
|
+
ObjectSpace.live_objects
|
18
|
+
ObjectSpace.allocated_objects
|
19
|
+
|
20
|
+
slot_size: GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
|
21
|
+
slots_per_page: GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT]
|
22
|
+
|
23
|
+
GC.stat[:heap_length] - total pages allocated.
|
24
|
+
GC.stat[:heap_used] - total pages used.
|
25
|
+
GC.stat[:heap_increment]
|
26
|
+
|
27
|
+
allocated_memory: heap_length * slots_per_page * slot_size
|
28
|
+
used_memory: heap_eden_page_length * slots_per_page * slot_size
|
29
|
+
live_objects: heap_live_slot
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'quick_mem/quick_mem'
|
4
|
+
|
5
|
+
module QuickMem
|
6
|
+
describe QuickMemory do
|
7
|
+
|
8
|
+
describe '#version' do
|
9
|
+
subject { QuickMemory.version }
|
10
|
+
|
11
|
+
it 'outputs the correct version number' do
|
12
|
+
expect(subject).to eq '0.0.1'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#show_config' do
|
17
|
+
subject { QuickMemory.show_config }
|
18
|
+
let(:mem_options) {
|
19
|
+
{
|
20
|
+
count: 22,
|
21
|
+
heap_eden_page_length: 226,
|
22
|
+
heap_final_slot: 0,
|
23
|
+
heap_free_slot: 829,
|
24
|
+
heap_increment: 0,
|
25
|
+
heap_length: 237,
|
26
|
+
heap_live_slot: 91292,
|
27
|
+
heap_swept_slot: 22651,
|
28
|
+
heap_tomb_page_length: 0,
|
29
|
+
heap_used: 226,
|
30
|
+
major_gc_count: 4,
|
31
|
+
malloc_increase: 545344,
|
32
|
+
malloc_limit: 16777216,
|
33
|
+
minor_gc_count: 18,
|
34
|
+
old_object: 54719,
|
35
|
+
old_object_limit: 56776,
|
36
|
+
oldmalloc_increase: 6406440,
|
37
|
+
oldmalloc_limit: 16777216,
|
38
|
+
remembered_shady_object: 811,
|
39
|
+
remembered_shady_object_limit: 758,
|
40
|
+
total_allocated_object: 524356,
|
41
|
+
total_freed_object: 433064
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
before do
|
46
|
+
# assuming default values for
|
47
|
+
# GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] = 40
|
48
|
+
# GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT] = 408
|
49
|
+
|
50
|
+
allow(GC).to receive(:stat) { mem_options }
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'spits out the number of major GCs' do
|
54
|
+
expect(subject[:major_gc_count]).to eq(4)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'spits out the number of minor GCs' do
|
58
|
+
expect(subject[:minor_gc_count]).to eq(18)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'spits out the total number of GCs' do
|
62
|
+
expect(subject[:total_gc_count]).to eq(22)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'spits out the total heap allocated in bytes' do
|
66
|
+
expect(subject[:heap_allocated]).to eq(3867840)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'spits out the heap used in bytes' do
|
70
|
+
expect(subject[:heap_used]).to eq(3688320)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quick_mem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rajiv Nair
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
description: A simple gem to dump memory stats
|
56
|
+
email:
|
57
|
+
- rajivrnair@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby_version"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/quick_mem/gc_constants.rb
|
70
|
+
- lib/quick_mem/quick_mem.rb
|
71
|
+
- lib/quick_mem/version.rb
|
72
|
+
- quick_mem.gemspec
|
73
|
+
- quick_mem.sublime-project
|
74
|
+
- quick_mem.txt
|
75
|
+
- spec/quick_mem/quick_mem_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- tasks/rspec.rake
|
78
|
+
homepage: https://github.com/rajivrnair/quick_mem
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.2.2
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Quickly look at GC stats
|
102
|
+
test_files:
|
103
|
+
- spec/quick_mem/quick_mem_spec.rb
|
104
|
+
- spec/spec_helper.rb
|