leak_profiler 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f38e71ee118af9012f16f7094a529faab161886bcf96ce02aedeafc6f513f4c6
4
- data.tar.gz: 52b68f566fcaf407bb5ae1bd7434f1316ea341be6d0c274c5a0b3faf36b679bf
3
+ metadata.gz: 89876429b4752e3c46009f0c6237a6868c6ef0416e58c504680a4bf7e75773f7
4
+ data.tar.gz: 6496e8a68442eefdf37b82f1e83e5040b259633e065420fc2d8f20e22596794a
5
5
  SHA512:
6
- metadata.gz: 37b790174706f1b8bee068581a5ecf26662a52abdd16892c1108ca8972f0bb137d94267af50362d955a066c7909dd6acb88e0d8d5435ea446f6b47fed9d0fceb
7
- data.tar.gz: 1104d9a5a231bca9404fa8753fe93ebcb4a606f6b10823a15ec678613fe448aaa814ac6376aab382e16c327246915c01aac448bda1cf059528f15a27173a568f
6
+ metadata.gz: 27aebb5b8a2e891b19ecf7d5f498efbfc309472f2bd33a40fdafdfec10fb7f5a87c1ee081c03fe5a4dcfc47c972e0c9c288a5ab2b2f554b68f3f32191c229068
7
+ data.tar.gz: 22e1155055df5e750b1f0ac94a6ae0fdf5939402c14caa2ba0bfb43ff2bd10119025c28ccba3862817ad79a8e951cd55d9ad09a1fd54a6748da039a91217c2f6
data/.rubocop.yml CHANGED
@@ -14,6 +14,9 @@ Metrics:
14
14
  Style/Copyright:
15
15
  Enabled: false
16
16
 
17
+ Style/ImplicitRuntimeError:
18
+ Enabled: false
19
+
17
20
  Style/MissingElse:
18
21
  Enabled: false
19
22
 
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2025-03-31 02:21:42 UTC using RuboCop version 1.75.1.
3
+ # on 2025-04-26 03:09:17 UTC using RuboCop version 1.75.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
9
+ # Offense count: 4
10
10
  # Configuration parameters: AllowedConstants.
11
11
  Style/Documentation:
12
12
  Exclude:
@@ -14,9 +14,10 @@ Style/Documentation:
14
14
  - 'test/**/*'
15
15
  - 'lib/leak_profiler/allocations.rb'
16
16
  - 'lib/leak_profiler/leak_profiler.rb'
17
+ - 'lib/leak_profiler/memory_memsize.rb'
17
18
  - 'lib/leak_profiler/memory_usage.rb'
18
19
 
19
- # Offense count: 4
20
+ # Offense count: 6
20
21
  # Configuration parameters: AllowedMethods, RequireForNonPublicMethods.
21
22
  Style/DocumentationMethod:
22
23
  Exclude:
@@ -24,4 +25,5 @@ Style/DocumentationMethod:
24
25
  - 'test/**/*'
25
26
  - 'lib/leak_profiler/allocations.rb'
26
27
  - 'lib/leak_profiler/leak_profiler.rb'
28
+ - 'lib/leak_profiler/memory_memsize.rb'
27
29
  - 'lib/leak_profiler/memory_usage.rb'
data/README.md CHANGED
@@ -66,6 +66,10 @@ Referrers ----------------------------------------------------------------------
66
66
  * `max_referrers` (default `3`): Outputs the number of references in order of the amount of memory used.
67
67
  * `report` (defalut `nil`): Specify the logger object if you want to use custom logger.
68
68
 
69
+ > [!WARNING]
70
+ > This uses `ObjectSpace.allocation_sourcefile` method to measurement.
71
+ > It can't get an object allocated information in Ruby core API / C extension library API.
72
+
69
73
  ### `LeakProfiler#report_rss`
70
74
  This method outputs the RSS (Resident Set Size) of the process with CSV format, like:
71
75
 
@@ -77,6 +81,26 @@ elapsed [sec],memory usage (rss) [MB]
77
81
  3,55.90234375
78
82
  ```
79
83
 
84
+ * Arguments:
85
+ * `interval` (default `1`): The interval in seconds for report.
86
+
87
+ > [!WARNING]
88
+ > This uses this uses `ps` command for measurement.
89
+ > So, this is not supported Windows platform.
90
+
91
+
92
+ ### `LeakProfiler#report_memsize`
93
+ This method outputs `ObjectSpace.memsize_of_all` values with CSV format, like:
94
+
95
+ ```
96
+ elapsed [sec],ObjectSpace.memsize_of_all values [MB]
97
+ 0,11.435378074645996
98
+ 1,12.78317642211914
99
+ 2,11.785511016845703
100
+ 3,11.785999298095703
101
+ 4,11.786487579345703
102
+ ```
103
+
80
104
  * Arguments:
81
105
  * `interval` (default `1`): The interval in seconds for report.
82
106
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'allocations'
4
+ require_relative 'memory_memsize'
4
5
  require_relative 'memory_usage'
5
6
  require 'fileutils'
6
7
  require 'logger'
@@ -24,4 +25,10 @@ class LeakProfiler
24
25
 
25
26
  self
26
27
  end
28
+
29
+ def report_memsize(interval: 1)
30
+ LeakProfiler::MemoryMemsize.new(output_dir: @output_dir, interval: interval).report
31
+
32
+ self
33
+ end
27
34
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'objspace'
4
+
5
+ class LeakProfiler
6
+ class MemoryMemsize
7
+ def initialize(output_dir:, interval:)
8
+ @output_dir = output_dir
9
+ @interval = interval
10
+ end
11
+
12
+ def report
13
+ pid = Process.pid
14
+
15
+ Thread.new do
16
+ i = 0
17
+ File.open(File.expand_path(File.join(@output_dir, "memory-memsize-#{pid}.csv")), 'w') do |f|
18
+ f.puts('elapsed [sec],ObjectSpace.memsize_of_all values [MB]')
19
+
20
+ loop do
21
+ memsize = Float(ObjectSpace.memsize_of_all) / (1024 * 1024)
22
+
23
+ f.puts("#{i},#{memsize}")
24
+ i += @interval
25
+ sleep(@interval)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -8,6 +8,8 @@ class LeakProfiler
8
8
  end
9
9
 
10
10
  def report
11
+ raise('Not supported Windows platform because this uses `ps` command for measurement.') if /mingw/.match?(RUBY_PLATFORM)
12
+
11
13
  pid = Process.pid
12
14
 
13
15
  Thread.new do
@@ -0,0 +1,10 @@
1
+ class LeakProfiler
2
+ def initialize: (?output_dir: String) -> void
3
+
4
+ # TODO: Use valid type for logger
5
+ def report: (?interval: Integer, ?max_allocations: Integer, ?max_referrers: Integer, ?logger: Object) -> self
6
+
7
+ def report_rss: (?interval: Integer) -> self
8
+
9
+ def report_memsize: (?interval: Integer) -> self
10
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leak_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watson
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: logger
@@ -38,7 +38,9 @@ files:
38
38
  - lib/leak_profiler.rb
39
39
  - lib/leak_profiler/allocations.rb
40
40
  - lib/leak_profiler/leak_profiler.rb
41
+ - lib/leak_profiler/memory_memsize.rb
41
42
  - lib/leak_profiler/memory_usage.rb
43
+ - sig/leak_profiler.rbs
42
44
  homepage: https://github.com/Watson1978/leak_profiler
43
45
  licenses:
44
46
  - MIT
@@ -60,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
62
64
  requirements: []
63
- rubygems_version: 3.6.2
65
+ rubygems_version: 3.6.7
64
66
  specification_version: 4
65
67
  summary: A simple profiler for Ruby to detect memory leak.
66
68
  test_files: []