memory_profiler 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -3
- data/lib/memory_profiler/reporter.rb +7 -1
- data/lib/memory_profiler/results.rb +9 -6
- data/lib/memory_profiler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b6b21cb4cecfbff39a58884f5c67e379ee246db
|
4
|
+
data.tar.gz: 17fc4f5587f41ce22ebd0445d4a8b207388447b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 842bfb7550e047af23d8db0ac5522da9bf14b39e82d88a332627d679ea6fecd39ba445971656f4758ad0194f30a91f45cbf81d0641934f89f7fba01d7ead7d8e
|
7
|
+
data.tar.gz: 754a46b32d671bcee62ea5704a8c636e7d1f20b2d4981cd1f376dc9d1f5156ce54a46469e68eede880d3e2801e5dcf0a6e293dc78eb9d125cb6e95bfcfa44569
|
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# MemoryProfiler
|
2
2
|
|
3
|
-
A memory profiler for Ruby
|
3
|
+
A memory profiler for Ruby
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/SamSaffron/memory_profiler.png?branch=master)](https://travis-ci.org/SamSaffron/memory_profiler)
|
6
6
|
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
Ruby(MRI) Version 2.1.0 and above.
|
10
|
+
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application's Gemfile:
|
@@ -29,7 +33,59 @@ end
|
|
29
33
|
report.pretty_print
|
30
34
|
```
|
31
35
|
|
32
|
-
|
36
|
+
## Options
|
37
|
+
|
38
|
+
You can use `allow_files` option for displaying only lines which contain string or array with strings:
|
39
|
+
|
40
|
+
```
|
41
|
+
pry> require 'memory_profiler'
|
42
|
+
pry> MemoryProfiler.report(allow_files: 'rubygems'){ require 'mime-types' }.pretty_print
|
43
|
+
Total allocated 82375
|
44
|
+
Total retained 22618
|
45
|
+
|
46
|
+
allocated memory by gem
|
47
|
+
-----------------------------------
|
48
|
+
rubygems x 305879
|
49
|
+
|
50
|
+
allocated memory by file
|
51
|
+
-----------------------------------
|
52
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb x 285433
|
53
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems/basic_specification.rb x 18597
|
54
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems.rb x 2218
|
55
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems/specification.rb x 1169
|
56
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems/defaults.rb x 520
|
57
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb x 80
|
58
|
+
/home/sam/.rbenv/versions/2.1.0-github/lib/ruby/2.1.0/rubygems/version.rb x 80
|
59
|
+
|
60
|
+
. . .
|
61
|
+
```
|
62
|
+
|
63
|
+
Also you can print report to file. For this use `pretty_print` method with `to_file` option and `path_to_your_log_file` string:
|
64
|
+
```
|
65
|
+
$ pry
|
66
|
+
pry> require 'memory_profiler'
|
67
|
+
pry> MemoryProfiler.report(allow_files: 'rubygems'){ require 'mime-types' }.pretty_print(to_file: 'path_to_your_log_file')
|
68
|
+
|
69
|
+
$ less my_report.txt
|
70
|
+
Total allocated 82375
|
71
|
+
Total retained 22618
|
72
|
+
|
73
|
+
allocated memory by gem
|
74
|
+
-----------------------------------
|
75
|
+
rubygems x 305879
|
76
|
+
|
77
|
+
. . .
|
78
|
+
```
|
79
|
+
|
80
|
+
Other options include:
|
81
|
+
|
82
|
+
* `top`: maximum number of entries to display in a report
|
83
|
+
* `trace`: an array of classes for which you explicitly want to trace object allocations
|
84
|
+
* `ignore_files`: a regular expression used to exclude certain files from tracing (opposite of `allow_files`)
|
85
|
+
|
86
|
+
Check out `Reporter#new` for more details.
|
87
|
+
|
88
|
+
## Example Session
|
33
89
|
|
34
90
|
You can easily use memory_profiler to profile require impact of a gem, for example:
|
35
91
|
|
@@ -316,7 +372,7 @@ Memory profiler also performs some String analysis to help you find strings that
|
|
316
372
|
|
317
373
|
|
318
374
|
### 0.0.4
|
319
|
-
- Added
|
375
|
+
- Added compatibility with released version of Ruby 2.1.0
|
320
376
|
- Cleanup to use latest APIs available in 2.1.0
|
321
377
|
|
322
378
|
### 0.0.3
|
@@ -14,6 +14,7 @@ module MemoryProfiler
|
|
14
14
|
@top = opts[:top] || 50
|
15
15
|
@trace = opts[:trace]
|
16
16
|
@ignore_files = opts[:ignore_files]
|
17
|
+
@allow_files = Array(opts[:allow_files])
|
17
18
|
end
|
18
19
|
|
19
20
|
# Helper for generating new reporter and running against block
|
@@ -73,6 +74,11 @@ module MemoryProfiler
|
|
73
74
|
@ignore_files && @ignore_files =~ file
|
74
75
|
end
|
75
76
|
|
77
|
+
def allow_file?(file)
|
78
|
+
return true if @allow_files.empty?
|
79
|
+
!/#{@allow_files.join('|')}/.match(file).to_s.empty?
|
80
|
+
end
|
81
|
+
|
76
82
|
# Iterates through objects in memory of a given generation.
|
77
83
|
# Stores results along with meta data of objects collected.
|
78
84
|
def object_list(generation, rvalue_size)
|
@@ -93,7 +99,7 @@ module MemoryProfiler
|
|
93
99
|
|
94
100
|
objs.each do |obj|
|
95
101
|
file = ObjectSpace.allocation_sourcefile(obj)
|
96
|
-
next if ignore_file?(file)
|
102
|
+
next if !allow_file?(file) || ignore_file?(file)
|
97
103
|
|
98
104
|
line = ObjectSpace.allocation_sourceline(obj)
|
99
105
|
class_path = ObjectSpace.allocation_class_path(obj)
|
@@ -68,15 +68,17 @@ module MemoryProfiler
|
|
68
68
|
def string_report(data, top)
|
69
69
|
data
|
70
70
|
.reject { |id, stat| stat.class_name != "String" }
|
71
|
-
.map { |id, stat| [ObjectSpace._id2ref(id), "#{stat.file}:#{stat.line}"] }
|
71
|
+
.map { |id, stat| [begin; ObjectSpace._id2ref(id); rescue "__UNKNOWN__"; end, "#{stat.file}:#{stat.line}"] }
|
72
72
|
.group_by { |string, location| string }
|
73
73
|
.sort_by { |string, list| -list.count }
|
74
74
|
.first(top)
|
75
75
|
.map { |string, list| [string, list.group_by { |str, location| location }
|
76
|
-
|
76
|
+
.map { |location, locations| [location, locations.count] }] }
|
77
77
|
end
|
78
78
|
|
79
|
-
def pretty_print(io = STDOUT, options
|
79
|
+
def pretty_print(io = STDOUT, **options)
|
80
|
+
io = File.open(options[:to_file], "w") if options[:to_file]
|
81
|
+
|
80
82
|
color_output = options.fetch(:color_output) { io.respond_to?(:isatty) && io.isatty }
|
81
83
|
@colorize = color_output ? Polychrome.new : Monochrome.new
|
82
84
|
|
@@ -87,14 +89,15 @@ module MemoryProfiler
|
|
87
89
|
.product(["memory", "objects"])
|
88
90
|
.product(["gem", "file", "location"])
|
89
91
|
.each do |(type, metric), name|
|
90
|
-
|
91
|
-
|
92
|
+
dump "#{type} #{metric} by #{name}", self.send("#{type}_#{metric}_by_#{name}"), io
|
93
|
+
end
|
92
94
|
|
93
95
|
io.puts
|
94
96
|
dump_strings(io, "Allocated", strings_allocated)
|
95
97
|
io.puts
|
96
98
|
dump_strings(io, "Retained", strings_retained)
|
97
|
-
|
99
|
+
|
100
|
+
io.close if io.is_a? File
|
98
101
|
end
|
99
102
|
|
100
103
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|