memory 0.3.0 → 0.4.1

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: 2400492846a2a2ac811dbdd279b3c1aa02446e6c2dfd45684e7c517d45ab3139
4
+ data.tar.gz: 649b747e821996d0aca2cb92782661916fb05b8c76418a8e95acef988f97909a
5
5
  SHA512:
6
- metadata.gz: 69d25c208346c039acf4c7b190c9b9eece09e7f6fc970db1d4191ed384d2cd74b0650f1c5e69d744e8a1344021c39945d0e21604706887d8495a3f719682bbf9
7
- data.tar.gz: 0d5d16c7def274988e920930c181e6abf0d5d32b60489d24d95d35b6fc9faa71e4cf285524246a53c3eb9ec589a6892af7685b52a3d320f933a130c0ca1f1553
6
+ metadata.gz: 34682359d1d6b6e04af1582fb9a3a43c798ca032a02fd79fe9f1f62ee00d4c717639867e41f53e998bfc2749afe9423e2a87865451b58de3e63cf033e40c2710
7
+ data.tar.gz: e5f1bbcf26cb1aae51c03d2fd465c38682ee35f8d9098af225791802ba5f9c34238d8b86993e10628b047da71c50336826ddf0f2beb1a0a204ffb244887894e0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -18,7 +18,7 @@ def check(paths:)
18
18
  cache = Memory::Cache.new
19
19
  wrapper = Memory::Wrapper.new(cache)
20
20
 
21
- measure = Console.logger.measure(report, total_size)
21
+ progress = Console.logger.progress(report, total_size)
22
22
 
23
23
  paths.each do |path|
24
24
  Console.logger.info(report, "Loading #{path}, #{Memory.formatted_bytes File.size(path)}")
@@ -29,7 +29,7 @@ def check(paths:)
29
29
 
30
30
  report.concat(unpacker)
31
31
 
32
- measure.increment(io.size)
32
+ progress.increment(io.size)
33
33
  end
34
34
 
35
35
  Console.logger.info(report, "Loaded allocations, #{report.total_allocated}")
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2020-2022, by Samuel Williams.
4
+ # Copyright, 2020-2023, by Samuel Williams.
5
5
 
6
6
  module Memory
7
7
  UNITS = {
@@ -43,7 +43,7 @@ module Memory
43
43
  "(#{Memory.formatted_bytes memory} in #{count} allocations)"
44
44
  end
45
45
 
46
- def as_json
46
+ def as_json(options = nil)
47
47
  {
48
48
  memory: memory,
49
49
  count: count
@@ -89,11 +89,11 @@ module Memory
89
89
  io.puts nil
90
90
  end
91
91
 
92
- def as_json
92
+ def as_json(options = nil)
93
93
  {
94
94
  title: @title,
95
- total: @total.as_json,
96
- totals: @totals.map{|k, v| [k, v.as_json]}
95
+ total: @total.as_json(options),
96
+ totals: @totals.map{|k, v| [k, v.as_json(options)]}
97
97
  }
98
98
  end
99
99
  end
@@ -130,7 +130,7 @@ module Memory
130
130
  end
131
131
  end
132
132
 
133
- def as_json
133
+ def as_json(options = nil)
134
134
  {
135
135
  title: @title,
136
136
  aggregates: @aggregates.map{|k, v| [k, v.as_json]}
data/lib/memory/report.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2020-2022, by Samuel Williams.
4
+ # Copyright, 2020-2023, by Samuel Williams.
5
5
 
6
6
  require_relative 'aggregate'
7
7
 
@@ -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
 
@@ -50,11 +58,11 @@ module Memory
50
58
  end
51
59
  end
52
60
 
53
- def as_json
61
+ def as_json(options = nil)
54
62
  {
55
- total_allocated: @total_allocated.as_json,
56
- total_retained: @total_retained.as_json,
57
- aggregates: @aggregates.map(&:as_json)
63
+ total_allocated: @total_allocated.as_json(options),
64
+ total_retained: @total_retained.as_json(options),
65
+ aggregates: @aggregates.map{|aggregate| aggregate.as_json(options)}
58
66
  }
59
67
  end
60
68
 
@@ -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.1"
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/license.md CHANGED
@@ -24,7 +24,7 @@ Copyright, 2019-2020, by Jean Boussier.
24
24
  Copyright, 2019, by Ashwin Maroli.
25
25
  Copyright, 2019, by Olle Jonsson.
26
26
  Copyright, 2019, by Danny Ben Shitrit.
27
- Copyright, 2020-2022, by Samuel Williams.
27
+ Copyright, 2020-2023, by Samuel Williams.
28
28
 
29
29
  Permission is hereby granted, free of charge, to any person obtaining a copy
30
30
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -121,3 +121,11 @@ We welcome contributions to this project.
121
121
  3. Commit your changes (`git commit -am 'Add some feature'`).
122
122
  4. Push to the branch (`git push origin my-new-feature`).
123
123
  5. Create new Pull Request.
124
+
125
+ ### Developer Certificate of Origin
126
+
127
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
128
+
129
+ ### Contributor Covenant
130
+
131
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  - Dave Gynn
9
+ - Samuel Williams
9
10
  - Nick LaMuro
10
11
  - Jonas Peschla
11
- - Samuel Williams
12
12
  - Ashwin Maroli
13
13
  - Søren Skovsbøll
14
14
  - Richard Schneeman
@@ -61,7 +61,7 @@ cert_chain:
61
61
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
62
62
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
63
63
  -----END CERTIFICATE-----
64
- date: 2022-11-15 00:00:00.000000000 Z
64
+ date: 2023-08-16 00:00:00.000000000 Z
65
65
  dependencies:
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: bake
@@ -105,62 +105,6 @@ dependencies:
105
105
  - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
- - !ruby/object:Gem::Dependency
109
- name: bake-test
110
- requirement: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: '0'
115
- type: :development
116
- prerelease: false
117
- version_requirements: !ruby/object:Gem::Requirement
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- version: '0'
122
- - !ruby/object:Gem::Dependency
123
- name: bundler
124
- requirement: !ruby/object:Gem::Requirement
125
- requirements:
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- version: '0'
129
- type: :development
130
- prerelease: false
131
- version_requirements: !ruby/object:Gem::Requirement
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- version: '0'
136
- - !ruby/object:Gem::Dependency
137
- name: covered
138
- requirement: !ruby/object:Gem::Requirement
139
- requirements:
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- version: '0'
143
- type: :development
144
- prerelease: false
145
- version_requirements: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
- - !ruby/object:Gem::Dependency
151
- name: sus
152
- requirement: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- version: '0'
157
- type: :development
158
- prerelease: false
159
- version_requirements: !ruby/object:Gem::Requirement
160
- requirements:
161
- - - ">="
162
- - !ruby/object:Gem::Version
163
- version: '0'
164
108
  description:
165
109
  email:
166
110
  executables: []
@@ -190,14 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
134
  requirements:
191
135
  - - ">="
192
136
  - !ruby/object:Gem::Version
193
- version: 2.3.0
137
+ version: '3.0'
194
138
  required_rubygems_version: !ruby/object:Gem::Requirement
195
139
  requirements:
196
140
  - - ">="
197
141
  - !ruby/object:Gem::Version
198
142
  version: '0'
199
143
  requirements: []
200
- rubygems_version: 3.3.7
144
+ rubygems_version: 3.4.10
201
145
  signing_key:
202
146
  specification_version: 4
203
147
  summary: Memory profiling routines for Ruby 2.3+
metadata.gz.sig CHANGED
Binary file