memory 0.6.1 → 0.7.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
- checksums.yaml.gz.sig +2 -2
- data/bake/memory/report.rb +2 -2
- data/bake/memory/sampler.rb +4 -4
- data/lib/memory/report.rb +11 -11
- data/lib/memory/sampler.rb +76 -60
- data/lib/memory/version.rb +2 -2
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 266bdfec74c35392a9c086c366df9bb6ab4fb5e1b162b98d3757f690fff09ded
|
4
|
+
data.tar.gz: dffe8472314144b5786b5c445c6e01973114e9c3915d08aae0352fc1be76d329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dcf3e65b4a7dee68b55919dc44004149a6febe80fde00d539d2b0361eea62dd47ab742006ef7ed75a2980829f0f58cbf1c341098ae394ac4ac3b7a4d816752b
|
7
|
+
data.tar.gz: '038621f8d88603eb8b0b2a89fe13e4007bc100ce0c16c53febd9d02a6cf4fa3a00c6c3e967bfa8a6aa6507e3611266cae774dc016d330fe5b22d5322beee12e3'
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
=��z�6�r��g9��j�V�,��$�$0�����SP��.��?�Yb
|
2
|
+
�F�$��}����rM�|H�n���U�̮�T��q��`�i0� q��zA=b:���@)��������3�;p������-N�����6.$Zc��] �d���O�{@"���M���?���SWQ�-�
|
data/bake/memory/report.rb
CHANGED
data/bake/memory/sampler.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
def initialize(...)
|
7
7
|
super
|
8
8
|
|
9
|
-
require_relative
|
9
|
+
require_relative "../../lib/memory"
|
10
10
|
end
|
11
11
|
|
12
12
|
# Load a sampler from one or more .mprof files.
|
@@ -27,7 +27,7 @@ def load(paths:)
|
|
27
27
|
paths.each do |path|
|
28
28
|
Console.logger.info(sampler, "Loading #{path}, #{Memory.formatted_bytes File.size(path)}")
|
29
29
|
|
30
|
-
File.open(path,
|
30
|
+
File.open(path, "r", encoding: Encoding::BINARY) do |io|
|
31
31
|
unpacker = wrapper.unpacker(io)
|
32
32
|
count = unpacker.read_array_header
|
33
33
|
|
@@ -56,7 +56,7 @@ end
|
|
56
56
|
# @parameter output [String] Path to write the .mprof file.
|
57
57
|
# @returns [Memory::Sampler] The input sampler.
|
58
58
|
def dump(path, input:)
|
59
|
-
File.open(path,
|
59
|
+
File.open(path, "w", encoding: Encoding::BINARY) do |io|
|
60
60
|
input.dump(io)
|
61
61
|
end
|
62
62
|
|
@@ -76,7 +76,7 @@ def load_object_space_dump(path)
|
|
76
76
|
Console.logger.info(self, "Loading heap dump from #{path} (#{Memory.formatted_bytes(file_size)})")
|
77
77
|
|
78
78
|
sampler = nil
|
79
|
-
File.open(path,
|
79
|
+
File.open(path, "r") do |io|
|
80
80
|
sampler = Memory::Sampler.load_object_space_dump(io) do |line_count, object_count|
|
81
81
|
# Update progress based on bytes read:
|
82
82
|
progress.increment(io.pos - progress.current)
|
data/lib/memory/report.rb
CHANGED
@@ -90,16 +90,16 @@ module Memory
|
|
90
90
|
}
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
93
|
+
# Convert this report to a JSON string.
|
94
|
+
# @returns [String] JSON representation of this report.
|
95
|
+
def to_json(...)
|
96
|
+
as_json.to_json(...)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Generate a human-readable representation of this report.
|
100
|
+
# @returns [String] Summary showing allocated and retained totals.
|
101
|
+
def inspect
|
102
|
+
"#<#{self.class}: #{@total_allocated} allocated, #{@total_retained} retained>"
|
103
|
+
end
|
103
104
|
end
|
104
105
|
end
|
105
|
-
end
|
data/lib/memory/sampler.rb
CHANGED
@@ -66,72 +66,72 @@ module Memory
|
|
66
66
|
# end
|
67
67
|
# ~~~
|
68
68
|
class Sampler
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
line_count = 0
|
81
|
-
object_count = 0
|
82
|
-
report_interval = 10000
|
83
|
-
|
84
|
-
io.each_line do |line|
|
85
|
-
line_count += 1
|
86
|
-
|
87
|
-
begin
|
88
|
-
object = JSON.parse(line)
|
89
|
-
rescue JSON::ParserError
|
90
|
-
# Skip invalid JSON lines
|
91
|
-
next
|
92
|
-
end
|
93
|
-
|
94
|
-
# Skip non-object entries (ROOT, SHAPE, etc.)
|
95
|
-
next unless object['address']
|
69
|
+
# Load allocations from an ObjectSpace heap dump.
|
70
|
+
#
|
71
|
+
# If a block is given, it will be called periodically with progress information.
|
72
|
+
#
|
73
|
+
# @parameter io [IO] The IO stream containing the heap dump JSON.
|
74
|
+
# @yields [line_count, object_count] Progress callback with current line and object counts.
|
75
|
+
# @returns [Sampler] A new sampler populated with allocations from the heap dump.
|
76
|
+
def self.load_object_space_dump(io, &block)
|
77
|
+
sampler = new
|
78
|
+
cache = sampler.cache
|
96
79
|
|
97
|
-
|
98
|
-
|
99
|
-
|
80
|
+
line_count = 0
|
81
|
+
object_count = 0
|
82
|
+
report_interval = 10000
|
100
83
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
84
|
+
io.each_line do |line|
|
85
|
+
line_count += 1
|
86
|
+
|
87
|
+
begin
|
88
|
+
object = JSON.parse(line)
|
89
|
+
rescue JSON::ParserError
|
90
|
+
# Skip invalid JSON lines
|
91
|
+
next
|
92
|
+
end
|
93
|
+
|
94
|
+
# Skip non-object entries (ROOT, SHAPE, etc.)
|
95
|
+
next unless object["address"]
|
96
|
+
|
97
|
+
# Get allocation information (may be nil if tracing wasn't enabled)
|
98
|
+
file = object["file"] || "(unknown)"
|
99
|
+
line_number = object["line"] || 0
|
100
|
+
|
101
|
+
# Get object type/class
|
102
|
+
type = object["type"] || "unknown"
|
103
|
+
|
104
|
+
# Get memory size
|
105
|
+
memsize = object["memsize"] || 0
|
106
|
+
|
107
|
+
# Get value for strings
|
108
|
+
value = object["value"]
|
109
|
+
|
110
|
+
allocation = Allocation.new(
|
111
|
+
cache,
|
112
|
+
type, # class_name
|
113
|
+
file, # file
|
114
|
+
line_number, # line
|
115
|
+
memsize, # memsize
|
116
|
+
value, # value (for strings)
|
117
|
+
true # retained (all objects in heap dump are live)
|
118
|
+
)
|
119
|
+
|
120
|
+
sampler.allocated << allocation
|
121
|
+
object_count += 1
|
122
|
+
|
123
|
+
# Report progress periodically
|
124
|
+
if block && (object_count % report_interval == 0)
|
125
|
+
block.call(line_count, object_count)
|
126
|
+
end
|
127
|
+
end
|
119
128
|
|
120
|
-
|
121
|
-
object_count
|
129
|
+
# Final progress report
|
130
|
+
block.call(line_count, object_count) if block
|
122
131
|
|
123
|
-
|
124
|
-
if block && (object_count % report_interval == 0)
|
125
|
-
block.call(line_count, object_count)
|
126
|
-
end
|
132
|
+
return sampler
|
127
133
|
end
|
128
134
|
|
129
|
-
# Final progress report
|
130
|
-
block.call(line_count, object_count) if block
|
131
|
-
|
132
|
-
return sampler
|
133
|
-
end
|
134
|
-
|
135
135
|
# Initialize a new sampler.
|
136
136
|
# @parameter filter [Block | Nil] Optional filter block to select which allocations to track.
|
137
137
|
def initialize(&filter)
|
@@ -231,6 +231,22 @@ module Memory
|
|
231
231
|
return report
|
232
232
|
end
|
233
233
|
|
234
|
+
# Convert this sampler to a JSON-compatible summary.
|
235
|
+
# Returns the allocation count without iterating through all allocations.
|
236
|
+
# @parameter options [Hash | Nil] Optional JSON serialization options.
|
237
|
+
# @returns [Hash] JSON-compatible summary of sampler data.
|
238
|
+
def as_json(options = nil)
|
239
|
+
{
|
240
|
+
allocations: @allocated.size
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
# Convert this sampler to a JSON string.
|
245
|
+
# @returns [String] JSON representation of this sampler summary.
|
246
|
+
def to_json(...)
|
247
|
+
as_json.to_json(...)
|
248
|
+
end
|
249
|
+
|
234
250
|
# Collects object allocation and memory of ruby code inside of passed block.
|
235
251
|
def run(&block)
|
236
252
|
start
|
data/lib/memory/version.rb
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
# Copyright, 2013-2019, by Sam Saffron.
|
5
5
|
# Copyright, 2015-2016, by Dave Gynn.
|
6
6
|
# Copyright, 2018, by Jonas Peschla.
|
7
|
-
# Copyright, 2020-
|
7
|
+
# Copyright, 2020-2025, by Samuel Williams.
|
8
8
|
|
9
9
|
module Memory
|
10
|
-
VERSION = "0.
|
10
|
+
VERSION = "0.7.0"
|
11
11
|
end
|
data/readme.md
CHANGED
data/releases.md
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|