leak_profiler 0.1.3 → 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: 062abe3c1684ea42ac45baabb2b11ab19624fd461af76ee89aff981d0dec4cb4
4
- data.tar.gz: e048e567ceae885b4ac91ff8b72b611144e131c9462ba1e33589c12e1fd392bc
3
+ metadata.gz: 89876429b4752e3c46009f0c6237a6868c6ef0416e58c504680a4bf7e75773f7
4
+ data.tar.gz: 6496e8a68442eefdf37b82f1e83e5040b259633e065420fc2d8f20e22596794a
5
5
  SHA512:
6
- metadata.gz: f023bc3f7a64638d2e63d7a9262a59b61b16459c22dca2d1a1bb5a3c846deb0758ffd525f504863107f0d3a1611f243fea0f55f6e2cdfbb801c8e75b51492b0d
7
- data.tar.gz: 47fe07ea97905182c7656f9557efee004906a15ffcd8e56d465ad39eb3fe57cfc7878e3cc094b6779d6fb33dc143dfcc1b420c55cbbeb8fc2cea3f8ed03950c0
6
+ metadata.gz: 27aebb5b8a2e891b19ecf7d5f498efbfc309472f2bd33a40fdafdfec10fb7f5a87c1ee081c03fe5a4dcfc47c972e0c9c288a5ab2b2f554b68f3f32191c229068
7
+ data.tar.gz: 22e1155055df5e750b1f0ac94a6ae0fdf5939402c14caa2ba0bfb43ff2bd10119025c28ccba3862817ad79a8e951cd55d9ad09a1fd54a6748da039a91217c2f6
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
@@ -88,6 +88,22 @@ elapsed [sec],memory usage (rss) [MB]
88
88
  > This uses this uses `ps` command for measurement.
89
89
  > So, this is not supported Windows platform.
90
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
+
104
+ * Arguments:
105
+ * `interval` (default `1`): The interval in seconds for report.
106
+
91
107
  ## Contributing
92
108
 
93
109
  Bug reports and pull requests are welcome on GitHub at https://github.com/Watson1978/leak_profiler.
@@ -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
@@ -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.3
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-05 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: []