hotch 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cddf426d75da3636d92f176d184821f53d22e7e
4
- data.tar.gz: a2c6938c26820426a7bbae6bb608546694375b82
3
+ metadata.gz: 0b46853925c0b06868a85c1f41b6464304d64c89
4
+ data.tar.gz: 2a75ea05ef514b527dc058de2252808b5074811d
5
5
  SHA512:
6
- metadata.gz: 44e05ae09f915021df7ba163b68831be51f3cdeffbe839ccca9aee326caf494d2d0b705ea8f5f0f0e899b05f0b7bcf2c1d630be24f17118c30dfc0ef5ad314b9
7
- data.tar.gz: 879ef47c33c0e7843846970e6b9e50e28663a229f5d7da307a66b71807549e5f213a87f75143605045a862105babc836f76644f9a49d7a174ed2ba49db081eb9
6
+ metadata.gz: 6419725e1737e5d1c662ff5ea6b2741817b041033c95f6961376d5427f3331ce05c18e8502b62299ce43b2b71616c9e96153ccc0327383da7815a983dc82b8a8
7
+ data.tar.gz: a2b344453ac3f59902b521dcb5066e5c98d40e0f1ead60c4d5a3c21534cf97f75be5eb6301483e87770444972ace8e3e68cbac45e72163f021117eb18d0836a0
data/README.md CHANGED
@@ -62,7 +62,7 @@ dry/struct/class_interface.rb:77 T_OBJECT 2000 0 0 0
62
62
  Add this line to your application's Gemfile:
63
63
 
64
64
  ```ruby
65
- gem 'hotch', '~> 0.4.2'
65
+ gem 'hotch', '~> 0.5.0'
66
66
  ```
67
67
 
68
68
  And then execute:
@@ -162,9 +162,7 @@ module Types
162
162
  end
163
163
  end
164
164
 
165
- # For more stable results
166
- GC.disable
167
-
165
+ # For more stable results the GC is disabled by default during runs.
168
166
  Hotch.memory do
169
167
  1000.times do
170
168
  Types::Success.new(
@@ -173,6 +171,29 @@ Hotch.memory do
173
171
  )
174
172
  end
175
173
  end
174
+
175
+ # In order to prevent disabling the GC during runs do:
176
+ Hotch.memory(disable_gc: false) do
177
+ # ...
178
+ end
179
+
180
+ # Disable aggregation between runs:
181
+ Hotch.memory(aggregate: false) do
182
+ # this run is not aggregated
183
+ end
184
+ ```
185
+
186
+ ### Minitest integration for the memory profiler
187
+
188
+ Load `hotch/memory/minitest` in your `test/test_helper.rb` like this:
189
+
190
+ ```ruby
191
+ require 'minitest/autorun'
192
+ require 'hotch/memory/minitest'
193
+
194
+ Hotch::Minitest.run
195
+ Hotch::Minitest.run(name: "my name")
196
+ Hotch::Minitest.run(disable_gc: false) # on by default
176
197
  ```
177
198
 
178
199
 
@@ -1,10 +1,14 @@
1
1
  require 'allocation_tracer'
2
2
 
3
3
  class Hotch
4
- def self.memory(name: $0, &block)
5
- caller = Kernel.caller_locations(1).first
6
- name = "#{name}:#{caller.path}:#{caller.lineno}"
7
- memory = Memory.new(name)
4
+ def self.memory(name: $0, aggregate: true, &block)
5
+ memory = if aggregate
6
+ $hotch_memory ||= Memory.new(name)
7
+ else
8
+ caller = Kernel.caller_locations(1).first
9
+ name = "#{name}:#{caller.path}:#{caller.lineno}"
10
+ Memory.new(name)
11
+ end
8
12
 
9
13
  memory.report_at_exit
10
14
 
@@ -16,15 +20,17 @@ class Hotch
16
20
  end
17
21
 
18
22
  class Memory
19
- def initialize(name, ignore_paths: [])
23
+ def initialize(name, ignore_paths: [], disable_gc: true)
20
24
  @name = name
21
25
  @ignore_paths = Array(ignore_paths || [])
22
26
  @reports = []
23
27
  @started = nil
28
+ @disable_gc = disable_gc
24
29
  end
25
30
 
26
31
  def start
27
32
  return if @started
33
+ GC.disable if @disable_gc
28
34
  ObjectSpace::AllocationTracer.setup [:path, :line, :type]
29
35
  ObjectSpace::AllocationTracer.start
30
36
  @started = true
@@ -34,6 +40,7 @@ class Hotch
34
40
  return unless @started
35
41
  results = ObjectSpace::AllocationTracer.stop
36
42
  @started = nil
43
+ GC.enable if @disable_gc
37
44
  @reports << Report.new(results, @ignore_paths)
38
45
  end
39
46
 
@@ -0,0 +1,28 @@
1
+ require "hotch/memory"
2
+
3
+ class Hotch
4
+ class Memory
5
+ module Minitest
6
+ # Usage in test/test_helper.rb:
7
+ #
8
+ # require 'hotch/memory/minitest'
9
+ #
10
+ # Hotch::Memory::Minitest.run
11
+ # Hotch::Memory::Minitest.run(name: "my name")
12
+ def self.run(**options)
13
+ ::Minitest.singleton_class.prepend Hotch::Memory::Minitest.aggregate(**options)
14
+ end
15
+
16
+ def self.aggregate(**options)
17
+ Module.new do
18
+ define_method(:run_one_method) do |*args|
19
+ options[:aggregate] = true
20
+ Hotch.memory(**options) do
21
+ super(*args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  class Hotch
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Suschlik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stackprof
@@ -85,6 +85,7 @@ files:
85
85
  - images/dry-validation.profile_schema_call_valid.svg
86
86
  - lib/hotch.rb
87
87
  - lib/hotch/memory.rb
88
+ - lib/hotch/memory/minitest.rb
88
89
  - lib/hotch/minitest.rb
89
90
  - lib/hotch/run.rb
90
91
  - lib/hotch/version.rb
@@ -108,9 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  requirements: []
110
111
  rubyforge_project:
111
- rubygems_version: 2.6.11
112
+ rubygems_version: 2.6.13
112
113
  signing_key:
113
114
  specification_version: 4
114
115
  summary: Profile helper
115
116
  test_files: []
116
- has_rdoc: