leak_profiler 0.6.0 → 0.7.1

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: 4d2aa447c7220ec2fa47d1a6668218c25f0ed87085408b1222eb8cf8e93661a5
4
+ data.tar.gz: fb80d3c0d8ac343883dbabd7142478002aa1d2c8809f85bc723224d2cec9a5da
5
5
  SHA512:
6
- metadata.gz: 1636ecd9234f7ba4216c2dbc22892c7aafef11cf26efda7c198dccde3c45cc5273eb2f23974d9524c6d2435f44533c2b20b60f0c70473bc69ebf0101729eddda
7
- data.tar.gz: b05038cb49f6e21a1a44a3dcc8525c3ee6fdb24a8aa4ae0c04b0544f8a4121218dbe80932281970d61260adc05e38042b2272c4502da4d516e71f0569f589748
6
+ metadata.gz: 20becb0f362b119105b9a3edf7e09e546e37654b6fc0214b3d659652a0189bce421b5c625e07a7ac99c40faf50675a17561ed2dfcd4e20b561e4ac221250cf25
7
+ data.tar.gz: b3d314f00426aca63d67d3f0369d2973db37c8a21db1c0da1afdf3d88347f332d27a97c95782e84c380e6b6ba271535137c8264c8e3aa70e95ebbddc9221eb46
@@ -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,14 +43,29 @@ 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)
49
+
50
+ allocations.each_value(&:clear)
51
+ allocations.clear
52
+ allocations_by_class.clear
45
53
  end
46
54
  end
47
55
  end
48
56
 
49
57
  private
50
58
 
59
+ def report_allocations_class(allocations_by_class)
60
+ return if @max_allocations <= 0
61
+
62
+ @logger.add(Logger::Severity::INFO, "Allocations by class #{"~" * 80}")
63
+ allocations_by_class.sort_by { |_, v| -v }
64
+ .take(@max_allocations).each do |klass, value|
65
+ @logger.add(Logger::Severity::INFO, "#{klass} retains #{value} bytes")
66
+ end
67
+ end
68
+
51
69
  def report_allocations(allocations)
52
70
  return if @max_allocations <= 0
53
71
 
@@ -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.1
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: []