memory_profiler 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +16 -0
- data/lib/memory_profiler.rb +13 -1
- data/lib/memory_profiler/reporter.rb +21 -11
- data/lib/memory_profiler/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87e903eb12fc8a885066fe621d8254a4297555fa
|
4
|
+
data.tar.gz: 179a6ccb31c2b71ae9d1ef620be16ce1fa9b4d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac3255e9b9623c580c3c7cdba776a530907936f8d4ff1c78b46ce42b3d7f97b446082d190c74d7a7f050ec7036d2c662f6736ce1db104ccd0cf17cc466f0ad67
|
7
|
+
data.tar.gz: c490d5aa5e024119839aaf8948c27d992c6b40325f8ded2447c228d726145c5668d9ee29d3ac13f8f7d0a8d9c0bc064130fcf67209103e493ad8e4ad5acb73ad
|
data/CHANGELOG.md
CHANGED
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:
|
data/lib/memory_profiler.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
31
|
-
def run(&block)
|
32
|
-
|
34
|
+
def start
|
33
35
|
GC.start
|
34
36
|
GC.disable
|
35
37
|
|
36
|
-
generation = GC.count
|
37
|
-
ObjectSpace.
|
38
|
-
|
39
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
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
|
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.
|
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:
|
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.
|
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+
|