quick_mem 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -0
- data/README.md +11 -1
- data/Rakefile +2 -2
- data/lib/quick_mem/dumps.rb +31 -0
- data/lib/quick_mem/gc_constants.rb +2 -2
- data/lib/quick_mem/memory_stats.rb +52 -0
- data/lib/quick_mem/summary.rb +48 -0
- data/lib/quick_mem/version.rb +1 -1
- data/lib/quick_mem.rb +19 -21
- data/quick_mem.gemspec +4 -2
- data/quick_mem.txt +4 -7
- data/spec/quick_mem/dumps_spec.rb +42 -0
- data/spec/quick_mem/{quick_mem_spec.rb → memory_stats_spec.rb} +34 -33
- data/spec/quick_mem/summary_spec.rb +47 -0
- data/spec/quick_mem_spec.rb +144 -0
- data/spec/spec_helper.rb +2 -1
- data/tasks/quality.rake +7 -0
- data/tasks/rspec.rake +1 -1
- metadata +42 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38b11f923b2dd55da18d9352b115c3c2f74fd8ed
|
4
|
+
data.tar.gz: e4b0602e20304f1e11812479cd4281834b85098d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6fec4d70b0c0c82efcc9818e295482d0909f6506aba31c9276fa22069ab5e2c01303979bd08737ae66765f2e11fa0991b78720780fa75b07394243c5fa4430d
|
7
|
+
data.tar.gz: d07737fe03b174664c213fd6980c30e92c8162ee0ef1f57a369cd5d6d9f2791f65a4254c28d2d2dc543256246a8d797069038f5c512f4cf28c6bdbe2830be2d0
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-03-30 13:26:25 +0530 using RuboCop version 0.29.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
Excludes:
|
10
|
+
- quick_mem.gemspec
|
11
|
+
- pkg/**
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/EmptyLinesAroundClassBody:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/NumericLiterals:
|
20
|
+
MinDigits: 10
|
21
|
+
|
22
|
+
Metrics/LineLength:
|
23
|
+
Max: 100
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 20
|
data/README.md
CHANGED
@@ -27,7 +27,17 @@ Or install it yourself as:
|
|
27
27
|
```ruby
|
28
28
|
require 'quick_mem'
|
29
29
|
|
30
|
-
|
30
|
+
# show memory stats (more-or-less raw form)
|
31
|
+
QuickMem::QuickMemory.show_stats
|
32
|
+
|
33
|
+
# show memory summary (heap total,used,free mem in MB and percentage)
|
34
|
+
QuickMem::QuickMemory.show_summary
|
35
|
+
|
36
|
+
# view top 50 objects by descending order of size
|
37
|
+
QuickMem::QuickMemory.view_objects_by_size
|
38
|
+
|
39
|
+
# view top 50 objects by descending order of instance count
|
40
|
+
QuickMem::QuickMemory.view_objects_by_count
|
31
41
|
```
|
32
42
|
|
33
43
|
## Contributing
|
data/Rakefile
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'objspace'
|
2
|
+
|
3
|
+
module QuickMem
|
4
|
+
class Dumps
|
5
|
+
|
6
|
+
def self.top_allocated_objects
|
7
|
+
objects_by_size = Hash.new { 0 }
|
8
|
+
ObjectSpace.each_object do |obj|
|
9
|
+
objects_by_size[obj.class] += ObjectSpace.memsize_of(obj)
|
10
|
+
end
|
11
|
+
get_top_50(objects_by_size)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.count_top_allocated_objects
|
15
|
+
objects_by_count = Hash.new { 0 }
|
16
|
+
ObjectSpace.each_object do |obj|
|
17
|
+
objects_by_count[obj.class] += 1
|
18
|
+
end
|
19
|
+
get_top_50(objects_by_count)
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
private
|
24
|
+
|
25
|
+
def get_top_50(a_hash)
|
26
|
+
a_hash.sort_by(&:last).reverse![0..49].to_h
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -2,11 +2,11 @@ module QuickMem
|
|
2
2
|
class GCConstants
|
3
3
|
|
4
4
|
def self.slot_size
|
5
|
-
|
5
|
+
@rvalue_size ||= GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.slots_per_page
|
9
|
-
|
9
|
+
@heap_obj_limit ||= GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT]
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'quick_mem/gc_constants'
|
2
|
+
|
3
|
+
module QuickMem
|
4
|
+
class MemoryStats
|
5
|
+
|
6
|
+
def self.show
|
7
|
+
raw_data = GC.stat
|
8
|
+
stats = {}
|
9
|
+
gc_counts(stats, raw_data)
|
10
|
+
heap_statistics(stats, raw_data)
|
11
|
+
stats
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
private
|
16
|
+
|
17
|
+
def heap_statistics(stats, raw_data)
|
18
|
+
stats[:heap_reserved] = raw_data[:heap_length] * page_size
|
19
|
+
stats[:heap_allocated] = total_slots(raw_data) * slot_size
|
20
|
+
stats[:heap_used] = used_slots(raw_data) * slot_size
|
21
|
+
stats[:heap_free] = raw_data[:heap_free_slot] * slot_size
|
22
|
+
end
|
23
|
+
|
24
|
+
def gc_counts(stats, raw_data)
|
25
|
+
stats[:major_gc_count] = raw_data[:major_gc_count]
|
26
|
+
stats[:minor_gc_count] = raw_data[:minor_gc_count]
|
27
|
+
stats[:total_gc_count] = raw_data[:count]
|
28
|
+
end
|
29
|
+
|
30
|
+
def total_slots(raw_data)
|
31
|
+
used_slots(raw_data) + raw_data[:heap_free_slot]
|
32
|
+
end
|
33
|
+
|
34
|
+
def used_slots(raw_data)
|
35
|
+
raw_data[:heap_live_slot] + raw_data[:heap_final_slot]
|
36
|
+
end
|
37
|
+
|
38
|
+
def page_size
|
39
|
+
slot_size * slots_per_page
|
40
|
+
end
|
41
|
+
|
42
|
+
def slot_size
|
43
|
+
QuickMem::GCConstants.slot_size
|
44
|
+
end
|
45
|
+
|
46
|
+
def slots_per_page
|
47
|
+
QuickMem::GCConstants.slots_per_page
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'quick_mem/gc_constants'
|
2
|
+
|
3
|
+
module QuickMem
|
4
|
+
class Summary
|
5
|
+
|
6
|
+
NUMBER_FORMAT = '%.2f'
|
7
|
+
|
8
|
+
def initialize(raw_data)
|
9
|
+
@summary = {}
|
10
|
+
@stats = raw_data
|
11
|
+
calculate_heap_summary
|
12
|
+
calculate_percentage_used
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
summary
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def calculate_heap_summary
|
22
|
+
summary[:heap_reserved] = pretty_bytes_to_megabytes(stats[:heap_reserved])
|
23
|
+
summary[:heap_allocated] = pretty_bytes_to_megabytes(stats[:heap_allocated])
|
24
|
+
summary[:heap_used] = pretty_bytes_to_megabytes(stats[:heap_used])
|
25
|
+
summary[:heap_free] = pretty_bytes_to_megabytes(stats[:heap_free])
|
26
|
+
end
|
27
|
+
|
28
|
+
def calculate_percentage_used
|
29
|
+
summary[:heap_used_pct] = percentage_of(stats[:heap_used], stats[:heap_allocated])
|
30
|
+
summary[:heap_free_pct] = percentage_of(stats[:heap_free], stats[:heap_allocated])
|
31
|
+
end
|
32
|
+
|
33
|
+
def pretty_bytes_to_megabytes(bytes)
|
34
|
+
NUMBER_FORMAT % bytes_to_megabytes(bytes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def percentage_of(size, total)
|
38
|
+
NUMBER_FORMAT % ((bytes_to_megabytes(size) / bytes_to_megabytes(total)) * 100.00)
|
39
|
+
end
|
40
|
+
|
41
|
+
def bytes_to_megabytes(bytes)
|
42
|
+
bytes / (1024.0 * 1024.0)
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :summary, :stats
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/quick_mem/version.rb
CHANGED
data/lib/quick_mem.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'quick_mem/
|
2
|
-
require 'quick_mem/
|
1
|
+
require 'quick_mem/memory_stats'
|
2
|
+
require 'quick_mem/summary'
|
3
|
+
require 'quick_mem/dumps'
|
3
4
|
|
4
5
|
module QuickMem
|
5
6
|
class QuickMemory
|
@@ -8,33 +9,30 @@ module QuickMem
|
|
8
9
|
QuickMem::VERSION
|
9
10
|
end
|
10
11
|
|
11
|
-
def self.
|
12
|
-
|
13
|
-
config = Hash.new
|
14
|
-
gc_counts(config, gc_stat)
|
15
|
-
heap_statistics(config, gc_stat)
|
16
|
-
config
|
12
|
+
def self.show_stats
|
13
|
+
add_meta_info(QuickMem::MemoryStats.show)
|
17
14
|
end
|
18
15
|
|
19
|
-
|
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
|
16
|
+
def self.show_summary
|
17
|
+
add_meta_info(QuickMem::Summary.new(show_stats).show)
|
24
18
|
end
|
25
19
|
|
26
|
-
def self.
|
27
|
-
|
28
|
-
config[:minor_gc_count] = gc_stat[:minor_gc_count]
|
29
|
-
config[:total_gc_count] = gc_stat[:count]
|
20
|
+
def self.view_objects_by_size
|
21
|
+
add_meta_info(objects_by_size: QuickMem::Dumps.top_allocated_objects)
|
30
22
|
end
|
31
23
|
|
32
|
-
def self.
|
33
|
-
QuickMem::
|
24
|
+
def self.view_objects_by_count
|
25
|
+
add_meta_info(objects_by_count: QuickMem::Dumps.count_top_allocated_objects)
|
34
26
|
end
|
35
27
|
|
36
|
-
|
37
|
-
|
28
|
+
class << self
|
29
|
+
private
|
30
|
+
|
31
|
+
def add_meta_info(a_hash)
|
32
|
+
a_hash[:version] = version
|
33
|
+
a_hash[:timestamp] = Time.now.strftime('%d/%m/%Y %H:%M:%S')
|
34
|
+
a_hash
|
35
|
+
end
|
38
36
|
end
|
39
37
|
|
40
38
|
end
|
data/quick_mem.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = QuickMem::VERSION
|
9
9
|
spec.authors = ["Rajiv Nair"]
|
10
10
|
spec.email = ["rajivrnair@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = 'Quickly look at GC stats'
|
12
|
+
spec.description = 'A simple gem to dump memory stats'
|
13
13
|
spec.homepage = "https://github.com/rajivrnair/quick_mem"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.post_install_message = "Live long and prosper!" # \\//,
|
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
25
|
spec.add_development_dependency 'rspec', '~>3.1.0'
|
26
|
+
spec.add_development_dependency 'rubocop', '~>0.29.1'
|
27
|
+
spec.add_development_dependency 'english', '~> 0.6.3'
|
26
28
|
end
|
27
29
|
|
28
30
|
# group :test do
|
data/quick_mem.txt
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
Total Heap size/ Heap size used / % used / % free
|
2
|
-
Total number of objects
|
3
|
-
Total Allocated slots / slots used
|
4
|
-
|
5
1
|
RUBY_GC_MALLOC_LIMIT
|
6
2
|
RUBY_GC_HEAP_INIT_SLOTS
|
7
3
|
RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR
|
@@ -19,11 +15,12 @@ ObjectSpace.allocated_objects
|
|
19
15
|
|
20
16
|
slot_size: GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
|
21
17
|
slots_per_page: GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT]
|
18
|
+
page_size = slots_per_page * slot_size
|
22
19
|
|
23
20
|
GC.stat[:heap_length] - total pages allocated.
|
24
21
|
GC.stat[:heap_used] - total pages used.
|
25
22
|
GC.stat[:heap_increment]
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
todo:
|
25
|
+
- stats snapshots to text files.
|
26
|
+
- graph to plot memory usage.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'quick_mem/dumps'
|
3
|
+
|
4
|
+
module QuickMem
|
5
|
+
describe Dumps do
|
6
|
+
describe '#top_allocated_objects' do
|
7
|
+
subject { Dumps.top_allocated_objects }
|
8
|
+
|
9
|
+
it 'returns a hash' do
|
10
|
+
expect(subject).to be_a Hash
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'has no more than fifty entries' do
|
14
|
+
expect(subject.size).to be <= 50
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is sorted in descending order of size' do
|
18
|
+
# Can't think of an easier way to do this :(
|
19
|
+
expected_result = subject.values.sort.reverse
|
20
|
+
expect(subject.values).to eql(expected_result)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#count_top_allocated_objects' do
|
25
|
+
subject { Dumps.count_top_allocated_objects }
|
26
|
+
|
27
|
+
it 'returns a hash' do
|
28
|
+
expect(subject).to be_a Hash
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'has no more than fifty entries' do
|
32
|
+
expect(subject.size).to be <= 50
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is sorted in descending order of object count' do
|
36
|
+
# Can't think of an easier way to do this :(
|
37
|
+
expected_result = subject.values.sort.reverse
|
38
|
+
expect(subject.values).to eql(expected_result)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,55 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'quick_mem'
|
4
|
-
|
5
3
|
module QuickMem
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
9
|
-
subject { QuickMemory.version }
|
10
|
-
|
11
|
-
it 'outputs the correct version number' do
|
12
|
-
expect(subject).to eq '0.0.3'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#show_config' do
|
17
|
-
subject { QuickMemory.show_config }
|
18
|
-
let(:mem_options) {
|
4
|
+
describe MemoryStats do
|
5
|
+
describe '#show' do
|
6
|
+
let(:mem_stats) do
|
19
7
|
{
|
20
8
|
count: 22,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
heap_increment: 0,
|
9
|
+
major_gc_count: 4,
|
10
|
+
minor_gc_count: 18,
|
11
|
+
|
25
12
|
heap_length: 237,
|
13
|
+
heap_used: 226,
|
14
|
+
heap_eden_page_length: 220,
|
15
|
+
heap_tomb_page_length: 6,
|
16
|
+
|
17
|
+
heap_final_slot: 21,
|
18
|
+
heap_free_slot: 829,
|
26
19
|
heap_live_slot: 91292,
|
27
20
|
heap_swept_slot: 22651,
|
28
|
-
|
29
|
-
|
30
|
-
major_gc_count: 4,
|
21
|
+
heap_increment: 0,
|
22
|
+
|
31
23
|
malloc_increase: 545344,
|
32
24
|
malloc_limit: 16777216,
|
33
|
-
minor_gc_count: 18,
|
34
|
-
old_object: 54719,
|
35
|
-
old_object_limit: 56776,
|
36
25
|
oldmalloc_increase: 6406440,
|
37
26
|
oldmalloc_limit: 16777216,
|
27
|
+
|
28
|
+
old_object: 54719,
|
29
|
+
old_object_limit: 56776,
|
30
|
+
|
38
31
|
remembered_shady_object: 811,
|
39
32
|
remembered_shady_object_limit: 758,
|
33
|
+
|
40
34
|
total_allocated_object: 524356,
|
41
35
|
total_freed_object: 433064
|
42
36
|
}
|
43
|
-
|
37
|
+
end
|
44
38
|
|
45
39
|
before do
|
46
40
|
# assuming default values for
|
47
41
|
# GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] = 40
|
48
42
|
# GC::INTERNAL_CONSTANTS[:HEAP_OBJ_LIMIT] = 408
|
49
|
-
|
50
|
-
allow(GC).to receive(:stat) { mem_options }
|
43
|
+
allow(GC).to receive(:stat) { mem_stats }
|
51
44
|
end
|
52
45
|
|
46
|
+
subject { MemoryStats.show }
|
47
|
+
|
53
48
|
it 'spits out the number of major GCs' do
|
54
49
|
expect(subject[:major_gc_count]).to eq(4)
|
55
50
|
end
|
@@ -62,15 +57,21 @@ module QuickMem
|
|
62
57
|
expect(subject[:total_gc_count]).to eq(22)
|
63
58
|
end
|
64
59
|
|
65
|
-
it 'spits out the
|
66
|
-
expect(subject[:
|
60
|
+
it 'spits out the max reserved heap in bytes' do
|
61
|
+
expect(subject[:heap_reserved]).to eq(3867840)
|
67
62
|
end
|
68
63
|
|
69
|
-
it 'spits out the heap
|
70
|
-
expect(subject[:
|
64
|
+
it 'spits out the allocated heap in bytes' do
|
65
|
+
expect(subject[:heap_allocated]).to eq(3685680)
|
71
66
|
end
|
72
67
|
|
73
|
-
|
68
|
+
it 'spits out the heap currently used in bytes' do
|
69
|
+
expect(subject[:heap_used]).to eq(3652520)
|
70
|
+
end
|
74
71
|
|
72
|
+
it 'spits out the heap free in bytes' do
|
73
|
+
expect(subject[:heap_free]).to eq(33160)
|
74
|
+
end
|
75
|
+
end
|
75
76
|
end
|
76
77
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'quick_mem/summary'
|
3
|
+
|
4
|
+
module QuickMem
|
5
|
+
describe Summary do
|
6
|
+
describe '#show' do
|
7
|
+
let(:mem_stats) do
|
8
|
+
{
|
9
|
+
heap_reserved: 204000000,
|
10
|
+
heap_allocated: 40800000,
|
11
|
+
heap_used: 32640000,
|
12
|
+
heap_free: 8160000
|
13
|
+
}
|
14
|
+
end
|
15
|
+
subject { Summary.new(mem_stats).show }
|
16
|
+
|
17
|
+
it 'returns a summary of the memory usage' do
|
18
|
+
expect(subject).to be_a Hash
|
19
|
+
expect(subject).not_to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'displays the total memory reserved by the rvm in mb' do
|
23
|
+
expect(subject[:heap_reserved]).to eql('194.55')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'displays the memory currently allocated in mb' do
|
27
|
+
expect(subject[:heap_allocated]).to eql('38.91')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'displays the memory currently used in mb' do
|
31
|
+
expect(subject[:heap_used]).to eql('31.13')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'displays the memory currently used as a percentage of allocated memory' do
|
35
|
+
expect(subject[:heap_used_pct]).to eql('80.00')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'displays the memory currently free in mb' do
|
39
|
+
expect(subject[:heap_free]).to eql('7.78')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'displays the memory currently free as a percentage of allocated memory' do
|
43
|
+
expect(subject[:heap_free_pct]).to eql('20.00')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'quick_mem'
|
4
|
+
|
5
|
+
module QuickMem
|
6
|
+
describe QuickMemory do
|
7
|
+
let(:version) { '0.0.4' }
|
8
|
+
let(:time_now) { double('time') }
|
9
|
+
let(:timestamp) { '30/03/2015 23:28:47' }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(Time).to receive(:now) { time_now }
|
13
|
+
allow(time_now).to receive(:strftime) { timestamp }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#version' do
|
17
|
+
subject { QuickMemory.version }
|
18
|
+
|
19
|
+
it 'outputs the correct version number' do
|
20
|
+
expect(subject).to eq version
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#show_stats' do
|
25
|
+
subject { QuickMemory.show_stats }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow(QuickMem::MemoryStats).to receive(:show) do
|
29
|
+
{ total_gc_count: 20 }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns a hash' do
|
34
|
+
expect(subject).to be_a Hash
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is not empty' do
|
38
|
+
expect(subject).not_to be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'contains statistics about the current memory usage' do
|
42
|
+
expect(subject[:total_gc_count]).to eql(20)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'contains the version' do
|
46
|
+
expect(subject[:version]).to eq version
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'contains the timestamp' do
|
50
|
+
expect(subject[:timestamp]).to eq timestamp
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#show_summary' do
|
55
|
+
subject { QuickMemory.show_summary }
|
56
|
+
let(:summary) { double('summary') }
|
57
|
+
|
58
|
+
before do
|
59
|
+
allow(QuickMem::Summary).to receive(:new) { summary }
|
60
|
+
allow(summary).to receive(:show) { { heap_used_pct: '50.55' } }
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns a hash' do
|
64
|
+
expect(subject).to be_a Hash
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'is not empty' do
|
68
|
+
expect(subject).not_to be_empty
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'contains a summary about the current memory usage' do
|
72
|
+
expect(subject[:heap_used_pct]).to eql('50.55')
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'contains the version' do
|
76
|
+
expect(subject[:version]).to eq version
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'contains the timestamp' do
|
80
|
+
expect(subject[:timestamp]).to eq timestamp
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#view_objects_by_size' do
|
85
|
+
subject { QuickMemory.view_objects_by_size }
|
86
|
+
|
87
|
+
before do
|
88
|
+
allow(QuickMem::Dumps).to receive(:top_allocated_objects) do
|
89
|
+
{ Thread: 1049960, String: 2688465, Class: 976088 }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns a hash' do
|
94
|
+
expect(subject).to be_a Hash
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'is not empty' do
|
98
|
+
expect(subject).not_to be_empty
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'contains a map of classes to total size of all instances' do
|
102
|
+
expect(subject[:objects_by_size]).to eql(String: 2688465, Thread: 1049960, Class: 976088)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'contains the version' do
|
106
|
+
expect(subject[:version]).to eq version
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'contains the timestamp' do
|
110
|
+
expect(subject[:timestamp]).to eq timestamp
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#view_objects_by_count' do
|
115
|
+
subject { QuickMemory.view_objects_by_count }
|
116
|
+
|
117
|
+
before do
|
118
|
+
allow(QuickMem::Dumps).to receive(:count_top_allocated_objects) do
|
119
|
+
{ Thread: 104, String: 268, Class: 97 }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'returns a hash' do
|
124
|
+
expect(subject).to be_a Hash
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'is not empty' do
|
128
|
+
expect(subject).not_to be_empty
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'contains a map of classes to instance count' do
|
132
|
+
expect(subject[:objects_by_count]).to eql(String: 268, Thread: 104, Class: 97)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'contains the version' do
|
136
|
+
expect(subject[:version]).to eq version
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'contains the timestamp' do
|
140
|
+
expect(subject[:timestamp]).to eq timestamp
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/tasks/quality.rake
ADDED
data/tasks/rspec.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_mem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajiv Nair
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.29.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.29.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: english
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.3
|
55
83
|
description: A simple gem to dump memory stats
|
56
84
|
email:
|
57
85
|
- rajivrnair@gmail.com
|
@@ -61,19 +89,27 @@ extra_rdoc_files: []
|
|
61
89
|
files:
|
62
90
|
- ".gitignore"
|
63
91
|
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
64
93
|
- ".ruby_version"
|
65
94
|
- Gemfile
|
66
95
|
- LICENSE.txt
|
67
96
|
- README.md
|
68
97
|
- Rakefile
|
69
98
|
- lib/quick_mem.rb
|
99
|
+
- lib/quick_mem/dumps.rb
|
70
100
|
- lib/quick_mem/gc_constants.rb
|
101
|
+
- lib/quick_mem/memory_stats.rb
|
102
|
+
- lib/quick_mem/summary.rb
|
71
103
|
- lib/quick_mem/version.rb
|
72
104
|
- quick_mem.gemspec
|
73
105
|
- quick_mem.sublime-project
|
74
106
|
- quick_mem.txt
|
75
|
-
- spec/quick_mem/
|
107
|
+
- spec/quick_mem/dumps_spec.rb
|
108
|
+
- spec/quick_mem/memory_stats_spec.rb
|
109
|
+
- spec/quick_mem/summary_spec.rb
|
110
|
+
- spec/quick_mem_spec.rb
|
76
111
|
- spec/spec_helper.rb
|
112
|
+
- tasks/quality.rake
|
77
113
|
- tasks/rspec.rake
|
78
114
|
homepage: https://github.com/rajivrnair/quick_mem
|
79
115
|
licenses:
|
@@ -100,5 +136,8 @@ signing_key:
|
|
100
136
|
specification_version: 4
|
101
137
|
summary: Quickly look at GC stats
|
102
138
|
test_files:
|
103
|
-
- spec/quick_mem/
|
139
|
+
- spec/quick_mem/dumps_spec.rb
|
140
|
+
- spec/quick_mem/memory_stats_spec.rb
|
141
|
+
- spec/quick_mem/summary_spec.rb
|
142
|
+
- spec/quick_mem_spec.rb
|
104
143
|
- spec/spec_helper.rb
|