memory 0.3.0 → 0.4.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: 37c553347c5941efab19b0f3df37824d10193cbf138582cfc5d24a598ba5a850
4
- data.tar.gz: edac25b5c09088fabde46d7af1cc5603897d26d5543b3c8b49adea9a92ef6c68
3
+ metadata.gz: d560993f9f0c1142d7330fd7f17893d84c46a9d1a265150d5aa6bbc891175479
4
+ data.tar.gz: bef207c3e7221996f9ac5a1caf9c025fa8da025ea47b8ac222933cc5c08f1947
5
5
  SHA512:
6
- metadata.gz: 69d25c208346c039acf4c7b190c9b9eece09e7f6fc970db1d4191ed384d2cd74b0650f1c5e69d744e8a1344021c39945d0e21604706887d8495a3f719682bbf9
7
- data.tar.gz: 0d5d16c7def274988e920930c181e6abf0d5d32b60489d24d95d35b6fc9faa71e4cf285524246a53c3eb9ec589a6892af7685b52a3d320f933a130c0ca1f1553
6
+ metadata.gz: 374e9de16464bcdc38453215dc0627d24651bb620f265453d37819e0faf6caef90be86f9ce772f70277a3aba4b4ec990d5587848c8964d17dd385359814081dc
7
+ data.tar.gz: 4e86fe73db538a6ce6e6b21d8a1bf57f32da62d1c5b7077c6aff8ca1593706ee787c2102bc9a141cce9b4d177415e015f7570e076218ee29b374f32b18a919ad
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/memory/report.rb CHANGED
@@ -26,7 +26,15 @@ module Memory
26
26
  end
27
27
 
28
28
  attr :total_allocated
29
+ attr :total_retained
30
+ attr :aggregates
29
31
 
32
+ # Add all samples from the given sampler to this report.
33
+ def add(sampler)
34
+ self.concat(sampler.allocated)
35
+ end
36
+
37
+ # Add allocations to this report.
30
38
  def concat(allocations)
31
39
  allocations.each do |allocation|
32
40
  @total_allocated << allocation
@@ -37,7 +45,7 @@ module Memory
37
45
  end
38
46
  end
39
47
  end
40
-
48
+
41
49
  def print(io = $stderr)
42
50
  io.puts "\# Memory Profile", nil
43
51
 
@@ -75,6 +75,9 @@ module Memory
75
75
 
76
76
  def start
77
77
  GC.disable
78
+ 3.times{GC.start}
79
+
80
+ # Ensure any allocations related to the block are freed:
78
81
  GC.start
79
82
 
80
83
  @generation = GC.count
@@ -90,6 +93,9 @@ module Memory
90
93
  GC.enable
91
94
  3.times{GC.start}
92
95
 
96
+ # See above.
97
+ GC.start
98
+
93
99
  ObjectSpace.each_object do |object|
94
100
  next unless ObjectSpace.allocation_generation(object) == @generation
95
101
 
@@ -7,5 +7,5 @@
7
7
  # Copyright, 2020-2022, by Samuel Williams.
8
8
 
9
9
  module Memory
10
- VERSION = "0.3.0"
10
+ VERSION = "0.4.0"
11
11
  end
data/lib/memory.rb CHANGED
@@ -13,10 +13,17 @@ require_relative "memory/report"
13
13
  require_relative "memory/sampler"
14
14
 
15
15
  module Memory
16
- def self.report(&block)
16
+ def self.capture(report = nil, &block)
17
17
  sampler = Sampler.new
18
18
  sampler.run(&block)
19
19
 
20
- return sampler.report
20
+ report ||= Report.general
21
+ report.add(sampler)
22
+
23
+ return report
24
+ end
25
+
26
+ def self.report(&block)
27
+ self.capture(&block)
21
28
  end
22
29
  end
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
metadata.gz.sig CHANGED
Binary file