memory 0.8.3 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b83713d537a03a16799ac6f3cde42daad364061ac4baeadaced28a1ebf3206f
4
- data.tar.gz: cde6c17579def23346ad980303d1d2cb57a7574ca59eec2656ae62ca132ff8d9
3
+ metadata.gz: 535ecdd0c6181d94b31384e4f71b4b4ce52d499d43daa647120fb22cf3dc244b
4
+ data.tar.gz: bfc66be86d65f7065ebc6a4193420ccbe50a98ad5e581ba6cf613484d1846012
5
5
  SHA512:
6
- metadata.gz: c4ded3952cdb38c6f9e0d15e9f98a0da1267da1bd85b9f0810b0d16385fa16246d40925e2ffb58942cd73a20ca7038d1b49d99e6a9b9292d27fe75ec57b0e65e
7
- data.tar.gz: 16eef76d5864170493759bed3c39aec78a4696b5ccd4ba91d2cc8caad13d0578c89e1d2f37dabc9713b21e9ee0a4f6d6a4fceea233cdfefe32ca3c8185bda4c2
6
+ metadata.gz: e2df82be2210853cdc3ede7d47d450d1a38bc14291ee4fdaa3bece83809ce78ffb73ae714d52da9843dbd43d2659e6a97b17005ecbf3abe1f81fe8a687b0cbc5
7
+ data.tar.gz: de6c8972b60a489e7f62834fe926674ed55103fae47a401ef81674b43a8a79b271a8b21051948c56b094a0372abb5493c78739265686b4c4591272ffd70b8f4b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -36,7 +36,7 @@ module Memory
36
36
  end
37
37
 
38
38
  # Sort totals by a given key.
39
- # @parameter key [Symbol] The key to sort by (e.g., :memory or :count).
39
+ # @parameter key [Symbol] The key to sort by (e.g., :size or :count).
40
40
  # @returns [Array] Sorted array of [metric, total] pairs.
41
41
  def totals_by(key)
42
42
  @totals.sort_by{|metric, total| [total[key], metric]}
@@ -50,7 +50,7 @@ module Memory
50
50
  def print(io = $stderr, limit: 10, title: @title, level: 2)
51
51
  io.puts "#{'#' * level} #{title} #{@total}", nil
52
52
 
53
- totals_by(:memory).last(limit).reverse_each do |metric, total|
53
+ totals_by(:size).last(limit).reverse_each do |metric, total|
54
54
  io.puts "- #{total}\t#{metric}"
55
55
  end
56
56
 
data/lib/memory/usage.rb CHANGED
@@ -19,10 +19,17 @@ module Memory
19
19
  attr_accessor :size
20
20
 
21
21
  alias memsize size
22
+ alias memory size
22
23
 
23
24
  # @attribute count [Integer] The total count of the usage in object instances.
24
25
  attr_accessor :count
25
26
 
27
+ # Access usage attributes by key.
28
+ # @parameter key [Symbol] The attribute name (:size, :count, :memory, :memsize).
29
+ def [](key)
30
+ public_send(key)
31
+ end
32
+
26
33
  # Add an allocation to this usage.
27
34
  # @parameter allocation [Allocation] The allocation to add.
28
35
  def << allocation
@@ -32,12 +39,27 @@ module Memory
32
39
  return self
33
40
  end
34
41
 
42
+ IGNORE = [
43
+ # Skip modules and symbols, they are usually "global":
44
+ Module,
45
+ # Note that `reachable_objects_from` does not include symbols, numbers, or other value types, AFAICT.
46
+
47
+ Proc,
48
+ Method,
49
+ UnboundMethod,
50
+ Binding,
51
+ TracePoint,
52
+
53
+ # We don't want to traverse into shared state:
54
+ Ractor,
55
+ Thread,
56
+ Fiber
57
+ ]
58
+
35
59
  # Compute the usage of an object and all reachable objects from it.
36
60
  # @parameter root [Object] The root object to start traversal from.
37
61
  # @returns [Usage] The usage of the object and all reachable objects from it.
38
- def self.of(root)
39
- seen = Set.new.compare_by_identity
40
-
62
+ def self.of(root, seen: Set.new.compare_by_identity, ignore: IGNORE)
41
63
  count = 0
42
64
  size = 0
43
65
 
@@ -45,9 +67,8 @@ module Memory
45
67
  while queue.any?
46
68
  object = queue.shift
47
69
 
48
- # Skip modules and symbols, they are usually "global":
49
- next if object.is_a?(Module)
50
- # Note that `reachable_objects_from` does not include symbols, numbers, or other value types, AFAICT.
70
+ # Skip ignored types:
71
+ next if ignore.any?{|type| object.is_a?(type)}
51
72
 
52
73
  # Skip internal objects - they don't behave correctly when added to `seen` and create unbounded recursion:
53
74
  next if object.is_a?(ObjectSpace::InternalObjectWrapper)
@@ -7,5 +7,5 @@
7
7
  # Copyright, 2020-2025, by Samuel Williams.
8
8
 
9
9
  module Memory
10
- VERSION = "0.8.3"
10
+ VERSION = "0.9.0"
11
11
  end
data/readme.md CHANGED
@@ -94,6 +94,14 @@ end
94
94
 
95
95
  Please see the [project releases](https://socketry.github.io/memory/releases/index) for all releases.
96
96
 
97
+ ### v0.9.0
98
+
99
+ - Explicit `ignore:` and `seen:` parameters for `Memory::Usage.of` to allow customization of ignored types and tracking of seen objects.
100
+
101
+ ### v0.8.4
102
+
103
+ - Fix bugs when printing reports due to interface mismatch with `Memory::Usage`.
104
+
97
105
  ### v0.8.3
98
106
 
99
107
  - Handle `Memory::Usage.of(number)` without error.
data/releases.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Releases
2
2
 
3
+ ## v0.9.0
4
+
5
+ - Explicit `ignore:` and `seen:` parameters for `Memory::Usage.of` to allow customization of ignored types and tracking of seen objects.
6
+
7
+ ## v0.8.4
8
+
9
+ - Fix bugs when printing reports due to interface mismatch with `Memory::Usage`.
10
+
3
11
  ## v0.8.3
4
12
 
5
13
  - Handle `Memory::Usage.of(number)` without error.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -29,7 +29,6 @@ authors:
29
29
  - Olle Jonsson
30
30
  - Vasily Kolesnikov
31
31
  - William Tabi
32
- autorequire:
33
32
  bindir: bin
34
33
  cert_chain:
35
34
  - |
@@ -61,7 +60,7 @@ cert_chain:
61
60
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
62
61
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
63
62
  -----END CERTIFICATE-----
64
- date: 2025-10-29 00:00:00.000000000 Z
63
+ date: 1980-01-02 00:00:00.000000000 Z
65
64
  dependencies:
66
65
  - !ruby/object:Gem::Dependency
67
66
  name: bake
@@ -105,8 +104,6 @@ dependencies:
105
104
  - - ">="
106
105
  - !ruby/object:Gem::Version
107
106
  version: '0'
108
- description:
109
- email:
110
107
  executables: []
111
108
  extensions: []
112
109
  extra_rdoc_files: []
@@ -133,7 +130,6 @@ licenses:
133
130
  metadata:
134
131
  documentation_uri: https://socketry.github.io/memory/
135
132
  source_code_uri: https://github.com/socketry/memory.git
136
- post_install_message:
137
133
  rdoc_options: []
138
134
  require_paths:
139
135
  - lib
@@ -148,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
144
  - !ruby/object:Gem::Version
149
145
  version: '0'
150
146
  requirements: []
151
- rubygems_version: 3.4.19
152
- signing_key:
147
+ rubygems_version: 3.7.2
153
148
  specification_version: 4
154
149
  summary: Memory profiling routines for Ruby 2.3+
155
150
  test_files: []
metadata.gz.sig CHANGED
@@ -1,4 +1,3 @@
1
- G;�
2
- ��d3u(�Q9q�X��
3
- �:�L�@�3\��5K�F����@G�6[�%�g�p��To�y�m�xo��M�}Q��Y5k5�ݚ����H�]_��e��鬁E�\�k�w1s��h!��~0#2��B �P���/ȗ�4��Diw�c�Qj���~��r3y�:���&j��R9M�ޖ�
4
- ��Fx�Z��t_�\])c�}7�j}O��v�ܺ�����|ӈ��\i������dʺ�N� � ��8K���v��9@rC1 1<p�[?R��:^� ��m% ��E*D?J��x؄v�=to�����jٖ,\P�냢�$Ņ�
1
+ R�,դ�J=�o����(��vI9M�&��̾
2
+ DP�`Z�#$�i���yj;��Zk0L82��������ouND�%B�W��U�a�Wiܛ��Cr1�y|�nq7��)���k�>|�6�'i-�X��5�G8\�E��p�ڶ ~�{q���q��ތ����l=��F"�(�0�@���ؓ���q!߅k)m���2���|�[F`�*����C��������[��Cl���]��i����|u`tK����;�x1o�p�
3
+ �񨵶o����c))IZ&�P���`$qhgo