memory 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/memory/aggregate.rb +2 -2
- data/lib/memory/report.rb +19 -8
- data/lib/memory/sampler.rb +8 -3
- data/lib/memory/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +7 -5
- 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: 116b9be7bb4a7d1c7b906923132406708953a8e3e7d43687d82f7920192ad74f
|
4
|
+
data.tar.gz: bf093a25998cefbf01f8fbc79d92d23bc972c016596acb3678cd6303eb09e034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 403676e22f95cd9239f3da72898a9be935c100e236bd51a6fca58d2ebf472a33609efb373dff628cf5f6f1e7ed9ace28dc3abc45adbbdc9975d489539b2f853d
|
7
|
+
data.tar.gz: be14f62bb150ab3daec0c9743800e887e606b0ba1545725143484362278779451f9a98dab2a35126d4396d6a57e08c1ccdce28b1a21fe5e894516b16e235b79c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/memory/aggregate.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
module Memory
|
7
7
|
UNITS = {
|
@@ -31,7 +31,7 @@ module Memory
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def << allocation
|
34
|
-
self.memory += allocation.
|
34
|
+
self.memory += allocation.memsize
|
35
35
|
self.count += 1
|
36
36
|
end
|
37
37
|
|
data/lib/memory/report.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative 'aggregate'
|
7
7
|
|
8
8
|
module Memory
|
9
9
|
class Report
|
10
|
-
def self.general
|
10
|
+
def self.general(**options)
|
11
11
|
Report.new([
|
12
12
|
Aggregate.new("By Gem", &:gem),
|
13
13
|
Aggregate.new("By File", &:file),
|
@@ -15,10 +15,12 @@ module Memory
|
|
15
15
|
Aggregate.new("By Class", &:class_name),
|
16
16
|
ValueAggregate.new("Strings By Gem", &:gem),
|
17
17
|
ValueAggregate.new("Strings By Location", &:location),
|
18
|
-
])
|
18
|
+
], **options)
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(aggregates)
|
21
|
+
def initialize(aggregates, retained_only: true)
|
22
|
+
@retained_only = retained_only
|
23
|
+
|
22
24
|
@total_allocated = Aggregate::Total.new
|
23
25
|
@total_retained = Aggregate::Total.new
|
24
26
|
|
@@ -38,16 +40,25 @@ module Memory
|
|
38
40
|
def concat(allocations)
|
39
41
|
allocations.each do |allocation|
|
40
42
|
@total_allocated << allocation
|
41
|
-
@total_retained << allocation if allocation.retained
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
if allocation.retained
|
45
|
+
@total_retained << allocation
|
46
|
+
end
|
47
|
+
|
48
|
+
if !@retained_only || allocation.retained
|
49
|
+
@aggregates.each do |aggregate|
|
50
|
+
aggregate << allocation
|
51
|
+
end
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
49
56
|
def print(io = $stderr)
|
50
|
-
|
57
|
+
if @retained_only
|
58
|
+
io.puts "\# Retained Memory Profile", nil
|
59
|
+
else
|
60
|
+
io.puts "\# Memory Profile", nil
|
61
|
+
end
|
51
62
|
|
52
63
|
io.puts "- Total Allocated: #{@total_allocated}"
|
53
64
|
io.puts "- Total Retained: #{@total_retained}"
|
data/lib/memory/sampler.rb
CHANGED
@@ -17,6 +17,8 @@ require 'objspace'
|
|
17
17
|
require 'msgpack'
|
18
18
|
require 'console'
|
19
19
|
|
20
|
+
require_relative 'cache'
|
21
|
+
|
20
22
|
module Memory
|
21
23
|
class Wrapper < MessagePack::Factory
|
22
24
|
def initialize(cache)
|
@@ -94,6 +96,9 @@ module Memory
|
|
94
96
|
|
95
97
|
# **WARNING** Do not allocate any new Objects between the call to GC.start and the completion of the retained lookups. It is likely that a new Object would reuse an object_id from a GC'd object.
|
96
98
|
|
99
|
+
# Overwrite any immediate values on the C stack to avoid retaining them.
|
100
|
+
ObjectSpace.dump(Object.new)
|
101
|
+
|
97
102
|
GC.enable
|
98
103
|
3.times{GC.start}
|
99
104
|
|
@@ -131,8 +136,8 @@ module Memory
|
|
131
136
|
@allocated.concat(allocations)
|
132
137
|
end
|
133
138
|
|
134
|
-
def report
|
135
|
-
report = Report.general
|
139
|
+
def report(**options)
|
140
|
+
report = Report.general(**options)
|
136
141
|
|
137
142
|
report.concat(@allocated)
|
138
143
|
|
@@ -158,7 +163,7 @@ module Memory
|
|
158
163
|
def track_allocations(generation)
|
159
164
|
rvalue_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
|
160
165
|
|
161
|
-
allocated = Hash.new
|
166
|
+
allocated = Hash.new
|
162
167
|
|
163
168
|
ObjectSpace.each_object do |object|
|
164
169
|
next unless ObjectSpace.allocation_generation(object) == generation
|
data/lib/memory/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -61,7 +61,7 @@ cert_chain:
|
|
61
61
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
62
62
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
63
63
|
-----END CERTIFICATE-----
|
64
|
-
date: 2024-
|
64
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
65
65
|
dependencies:
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
name: bake
|
@@ -125,7 +125,9 @@ files:
|
|
125
125
|
homepage: https://github.com/socketry/memory
|
126
126
|
licenses:
|
127
127
|
- MIT
|
128
|
-
metadata:
|
128
|
+
metadata:
|
129
|
+
documentation_uri: https://socketry.github.io/memory/
|
130
|
+
source_code_uri: https://github.com/socketry/memory.git
|
129
131
|
post_install_message:
|
130
132
|
rdoc_options: []
|
131
133
|
require_paths:
|
@@ -134,14 +136,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
136
|
requirements:
|
135
137
|
- - ">="
|
136
138
|
- !ruby/object:Gem::Version
|
137
|
-
version: '3.
|
139
|
+
version: '3.1'
|
138
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
141
|
requirements:
|
140
142
|
- - ">="
|
141
143
|
- !ruby/object:Gem::Version
|
142
144
|
version: '0'
|
143
145
|
requirements: []
|
144
|
-
rubygems_version: 3.5.
|
146
|
+
rubygems_version: 3.5.11
|
145
147
|
signing_key:
|
146
148
|
specification_version: 4
|
147
149
|
summary: Memory profiling routines for Ruby 2.3+
|
metadata.gz.sig
CHANGED
Binary file
|