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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -34
  3. data/lib/sheap/version.rb +1 -1
  4. data/lib/sheap.rb +20 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63584faef266eb7722518ee68bbb9cb757786a6aec38779889466b3d215eb542
4
- data.tar.gz: f4979afbb9ce9f1f7ae8aabb58a8b69e7fc86b676c35a451774311a8d6d212d1
3
+ metadata.gz: 84cd499accc73ed5e94564c3703fd2ed19dfb380b1c62cbccb35a207ab670e1e
4
+ data.tar.gz: b44e356f1d76c36b1cd4bb335594765aafafcdf3e21af96b7cecda3bb3617fdb
5
5
  SHA512:
6
- metadata.gz: 5388e77ef86d256762f7388836f6aa2f34837e0a87da9e9fa842156fca972c475b87c506c7310cbde3739343d250bcc11714c875785627fd557da7bd0a7606e7
7
- data.tar.gz: b3696454a64657a42c07c331d659938933417fb611ef5494127d76c9aa4b83ee2ef057c0c0e2d220d8cf27a1b822c9e5300b0a1fee9c1706ab07283335e21175
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 contains a command-line tool and a library for use in IRB.
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 array in the 'after' heap dump
42
- $diff.after.of_type("ARRAY").sort_by { |o| o.data["length"] }.last
43
- # => <ARRAY 0x1023effc8 (10000 refs)>
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
- $diff.after.of_type("ARRAY").sort_by { |o| o.data["length"] }.last.old?
64
+ large_arr.old?
47
65
  # => false
48
66
 
49
- # What else can be learned about it
50
- $diff.after.of_type("ARRAY").sort_by { |o| o.data["length"] }.last.data
51
- # =>
52
- # { "address"=>"0x1023effc8",
53
- # "type"=>"ARRAY",
54
- # "shape_id"=>0,
55
- # "slot_size"=>40,
56
- # "class"=>"0x1024c33f0",
57
- # "length"=>10000,
58
- # "memsize"=>89712,
59
- # "flags"=>{"wb_protected"=>true}
60
- # "references" => [
61
- # <ARRAY 0x1023efc80>,
62
- # <ARRAY 0x1023efc58>,
63
- # <ARRAY 0x1023efc30>,
64
- # <ARRAY 0x1023efc08>,
65
- # <ARRAY 0x1023efbe0>,
66
- # <ARRAY 0x1023efbb8>,
67
- # # ...
68
- # ]
69
- # }
70
-
71
- # Find the first of its references by address
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sheap
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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
- alias count length
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.2.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-02-22 00:00:00.000000000 Z
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: