memory_profiler 1.0.1 → 1.1.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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +14 -5
- data/lib/memory_profiler/autorun.rb +16 -0
- data/lib/memory_profiler/cli.rb +23 -26
- data/lib/memory_profiler/helpers.rb +8 -26
- data/lib/memory_profiler/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5a66fca1aa2343e5380049e2079a9949bf315ab053db4106ab591ec8f1a3b87
|
|
4
|
+
data.tar.gz: cf5d847031900969429d4aa295afe385375bf18582444dcc559e4171561c23b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27898d1f93136732b68dfc3c624b20865c9a5772f017204afefe23e61295e5d00775c6b3ba73e4747d6cc5df862cc251ba6046313d54e6893187aab075442eb6
|
|
7
|
+
data.tar.gz: 4c2f5c257ed8a9be18b06bbe3931527e1da026ad431e00e05c10e4a3938eaa4329cc65e7fd79c89257d2994dcacb5d9e3c5d363f10993625ff362e778750a82b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0 - 17-09-2024
|
|
4
|
+
|
|
5
|
+
- Remove EOL Rubies: < 3.1 are no longer supported (use an earlier version of the gem if needed)
|
|
6
|
+
|
|
7
|
+
## 1.0.2 - 17-06-2024
|
|
8
|
+
|
|
9
|
+
- Add ability to profile commands via CLI @fatkodima
|
|
10
|
+
|
|
3
11
|
## 1.0.1 - 23-10-2022
|
|
4
12
|
|
|
5
13
|
- Adapts tests to Ruby 3.0 / 3.1
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://github.com/SamSaffron/memory_profiler/actions/workflows/ci.yml)
|
|
2
2
|
[](https://rubygems.org/gems/memory_profiler)
|
|
3
3
|
|
|
4
4
|
# MemoryProfiler
|
|
@@ -7,7 +7,7 @@ A memory profiler for Ruby
|
|
|
7
7
|
|
|
8
8
|
## Requirements
|
|
9
9
|
|
|
10
|
-
Ruby(MRI) Version
|
|
10
|
+
Ruby(MRI) Version 3.1.0 and above.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -32,14 +32,23 @@ There are two ways to use `memory_profiler`:
|
|
|
32
32
|
### Command Line
|
|
33
33
|
|
|
34
34
|
The easiest way to use memory_profiler is via the command line, which requires no modifications to your program. The basic usage is:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
$ ruby-memory-profiler [options] run [--] command [command-options]
|
|
35
38
|
```
|
|
36
|
-
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
$ ruby-memory-profiler --pretty run -- rubocop --cache false
|
|
44
|
+
|
|
45
|
+
$ ruby-memory-profiler --max=10 --pretty run -- ruby notify_users.rb 1 2 3 --quiet
|
|
37
46
|
```
|
|
38
|
-
Where `script.rb` is the program you want to profile.
|
|
39
47
|
|
|
40
48
|
For a full list of options, execute the following command:
|
|
49
|
+
|
|
41
50
|
```
|
|
42
|
-
ruby-memory-profiler -h
|
|
51
|
+
$ ruby-memory-profiler -h
|
|
43
52
|
```
|
|
44
53
|
|
|
45
54
|
### Convenience API
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "memory_profiler"
|
|
4
|
+
|
|
5
|
+
def deserialize_hash(data)
|
|
6
|
+
Marshal.load(data.unpack1("m0")) if data
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
options = deserialize_hash(ENV["MEMORY_PROFILER_OPTIONS"]) || {}
|
|
10
|
+
|
|
11
|
+
at_exit do
|
|
12
|
+
report = MemoryProfiler.stop
|
|
13
|
+
report.pretty_print(**options)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
MemoryProfiler.start(options)
|
data/lib/memory_profiler/cli.rb
CHANGED
|
@@ -14,20 +14,6 @@ module MemoryProfiler
|
|
|
14
14
|
ignore_files: "memory_profiler/lib"
|
|
15
15
|
}.freeze
|
|
16
16
|
|
|
17
|
-
REPORTER_KEYS = [
|
|
18
|
-
:top, :trace, :ignore_files, :allow_files
|
|
19
|
-
].freeze
|
|
20
|
-
|
|
21
|
-
RESULTS_KEYS = [
|
|
22
|
-
:to_file, :color_output, :retained_strings, :allocated_strings,
|
|
23
|
-
:detailed_report, :scale_bytes, :normalize_paths
|
|
24
|
-
].freeze
|
|
25
|
-
|
|
26
|
-
private_constant :BIN_NAME, :VERSION_INFO,:STATUS_SUCCESS, :STATUS_ERROR,
|
|
27
|
-
:DEFAULTS, :REPORTER_KEYS, :RESULTS_KEYS
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
|
|
31
17
|
def run(argv)
|
|
32
18
|
options = {}
|
|
33
19
|
parser = option_parser(options)
|
|
@@ -43,17 +29,24 @@ module MemoryProfiler
|
|
|
43
29
|
return STATUS_ERROR
|
|
44
30
|
end
|
|
45
31
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
if script == "run"
|
|
33
|
+
# We are profiling a command.
|
|
34
|
+
profile_command(options, argv)
|
|
35
|
+
else
|
|
36
|
+
# We are profiling a ruby file.
|
|
37
|
+
begin
|
|
38
|
+
MemoryProfiler.start(options)
|
|
39
|
+
load(script)
|
|
40
|
+
ensure
|
|
41
|
+
report = MemoryProfiler.stop
|
|
42
|
+
report.pretty_print(**options)
|
|
43
|
+
end
|
|
44
|
+
STATUS_SUCCESS
|
|
45
|
+
end
|
|
50
46
|
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::MissingArgument => e
|
|
51
47
|
puts parser
|
|
52
48
|
puts e.message
|
|
53
49
|
STATUS_ERROR
|
|
54
|
-
ensure
|
|
55
|
-
report = MemoryProfiler.stop
|
|
56
|
-
report&.pretty_print(**results_options(options))
|
|
57
50
|
end
|
|
58
51
|
|
|
59
52
|
private
|
|
@@ -66,7 +59,7 @@ module MemoryProfiler
|
|
|
66
59
|
A Memory Profiler for Ruby
|
|
67
60
|
|
|
68
61
|
Usage:
|
|
69
|
-
#{BIN_NAME} [options]
|
|
62
|
+
#{BIN_NAME} [options] run [--] command [command-options]
|
|
70
63
|
BANNER
|
|
71
64
|
|
|
72
65
|
opts.separator ""
|
|
@@ -138,12 +131,16 @@ module MemoryProfiler
|
|
|
138
131
|
end
|
|
139
132
|
end
|
|
140
133
|
|
|
141
|
-
def
|
|
142
|
-
|
|
134
|
+
def profile_command(options, argv)
|
|
135
|
+
env = {}
|
|
136
|
+
env["MEMORY_PROFILER_OPTIONS"] = serialize_hash(options) if options.any?
|
|
137
|
+
gem_path = File.expand_path('../', __dir__)
|
|
138
|
+
env["RUBYOPT"] = "-I #{gem_path} -r memory_profiler/autorun #{ENV['RUBYOPT']}"
|
|
139
|
+
exec(env, *argv)
|
|
143
140
|
end
|
|
144
141
|
|
|
145
|
-
def
|
|
146
|
-
|
|
142
|
+
def serialize_hash(hash)
|
|
143
|
+
[Marshal.dump(hash)].pack("m0")
|
|
147
144
|
end
|
|
148
145
|
end
|
|
149
146
|
end
|
|
@@ -6,7 +6,6 @@ module MemoryProfiler
|
|
|
6
6
|
def initialize
|
|
7
7
|
@gem_guess_cache = Hash.new
|
|
8
8
|
@location_cache = Hash.new { |h, k| h[k] = Hash.new.compare_by_identity }
|
|
9
|
-
@class_name_cache = Hash.new.compare_by_identity
|
|
10
9
|
@string_cache = Hash.new
|
|
11
10
|
end
|
|
12
11
|
|
|
@@ -30,34 +29,17 @@ module MemoryProfiler
|
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
KERNEL_CLASS_METHOD = Kernel.instance_method(:class)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
klass = KERNEL_CLASS_METHOD.bind_call(obj)
|
|
39
|
-
end
|
|
40
|
-
klass
|
|
41
|
-
end
|
|
42
|
-
else
|
|
43
|
-
def object_class(obj)
|
|
44
|
-
klass = obj.class rescue nil
|
|
45
|
-
unless Class === klass
|
|
46
|
-
# attempt to determine the true Class when .class returns something other than a Class
|
|
47
|
-
klass = KERNEL_CLASS_METHOD.bind(obj).call
|
|
48
|
-
end
|
|
49
|
-
klass
|
|
32
|
+
def object_class(obj)
|
|
33
|
+
klass = obj.class rescue nil
|
|
34
|
+
unless Class === klass
|
|
35
|
+
# attempt to determine the true Class when .class returns something other than a Class
|
|
36
|
+
klass = KERNEL_CLASS_METHOD.bind_call(obj)
|
|
50
37
|
end
|
|
38
|
+
klass
|
|
51
39
|
end
|
|
52
40
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
|
|
56
|
-
end
|
|
57
|
-
else
|
|
58
|
-
def lookup_class_name(klass)
|
|
59
|
-
@class_name_cache[klass] ||= ((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
|
|
60
|
-
end
|
|
41
|
+
def lookup_class_name(klass)
|
|
42
|
+
((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
|
|
61
43
|
end
|
|
62
44
|
|
|
63
45
|
def lookup_string(obj)
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: memory_profiler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
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: 2024-09-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description: Memory profiling routines for Ruby
|
|
13
|
+
description: Memory profiling routines for Ruby 3.1+
|
|
14
14
|
email:
|
|
15
15
|
- sam.saffron@gmail.com
|
|
16
16
|
executables:
|
|
@@ -23,6 +23,7 @@ files:
|
|
|
23
23
|
- README.md
|
|
24
24
|
- bin/ruby-memory-profiler
|
|
25
25
|
- lib/memory_profiler.rb
|
|
26
|
+
- lib/memory_profiler/autorun.rb
|
|
26
27
|
- lib/memory_profiler/cli.rb
|
|
27
28
|
- lib/memory_profiler/helpers.rb
|
|
28
29
|
- lib/memory_profiler/monochrome.rb
|
|
@@ -36,7 +37,8 @@ files:
|
|
|
36
37
|
homepage: https://github.com/SamSaffron/memory_profiler
|
|
37
38
|
licenses:
|
|
38
39
|
- MIT
|
|
39
|
-
metadata:
|
|
40
|
+
metadata:
|
|
41
|
+
changelog_uri: https://github.com/SamSaffron/memory_profiler/blob/master/CHANGELOG.md
|
|
40
42
|
post_install_message:
|
|
41
43
|
rdoc_options: []
|
|
42
44
|
require_paths:
|
|
@@ -45,15 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
45
47
|
requirements:
|
|
46
48
|
- - ">="
|
|
47
49
|
- !ruby/object:Gem::Version
|
|
48
|
-
version:
|
|
50
|
+
version: 3.1.0
|
|
49
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
52
|
requirements:
|
|
51
53
|
- - ">="
|
|
52
54
|
- !ruby/object:Gem::Version
|
|
53
55
|
version: '0'
|
|
54
56
|
requirements: []
|
|
55
|
-
rubygems_version: 3.
|
|
57
|
+
rubygems_version: 3.5.11
|
|
56
58
|
signing_key:
|
|
57
59
|
specification_version: 4
|
|
58
|
-
summary: Memory profiling routines for Ruby
|
|
60
|
+
summary: Memory profiling routines for Ruby 3.1+
|
|
59
61
|
test_files: []
|