memory 0.1.0 → 0.2.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: d0feb44dbfa1bf04a279604fb651dc730c03fadfcfda51e0818b08d1d590b4a0
4
+ data.tar.gz: eb5371436c2c66246d5bdb55a879b3da29c619d20f6a1bfef4a5802000db0a70
5
5
  SHA512:
6
- metadata.gz: 8e546c7a3d224c4349152630e37c0c00446aff9184395dbdb9699eec0eacfdd9724e313a33c7442b99c6fdcc6a684a75d28d54f99c78122260bda499503f1682
7
- data.tar.gz: a4760e52fc70250c44faf2685dac5101fe726ef719578cb37dbabe00db4eeebb9cfe46cad41f7238e45d5bd6eb5a591f8f96d7d61766e385567739aad4a49cfa
6
+ metadata.gz: b993009c31964ca15a4ee65f621ec656b3fea7e82b184a8e33b0f0e3163d47947295b0506300e83ff0fc1072e03f071a14a0e26b70d08e8f86760d7a8e1bc993
7
+ data.tar.gz: 6167b0aeee0a0f2cb0aba05280b6379d407af895571d28a63921991051e7ba064d5775a5f43aa88b02929dc2582f0688dfe75ec02407e1be7f856f5cb39a26e1
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- def check
3
+ # @parameter paths [Array(String)] The paths which contain the memory profiles.
4
+ def check(paths:)
4
5
  require 'console'
5
6
 
6
- paths = Dir["../../*.mprof"]
7
-
8
7
  total_size = paths.sum{|path| File.size(path)}
9
8
 
10
- require_relative 'lib/memory_profiler'
9
+ require_relative '../../lib/memory'
11
10
 
12
11
  report = Memory::Report.general
13
12
 
@@ -32,6 +31,4 @@ def check
32
31
  end
33
32
 
34
33
  report.print($stdout)
35
-
36
- binding.irb
37
34
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
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.
22
+
23
+ require_relative '../sampler'
24
+
25
+ module Memory
26
+ module RSpec
27
+ module Profiler
28
+ def self.profile(scope)
29
+ memory_sampler = nil
30
+
31
+ scope.before(:all) do |example_group|
32
+ name = example_group.class.description.gsub(/[^\w]+/, "-")
33
+ path = "#{name}.mprof"
34
+
35
+ skip if File.exist?(path)
36
+
37
+ memory_sampler = Memory::Sampler.new
38
+ memory_sampler.start
39
+ end
40
+
41
+ scope.after(:all) do |example_group|
42
+ name = example_group.class.description.gsub(/[^\w]+/, "-")
43
+ path = "#{name}.mprof"
44
+
45
+ if memory_sampler
46
+ memory_sampler.stop
47
+
48
+ File.open(path, "w", encoding: Encoding::BINARY) do |io|
49
+ memory_sampler.dump(io)
50
+ end
51
+
52
+ memory_sampler = nil
53
+ end
54
+ end
55
+
56
+ scope.after(:suite) do
57
+ memory_sampler = Memory::Sampler.new
58
+
59
+ Dir.glob("*.mprof") do |path|
60
+ memory_sampler.load(File.read(
61
+ path,
62
+ encoding: Encoding::BINARY,
63
+ ))
64
+ end
65
+
66
+ memory_sampler.report.print
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Memory
24
- VERSION = "0.1.0"
24
+ VERSION = "0.2.0"
25
25
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-02 00:00:00.000000000 Z
12
+ date: 2020-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
@@ -25,6 +25,34 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: console
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.15.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.15.0
28
56
  - !ruby/object:Gem::Dependency
29
57
  name: bundler
30
58
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +107,7 @@ files:
79
107
  - lib/memory/cache.rb
80
108
  - lib/memory/deque.rb
81
109
  - lib/memory/report.rb
110
+ - lib/memory/rspec/profiler.rb
82
111
  - lib/memory/sampler.rb
83
112
  - lib/memory/version.rb
84
113
  homepage: https://github.com/socketry/memory