leak_profiler 0.7.1 → 0.7.3

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: 4d2aa447c7220ec2fa47d1a6668218c25f0ed87085408b1222eb8cf8e93661a5
4
- data.tar.gz: fb80d3c0d8ac343883dbabd7142478002aa1d2c8809f85bc723224d2cec9a5da
3
+ metadata.gz: d4f01a98a56470c1b07aa9bc55521c44eae5279e830a32a254336ce472d62c1c
4
+ data.tar.gz: f428e7b17dc7add1e1ababe905b5e7ef01b634535320f6af2e1a13c559b80adf
5
5
  SHA512:
6
- metadata.gz: 20becb0f362b119105b9a3edf7e09e546e37654b6fc0214b3d659652a0189bce421b5c625e07a7ac99c40faf50675a17561ed2dfcd4e20b561e4ac221250cf25
7
- data.tar.gz: b3d314f00426aca63d67d3f0369d2973db37c8a21db1c0da1afdf3d88347f332d27a97c95782e84c380e6b6ba271535137c8264c8e3aa70e95ebbddc9221eb46
6
+ metadata.gz: 3b1ac598321fe43ec9000ad0736372b81ec953312ea3926c8ec391b7356b026e5645739ddff278ea62decf48637f3c2afffbbe52f599db37bd819c37619a9b2d
7
+ data.tar.gz: bdfef29645f51e639583baebd979c62cfdcca8eae034d677e44762273652a70ca097362f933ea41941da77dd0a715f1f20f1011068b37e14a44d29c3befab5b9
@@ -26,16 +26,16 @@ class LeakProfiler
26
26
  sleep(@interval)
27
27
  ObjectSpace.trace_object_allocations_stop
28
28
 
29
- allocations = {}
29
+ allocations = Hash.new { |h, k| h[k] = {} }
30
30
  allocations_by_class = Hash.new { |h, k| h[k] = 0 }
31
31
 
32
32
  ObjectSpace.each_object.each do |obj|
33
- allocations_by_class[obj.class] += ObjectSpace.memsize_of(obj)
33
+ klass = obj_class(obj)
34
+ allocations_by_class[klass] += ObjectSpace.memsize_of(obj)
34
35
 
35
36
  key = allocated_location(obj)
36
37
  next unless key
37
38
 
38
- allocations[key] ||= {}
39
39
  allocations[key][:metrics] ||= Hash.new { |h, k| h[k] = 0 }
40
40
  allocations[key][:metrics][:count] += 1
41
41
  allocations[key][:metrics][:bytes] += ObjectSpace.memsize_of(obj)
@@ -50,6 +50,8 @@ class LeakProfiler
50
50
  allocations.each_value(&:clear)
51
51
  allocations.clear
52
52
  allocations_by_class.clear
53
+ rescue StandardError => e
54
+ @logger.add(Logger::Severity::ERROR, "Error occurred: #{e.message}, backtrace: #{e.backtrace.join("\n")}")
53
55
  end
54
56
  end
55
57
  end
@@ -83,7 +85,8 @@ class LeakProfiler
83
85
  referrer_objects = detect_referrer_objects(value[:sample_object])
84
86
 
85
87
  logs = referrer_objects.map do |r|
86
- " #{r[:referrer_object].class} (allocated at #{r[:referrer_object_allocated_line]})"
88
+ klass = obj_class(r[:referrer_object])
89
+ " #{klass} (allocated at #{r[:referrer_object_allocated_line]})"
87
90
  end
88
91
 
89
92
  @logger.add(Logger::Severity::INFO, "#{key} object is referred at:")
@@ -98,7 +101,7 @@ class LeakProfiler
98
101
  ObjectSpace.each_object.each do |obj|
99
102
  r = ObjectSpace.reachable_objects_from(obj)
100
103
  begin
101
- if r&.include?(object)
104
+ if r&.any? { |o| o.equal?(object) }
102
105
  key = allocated_location(obj)
103
106
  next unless key
104
107
 
@@ -119,5 +122,9 @@ class LeakProfiler
119
122
  def sort(allocations)
120
123
  allocations.sort_by { |_, v| -v[:metrics][:bytes] }
121
124
  end
125
+
126
+ def obj_class(obj)
127
+ obj.respond_to?(:class) ? obj.class : BasicObject
128
+ end
122
129
  end
123
130
  end
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.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watson