sheap 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +46 -34
- data/lib/sheap/version.rb +1 -1
- data/lib/sheap.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84cd499accc73ed5e94564c3703fd2ed19dfb380b1c62cbccb35a207ab670e1e
|
4
|
+
data.tar.gz: b44e356f1d76c36b1cd4bb335594765aafafcdf3e21af96b7cecda3bb3617fdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69fdf739e7088d998f3968024f2fe2b086ba79d2a4707f3dc924a87a079f40c2b89958647ef92fafa8f7a9f513377bae229c715178071a2c19c30384c81374ec
|
7
|
+
data.tar.gz: 6b29e443a217dab6b283c9026b85c1ac358fca2c8653926774cb7356eff8693e61652c1d4bad1032539c9cb0e37fba56b2dc3267d334a38c6105d2bcb8bde69f
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Sheap
|
2
2
|
|
3
|
-
Sheap is a library for interactively exploring Ruby Heap dumps. Sheap contains
|
3
|
+
Sheap is a library for interactively exploring Ruby Heap dumps. Sheap contains a command-line tool and a library for use in IRB.
|
4
4
|
|
5
5
|
Some examples of things you can do with Sheap:
|
6
6
|
- Find all retained objects between two heap dumps, and analyze them by their properties
|
@@ -38,43 +38,55 @@ $diff = Sheap::Diff.new('tmp/heap_before.dump', 'tmp/heap_after.dump')
|
|
38
38
|
$diff.retained.map(&:type_str).tally.sort_by(&:last)
|
39
39
|
# => [["DATA", 1], ["FILE", 1], ["IMEMO", 4], ["STRING", 4], ["ARRAY", 10000]]
|
40
40
|
|
41
|
-
# Find the largest
|
42
|
-
$diff.after.
|
43
|
-
# =>
|
41
|
+
# Find the 4 largest arrays in the 'after' heap dump
|
42
|
+
>> $diff.after.arrays.sort_by(&:length).last(5)
|
43
|
+
# =>
|
44
|
+
# [#<ARRAY 0x100ec0440 (512 refs)>,
|
45
|
+
# #<ARRAY 0x100ec9270 (512 refs)>,
|
46
|
+
# #<ARRAY 0x100f4b450 (512 refs)>,
|
47
|
+
# #<ARRAY 0x11bc6d5b0 (512 refs)>,
|
48
|
+
# #<ARRAY 0x11c137960 (10000 refs)>]
|
49
|
+
|
50
|
+
# Grab and examine just the largest array
|
51
|
+
large_arr = $diff.after.arrays.max_by(&:length)
|
52
|
+
# =>
|
53
|
+
# #<ARRAY 0x1023effc8
|
54
|
+
# type="ARRAY",
|
55
|
+
# shape_id=0,
|
56
|
+
# slot_size=40,
|
57
|
+
# class=#<CLASS 0x100e43350 Array (252 refs)>,
|
58
|
+
# length=10000,
|
59
|
+
# references=(10000 refs),
|
60
|
+
# memsize=89712,
|
61
|
+
# flags=wb_protected>
|
44
62
|
|
45
63
|
# Is it old?
|
46
|
-
|
64
|
+
large_arr.old?
|
47
65
|
# => false
|
48
66
|
|
49
|
-
#
|
50
|
-
|
51
|
-
# =>
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
|
62
|
-
#
|
63
|
-
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
|
69
|
-
#
|
70
|
-
|
71
|
-
#
|
72
|
-
$diff.after.at("0x1023efc80")
|
73
|
-
=> <ARRAY 0x1023efc80>
|
74
|
-
|
75
|
-
# Show that object's path back to the root of the heap
|
76
|
-
$diff.after.find_path($diff.after.at("0x1023efc80"))
|
77
|
-
# => [<ROOT global_tbl (13 refs)>, <ARRAY 0x1023effc8 (10000 refs)>, <ARRAY 0x1023efc80>]
|
67
|
+
# Find the first of its references
|
68
|
+
large_arr.references.first
|
69
|
+
# =>
|
70
|
+
# #<ARRAY 0x11c13fdb8
|
71
|
+
# type="ARRAY",
|
72
|
+
# shape_id=0,
|
73
|
+
# slot_size=40,
|
74
|
+
# class=#<CLASS 0x100e43350 Array (252 refs)>,
|
75
|
+
# length=0,
|
76
|
+
# embedded=true,
|
77
|
+
# memsize=40,
|
78
|
+
# flags=wb_protected>
|
79
|
+
|
80
|
+
# Reference that same object by address
|
81
|
+
$diff.after.at("0x11c13fdb8")
|
82
|
+
# =>
|
83
|
+
# #<ARRAY 0x11c13fdb8
|
84
|
+
# type="ARRAY",
|
85
|
+
# ...
|
86
|
+
|
87
|
+
# Show that object's path back to the root of the heap
|
88
|
+
$diff.after.find_path($diff.after.at("0x11c13fdb8"))
|
89
|
+
# => [#<ROOT global_tbl (13 refs)>, #<ARRAY 0x1023effc8 (10000 refs)>, #<ARRAY 0x11c13fdb8>]
|
78
90
|
```
|
79
91
|
|
80
92
|
### Generating heap dumps
|
data/lib/sheap/version.rb
CHANGED
data/lib/sheap.rb
CHANGED
@@ -37,6 +37,11 @@ class Sheap
|
|
37
37
|
filter { |o| o.json.include?(type) && o.type_str == type }
|
38
38
|
end
|
39
39
|
|
40
|
+
def of_imemo_type(type)
|
41
|
+
type = type.to_s.downcase
|
42
|
+
filter { |o| o.json.include?(type) && o.imemo_type == type }
|
43
|
+
end
|
44
|
+
|
40
45
|
def classes; of_type("CLASS"); end
|
41
46
|
def icasses; of_type("ICLASS"); end
|
42
47
|
def modules; of_type("MODULE"); end
|
@@ -59,6 +64,14 @@ class Sheap
|
|
59
64
|
def floats; of_type("FLOAT"); end
|
60
65
|
def rationals; of_type("RATIONAL"); end
|
61
66
|
def complexes; of_type("COMPLEX"); end
|
67
|
+
|
68
|
+
# imemo types
|
69
|
+
def iseqs; of_imemo_type("iseq"); end
|
70
|
+
def callcaches; of_imemo_type("callcache"); end
|
71
|
+
def constcaches; of_imemo_type("constcache"); end
|
72
|
+
def callinfos; of_imemo_type("callinfo"); end
|
73
|
+
def crefs; of_imemo_type("cref"); end
|
74
|
+
def ments; of_imemo_type("ment"); end
|
62
75
|
end
|
63
76
|
|
64
77
|
class Diff
|
@@ -142,6 +155,10 @@ class Sheap
|
|
142
155
|
end
|
143
156
|
end
|
144
157
|
|
158
|
+
def [](*args)
|
159
|
+
@objects[*args]
|
160
|
+
end
|
161
|
+
|
145
162
|
def last(n = nil)
|
146
163
|
if n
|
147
164
|
HeapObjectCollection.new(@objects.last(n))
|
@@ -158,7 +175,9 @@ class Sheap
|
|
158
175
|
@objects.length
|
159
176
|
end
|
160
177
|
alias size length
|
161
|
-
|
178
|
+
def count(&block)
|
179
|
+
@objects.count(&block)
|
180
|
+
end
|
162
181
|
|
163
182
|
def pretty_print(q)
|
164
183
|
q.group(1, '[', ']') {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A set of helpers for analyzing the output of ObjectSpace.dump_all
|
14
14
|
email:
|