memory 0.1.0 → 0.3.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: dc40099542a524f07fbf5b7366935ea4ec2f9b935df2f6f8016067c1d210794f
4
- data.tar.gz: 6d5a19607b091081788dbf26bab000a7b1f221befb5c7f9aece9d80f4583fa44
3
+ metadata.gz: 37c553347c5941efab19b0f3df37824d10193cbf138582cfc5d24a598ba5a850
4
+ data.tar.gz: edac25b5c09088fabde46d7af1cc5603897d26d5543b3c8b49adea9a92ef6c68
5
5
  SHA512:
6
- metadata.gz: 8e546c7a3d224c4349152630e37c0c00446aff9184395dbdb9699eec0eacfdd9724e313a33c7442b99c6fdcc6a684a75d28d54f99c78122260bda499503f1682
7
- data.tar.gz: a4760e52fc70250c44faf2685dac5101fe726ef719578cb37dbabe00db4eeebb9cfe46cad41f7238e45d5bd6eb5a591f8f96d7d61766e385567739aad4a49cfa
6
+ metadata.gz: 69d25c208346c039acf4c7b190c9b9eece09e7f6fc970db1d4191ed384d2cd74b0650f1c5e69d744e8a1344021c39945d0e21604706887d8495a3f719682bbf9
7
+ data.tar.gz: 0d5d16c7def274988e920930c181e6abf0d5d32b60489d24d95d35b6fc9faa71e4cf285524246a53c3eb9ec589a6892af7685b52a3d320f933a130c0ca1f1553
checksums.yaml.gz.sig ADDED
Binary file
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- def check
3
+ # Released under the MIT License.
4
+ # Copyright, 2013-2018, by Sam Saffron.
5
+ # Copyright, 2014, by Richard Schneeman.
6
+ # Copyright, 2018, by Jonas Peschla.
7
+ # Copyright, 2020-2022, by Samuel Williams.
8
+
9
+ def check(paths:)
4
10
  require 'console'
5
11
 
6
- paths = Dir["../../*.mprof"]
7
-
8
12
  total_size = paths.sum{|path| File.size(path)}
9
13
 
10
- require_relative 'lib/memory_profiler'
14
+ require_relative '../../lib/memory'
11
15
 
12
16
  report = Memory::Report.general
13
17
 
@@ -32,6 +36,4 @@ def check
32
36
  end
33
37
 
34
38
  report.print($stdout)
35
-
36
- binding.irb
37
- end
39
+ end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2022, by Samuel Williams.
22
5
 
23
6
  module Memory
24
7
  UNITS = {
@@ -59,6 +42,13 @@ module Memory
59
42
  def to_s
60
43
  "(#{Memory.formatted_bytes memory} in #{count} allocations)"
61
44
  end
45
+
46
+ def as_json
47
+ {
48
+ memory: memory,
49
+ count: count
50
+ }
51
+ end
62
52
  end
63
53
 
64
54
  def initialize(title, &block)
@@ -69,7 +59,10 @@ module Memory
69
59
  @totals = Hash.new{|h,k| h[k] = Total.new}
70
60
  end
71
61
 
62
+ attr :title
63
+ attr :metric
72
64
  attr :total
65
+ attr :totals
73
66
 
74
67
  def << allocation
75
68
  metric = @metric.call(allocation)
@@ -95,6 +88,14 @@ module Memory
95
88
 
96
89
  io.puts nil
97
90
  end
91
+
92
+ def as_json
93
+ {
94
+ title: @title,
95
+ total: @total.as_json,
96
+ totals: @totals.map{|k, v| [k, v.as_json]}
97
+ }
98
+ end
98
99
  end
99
100
 
100
101
  class ValueAggregate
@@ -105,6 +106,10 @@ module Memory
105
106
  @aggregates = Hash.new{|h,k| h[k] = Aggregate.new(k.inspect, &@metric)}
106
107
  end
107
108
 
109
+ attr :title
110
+ attr :metric
111
+ attr :aggregates
112
+
108
113
  def << allocation
109
114
  if value = allocation.value
110
115
  aggregate = @aggregates[value]
@@ -124,5 +129,12 @@ module Memory
124
129
  aggregate.print(io, level: level+1)
125
130
  end
126
131
  end
132
+
133
+ def as_json
134
+ {
135
+ title: @title,
136
+ aggregates: @aggregates.map{|k, v| [k, v.as_json]}
137
+ }
138
+ end
127
139
  end
128
140
  end
data/lib/memory/cache.rb CHANGED
@@ -1,24 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2013-2020, by Sam Saffron.
5
+ # Copyright, 2015-2018, by Dave Gynn.
6
+ # Copyright, 2015, by Vincent Woo.
7
+ # Copyright, 2015, by Boris Staal.
8
+ # Copyright, 2016, by Hamdi Akoğuz.
9
+ # Copyright, 2018, by Jonas Peschla.
10
+ # Copyright, 2020, by Jean Boussier.
11
+ # Copyright, 2020-2022, by Samuel Williams.
22
12
 
23
13
  module Memory
24
14
  class Cache
data/lib/memory/deque.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2022, by Samuel Williams.
22
5
 
23
6
  require 'objspace'
24
7
  require 'msgpack'
data/lib/memory/report.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2022, by Samuel Williams.
22
5
 
23
6
  require_relative 'aggregate'
24
7
 
@@ -66,5 +49,17 @@ module Memory
66
49
  aggregate.print(io)
67
50
  end
68
51
  end
52
+
53
+ def as_json
54
+ {
55
+ total_allocated: @total_allocated.as_json,
56
+ total_retained: @total_retained.as_json,
57
+ aggregates: @aggregates.map(&:as_json)
58
+ }
59
+ end
60
+
61
+ def to_json(...)
62
+ as_json.to_json(...)
63
+ end
69
64
  end
70
65
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2022, by Samuel Williams.
5
+
6
+ require_relative '../sampler'
7
+
8
+ module Memory
9
+ module RSpec
10
+ module Profiler
11
+ def self.profile(scope)
12
+ memory_sampler = nil
13
+
14
+ scope.before(:all) do |example_group|
15
+ name = example_group.class.description.gsub(/[^\w]+/, "-")
16
+ path = "#{name}.mprof"
17
+
18
+ skip if File.exist?(path)
19
+
20
+ memory_sampler = Memory::Sampler.new
21
+ memory_sampler.start
22
+ end
23
+
24
+ scope.after(:all) do |example_group|
25
+ name = example_group.class.description.gsub(/[^\w]+/, "-")
26
+ path = "#{name}.mprof"
27
+
28
+ if memory_sampler
29
+ memory_sampler.stop
30
+
31
+ File.open(path, "w", encoding: Encoding::BINARY) do |io|
32
+ memory_sampler.dump(io)
33
+ end
34
+
35
+ memory_sampler = nil
36
+ end
37
+ end
38
+
39
+ scope.after(:suite) do
40
+ memory_sampler = Memory::Sampler.new
41
+
42
+ Dir.glob("*.mprof") do |path|
43
+ memory_sampler.load(File.read(
44
+ path,
45
+ encoding: Encoding::BINARY,
46
+ ))
47
+ end
48
+
49
+ memory_sampler.report.print
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,24 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2013-2020, by Sam Saffron.
5
+ # Copyright, 2014, by Richard Schneeman.
6
+ # Copyright, 2014, by Søren Skovsbøll.
7
+ # Copyright, 2015, by Anton Davydov.
8
+ # Copyright, 2015-2018, by Dave Gynn.
9
+ # Copyright, 2017, by Nick LaMuro.
10
+ # Copyright, 2018, by William Tabi.
11
+ # Copyright, 2018, by Jonas Peschla.
12
+ # Copyright, 2018, by Espartaco Palma.
13
+ # Copyright, 2020, by Jean Boussier.
14
+ # Copyright, 2020-2022, by Samuel Williams.
22
15
 
23
16
  require 'objspace'
24
17
  require 'msgpack'
@@ -1,25 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2013-2019, by Sam Saffron.
5
+ # Copyright, 2015-2016, by Dave Gynn.
6
+ # Copyright, 2018, by Jonas Peschla.
7
+ # Copyright, 2020-2022, by Samuel Williams.
22
8
 
23
9
  module Memory
24
- VERSION = "0.1.0"
10
+ VERSION = "0.3.0"
25
11
  end
data/lib/memory.rb CHANGED
@@ -1,24 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2013-2019, by Sam Saffron.
5
+ # Copyright, 2014, by Søren Skovsbøll.
6
+ # Copyright, 2017, by Nick LaMuro.
7
+ # Copyright, 2018, by Jonas Peschla.
8
+ # Copyright, 2020-2022, by Samuel Williams.
22
9
 
23
10
  require_relative "memory/version"
24
11
  require_relative "memory/cache"
data/license.md ADDED
@@ -0,0 +1,45 @@
1
+ # MIT License
2
+
3
+ Copyright, 2013-2020, by Sam Saffron.
4
+ Copyright, 2013, by Luís Ferreira.
5
+ Copyright, 2014, by John Bachir.
6
+ Copyright, 2014, by Andrew Grimm.
7
+ Copyright, 2014, by Richard Schneeman.
8
+ Copyright, 2014, by Jaiden Mispy.
9
+ Copyright, 2014, by Søren Skovsbøll.
10
+ Copyright, 2015, by Anton Davydov.
11
+ Copyright, 2015, by Mike Subelsky.
12
+ Copyright, 2015, by Florian Schwab.
13
+ Copyright, 2015-2018, by Dave Gynn.
14
+ Copyright, 2015, by Vincent Woo.
15
+ Copyright, 2015, by Boris Staal.
16
+ Copyright, 2016, by Hamdi Akoğuz.
17
+ Copyright, 2017, by Nick LaMuro.
18
+ Copyright, 2017, by Vasily Kolesnikov.
19
+ Copyright, 2018, by William Tabi.
20
+ Copyright, 2018, by Jonas Peschla.
21
+ Copyright, 2018, by Benoit Tigeot.
22
+ Copyright, 2018, by Espartaco Palma.
23
+ Copyright, 2019-2020, by Jean Boussier.
24
+ Copyright, 2019, by Ashwin Maroli.
25
+ Copyright, 2019, by Olle Jonsson.
26
+ Copyright, 2019, by Danny Ben Shitrit.
27
+ Copyright, 2020-2022, by Samuel Williams.
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ of this software and associated documentation files (the "Software"), to deal
31
+ in the Software without restriction, including without limitation the rights
32
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ copies of the Software, and to permit persons to whom the Software is
34
+ furnished to do so, subject to the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included in all
37
+ copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,123 @@
1
+ # Memory
2
+
3
+ A set of tools for profiling memory in Ruby.
4
+
5
+ [![Development Status](https://github.com/socketry/memory/workflows/Test/badge.svg)](https://github.com/socketry/memory/actions?workflow=Test)
6
+
7
+ ## Features
8
+
9
+ - Fast memory capture for million+ allocations.
10
+ - Persist results to disk for vast aggregations and comparisons over time.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ``` shell
17
+ $ bundle add 'memory'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ``` ruby
23
+ require 'memory'
24
+
25
+ report = Memory.report do
26
+ # run your code here
27
+ end
28
+
29
+ report.print
30
+ ```
31
+
32
+ Or, you can use the `.start`/`.stop` methods as well:
33
+
34
+ ``` ruby
35
+ require 'memory'
36
+
37
+ sampler = Memory::Sampler.new
38
+
39
+ sampler.start
40
+ # run your code here
41
+ sampler.stop
42
+
43
+ report = sampler.report
44
+ report.print
45
+ ```
46
+
47
+ ### RSpec Integration
48
+
49
+ ``` ruby
50
+ memory_sampler = nil
51
+ config.before(:all) do |example_group|
52
+ name = example_group.class.description.gsub(/[^\w]+/, "-")
53
+ path = "#{name}.mprof"
54
+
55
+ skip if File.exist?(path)
56
+
57
+ memory_sampler = Memory::Sampler.new
58
+ memory_sampler.start
59
+ end
60
+
61
+ config.after(:all) do |example_group|
62
+ name = example_group.class.description.gsub(/[^\w]+/, "-")
63
+ path = "#{name}.mprof"
64
+
65
+ if memory_sampler
66
+ memory_sampler.stop
67
+
68
+ File.open(path, "w", encoding: Encoding::BINARY) do |io|
69
+ memory_sampler.dump(io)
70
+ end
71
+
72
+ memory_sampler = nil
73
+ end
74
+ end
75
+
76
+ config.after(:suite) do
77
+ memory_sampler = Memory::Sampler.new
78
+
79
+ Dir.glob("*.mprof") do |path|
80
+ memory_sampler.load(File.read(
81
+ path,
82
+ encoding: Encoding::BINARY,
83
+ ))
84
+ end
85
+
86
+ memory_sampler.results.print
87
+ end
88
+ ```
89
+
90
+ #### Raw Object Allocations
91
+
92
+ ``` ruby
93
+ before = nil
94
+
95
+ config.before(:suite) do |example|
96
+ 3.times{GC.start}
97
+ GC.disable
98
+ before = ObjectSpace.count_objects
99
+ end
100
+
101
+ config.after(:suite) do |example|
102
+ after = ObjectSpace.count_objects
103
+ GC.enable
104
+
105
+ $stderr.puts
106
+ $stderr.puts "Object Allocations:"
107
+
108
+ after.each do |key, b|
109
+ a = before.fetch(key, 0)
110
+ $stderr.puts "#{key}: #{a} -> #{b} = #{b-a} allocations"
111
+ end
112
+ end
113
+ ```
114
+
115
+ ## Contributing
116
+
117
+ We welcome contributions to this project.
118
+
119
+ 1. Fork it.
120
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
121
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
122
+ 4. Push to the branch (`git push origin my-new-feature`).
123
+ 5. Create new Pull Request.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,16 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Samuel Williams
8
7
  - Sam Saffron
8
+ - Dave Gynn
9
+ - Nick LaMuro
10
+ - Jonas Peschla
11
+ - Samuel Williams
12
+ - Ashwin Maroli
13
+ - Søren Skovsbøll
14
+ - Richard Schneeman
15
+ - Anton Davydov
16
+ - Benoit Tigeot
17
+ - Jean Boussier
18
+ - Vincent Woo
19
+ - Andrew Grimm
20
+ - Boris Staal
21
+ - Danny Ben Shitrit
22
+ - Espartaco Palma
23
+ - Florian Schwab
24
+ - Hamdi Akoğuz
25
+ - Jaiden Mispy
26
+ - John Bachir
27
+ - Luís Ferreira
28
+ - Mike Subelsky
29
+ - Olle Jonsson
30
+ - Vasily Kolesnikov
31
+ - William Tabi
9
32
  autorequire:
10
33
  bindir: bin
11
- cert_chain: []
12
- date: 2020-09-02 00:00:00.000000000 Z
34
+ cert_chain:
35
+ - |
36
+ -----BEGIN CERTIFICATE-----
37
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
38
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
39
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
40
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
41
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
42
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
43
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
44
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
45
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
46
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
47
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
48
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
49
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
50
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
51
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
52
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
53
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
54
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
55
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
56
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
57
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
58
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
59
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
60
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
61
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
62
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
63
+ -----END CERTIFICATE-----
64
+ date: 2022-11-15 00:00:00.000000000 Z
13
65
  dependencies:
66
+ - !ruby/object:Gem::Dependency
67
+ name: bake
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.15'
73
+ type: :runtime
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.15'
80
+ - !ruby/object:Gem::Dependency
81
+ name: console
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
14
94
  - !ruby/object:Gem::Dependency
15
95
  name: msgpack
16
96
  requirement: !ruby/object:Gem::Requirement
@@ -25,6 +105,20 @@ dependencies:
25
105
  - - ">="
26
106
  - !ruby/object:Gem::Version
27
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'
28
122
  - !ruby/object:Gem::Dependency
29
123
  name: bundler
30
124
  requirement: !ruby/object:Gem::Requirement
@@ -54,19 +148,19 @@ dependencies:
54
148
  - !ruby/object:Gem::Version
55
149
  version: '0'
56
150
  - !ruby/object:Gem::Dependency
57
- name: rspec
151
+ name: sus
58
152
  requirement: !ruby/object:Gem::Requirement
59
153
  requirements:
60
- - - "~>"
154
+ - - ">="
61
155
  - !ruby/object:Gem::Version
62
- version: '3.0'
156
+ version: '0'
63
157
  type: :development
64
158
  prerelease: false
65
159
  version_requirements: !ruby/object:Gem::Requirement
66
160
  requirements:
67
- - - "~>"
161
+ - - ">="
68
162
  - !ruby/object:Gem::Version
69
- version: '3.0'
163
+ version: '0'
70
164
  description:
71
165
  email:
72
166
  executables: []
@@ -79,8 +173,11 @@ files:
79
173
  - lib/memory/cache.rb
80
174
  - lib/memory/deque.rb
81
175
  - lib/memory/report.rb
176
+ - lib/memory/rspec/profiler.rb
82
177
  - lib/memory/sampler.rb
83
178
  - lib/memory/version.rb
179
+ - license.md
180
+ - readme.md
84
181
  homepage: https://github.com/socketry/memory
85
182
  licenses:
86
183
  - MIT
@@ -100,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
197
  - !ruby/object:Gem::Version
101
198
  version: '0'
102
199
  requirements: []
103
- rubygems_version: 3.0.3
200
+ rubygems_version: 3.3.7
104
201
  signing_key:
105
202
  specification_version: 4
106
203
  summary: Memory profiling routines for Ruby 2.3+
metadata.gz.sig ADDED
Binary file