leak_profiler 0.6.0 → 0.7.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: a0cec55b42b6d790d84c3b54c009da7623040f8aa5c0d3a871eb8d44546d82aa
4
- data.tar.gz: 0f576971b8e6b1734f51ab4a1bdbb8e00d2822a1eedb1e24f53dc7342c25caff
3
+ metadata.gz: '0893023e2e636f17ea493dbb9e48a3663efdec4839aa0f8f92575fbf679d619f'
4
+ data.tar.gz: 5274e289f44e7d0157c337f44b02d8e7628b482d1c3033e22eee8d5a0b3addac
5
5
  SHA512:
6
- metadata.gz: 1636ecd9234f7ba4216c2dbc22892c7aafef11cf26efda7c198dccde3c45cc5273eb2f23974d9524c6d2435f44533c2b20b60f0c70473bc69ebf0101729eddda
7
- data.tar.gz: b05038cb49f6e21a1a44a3dcc8525c3ee6fdb24a8aa4ae0c04b0544f8a4121218dbe80932281970d61260adc05e38042b2272c4502da4d516e71f0569f589748
6
+ metadata.gz: 565d9b09913c43416dce885ce9345e2d2d41a383c35d3238ff3d06609809da29b5e534ffaf6485069c850a9c7f9780f5a6b0221ec81345eb3d88724327bc0134
7
+ data.tar.gz: 762cc7effc4e9d7f0780fa193a60f6f977de4169d7a709d42cb5191e5fe88cc2be78b09603c0815a11774ff07b6888f8a5e75543f719a472cc3929f6ef7cfca7
@@ -22,13 +22,16 @@ class LeakProfiler
22
22
  def report
23
23
  @thread = Thread.start do
24
24
  loop do
25
- allocations = {}
26
-
27
25
  ObjectSpace.trace_object_allocations_start
28
26
  sleep(@interval)
29
27
  ObjectSpace.trace_object_allocations_stop
30
28
 
29
+ allocations = {}
30
+ allocations_by_class = Hash.new { |h, k| h[k] = 0 }
31
+
31
32
  ObjectSpace.each_object.each do |obj|
33
+ allocations_by_class[obj.class] += ObjectSpace.memsize_of(obj)
34
+
32
35
  key = allocated_location(obj)
33
36
  next unless key
34
37
 
@@ -40,6 +43,7 @@ class LeakProfiler
40
43
  allocations[key][:sample_object] = obj
41
44
  end
42
45
 
46
+ report_allocations_class(allocations_by_class)
43
47
  report_allocations(allocations)
44
48
  report_referrer_objects(allocations)
45
49
  end
@@ -48,6 +52,16 @@ class LeakProfiler
48
52
 
49
53
  private
50
54
 
55
+ def report_allocations_class(allocations_by_class)
56
+ return if @max_allocations <= 0
57
+
58
+ @logger.add(Logger::Severity::INFO, "Allocations by class #{"~" * 80}")
59
+ allocations_by_class.sort_by { |_, v| -v }
60
+ .take(@max_allocations).each do |klass, value|
61
+ @logger.add(Logger::Severity::INFO, "#{klass} retains #{value} bytes")
62
+ end
63
+ end
64
+
51
65
  def report_allocations(allocations)
52
66
  return if @max_allocations <= 0
53
67
 
@@ -14,6 +14,8 @@ class LeakProfiler
14
14
 
15
15
  private
16
16
 
17
+ def report_allocations_class: (untyped allocations_by_class) -> untyped
18
+
17
19
  def report_allocations: (untyped allocations) -> untyped
18
20
 
19
21
  def report_referrer_objects: (untyped allocations) -> untyped
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leak_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watson
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.6.7
74
+ rubygems_version: 3.6.9
75
75
  specification_version: 4
76
76
  summary: A simple profiler for Ruby to detect memory leak.
77
77
  test_files: []