memory_profiler 0.9.7 → 0.9.8

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
  SHA1:
3
- metadata.gz: b3f841c1bfcbaecdaccf8359aa37a7d42605c485
4
- data.tar.gz: 599119026dfb887ffc810d81da2b17a9e71f29cf
3
+ metadata.gz: 87e903eb12fc8a885066fe621d8254a4297555fa
4
+ data.tar.gz: 179a6ccb31c2b71ae9d1ef620be16ce1fa9b4d70
5
5
  SHA512:
6
- metadata.gz: ac957555ecad713d83c891c87bf118f1a00dcf0633d1f18b3d38181b472f654db5218eb3c6494d66ae7b3a5da8bdd9425a4457a3c5e77f69514d8628490cba98
7
- data.tar.gz: 54eb5dc1456d906452b152b000abcaca1d6b229d70e259ca54b2bad36476d69a94edbb2666daa603595a174f468ea7edf619e8afe6554ad3e2606443fbd1d11a
6
+ metadata.gz: ac3255e9b9623c580c3c7cdba776a530907936f8d4ff1c78b46ce42b3d7f97b446082d190c74d7a7f050ec7036d2c662f6736ce1db104ccd0cf17cc466f0ad67
7
+ data.tar.gz: c490d5aa5e024119839aaf8948c27d992c6b40325f8ded2447c228d726145c5668d9ee29d3ac13f8f7d0a8d9c0bc064130fcf67209103e493ad8e4ad5acb73ad
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.8
4
+ - Add optional start/stop sematics to memory profiler api @nicklamuro @dgynn
5
+
3
6
  ## 0.9.7
4
7
  - Improved class name detection for proxy objects, BasicObject objects, and
5
8
  other edge cases @inossidabile @Hamdiakoguz @dgynn
data/README.md CHANGED
@@ -33,6 +33,22 @@ end
33
33
  report.pretty_print
34
34
  ```
35
35
 
36
+ Or, you can use the `.start`/`.stop` API as well:
37
+
38
+ ```ruby
39
+ require 'memory_profiler'
40
+
41
+ MemoryProfiler.start
42
+
43
+ # run your code
44
+
45
+ report = MemoryProfiler.stop
46
+ report.pretty_print
47
+ ```
48
+
49
+ **NOTE:** `.start`/`.stop` can only be run once per report, and `.stop` will
50
+ be the only time you can retrieve the report using this API.
51
+
36
52
  ## Options
37
53
 
38
54
  The report method can take a few options:
@@ -10,9 +10,21 @@ require "memory_profiler/reporter"
10
10
 
11
11
  module MemoryProfiler
12
12
  def self.report(opts={},&block)
13
- opts[:top] ||= 50
14
13
  Reporter.report(opts,&block)
15
14
  end
15
+
16
+ def self.start(opts={})
17
+ unless Reporter.current_reporter
18
+ Reporter.current_reporter = Reporter.new(opts)
19
+ Reporter.current_reporter.start
20
+ end
21
+ end
22
+
23
+ def self.stop
24
+ Reporter.current_reporter.stop if Reporter.current_reporter
25
+ ensure
26
+ Reporter.current_reporter = nil
27
+ end
16
28
  end
17
29
 
18
30
 
@@ -7,7 +7,11 @@ module MemoryProfiler
7
7
  # 5.times { "foo" }
8
8
  # end
9
9
  class Reporter
10
- attr_reader :top, :trace
10
+ class << self
11
+ attr_accessor :current_reporter
12
+ end
13
+
14
+ attr_reader :top, :trace, :generation, :report_results
11
15
 
12
16
  def initialize(opts = {})
13
17
  @top = opts[:top] || 50
@@ -27,16 +31,16 @@ module MemoryProfiler
27
31
  self.new(opts).run(&block)
28
32
  end
29
33
 
30
- # Collects object allocation and memory of ruby code inside of passed block.
31
- def run(&block)
32
-
34
+ def start
33
35
  GC.start
34
36
  GC.disable
35
37
 
36
- generation = GC.count
37
- ObjectSpace.trace_object_allocations do
38
- block.call
39
- end
38
+ @generation = GC.count
39
+ ObjectSpace.trace_object_allocations_start
40
+ end
41
+
42
+ def stop
43
+ ObjectSpace.trace_object_allocations_stop
40
44
  allocated = object_list(generation)
41
45
  retained = StatHash.new.compare_by_identity
42
46
 
@@ -53,9 +57,15 @@ module MemoryProfiler
53
57
  end
54
58
  ObjectSpace.trace_object_allocations_clear
55
59
 
56
- results = Results.new
57
- results.register_results(allocated, retained, top)
58
- results
60
+ @report_results = Results.new
61
+ @report_results.register_results(allocated, retained, top)
62
+ end
63
+
64
+ # Collects object allocation and memory of ruby code inside of passed block.
65
+ def run(&block)
66
+ start
67
+ block.call
68
+ stop
59
69
  end
60
70
 
61
71
  private
@@ -1,3 +1,3 @@
1
1
  module MemoryProfiler
2
- VERSION = "0.9.7"
2
+ VERSION = "0.9.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memory_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-06 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Memory profiling routines for Ruby 2.1+
14
14
  email:
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.5.1
53
+ rubygems_version: 2.5.2
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: Memory profiling routines for Ruby 2.1+