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 +4 -4
- data/lib/leak_profiler/allocations.rb +12 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4f01a98a56470c1b07aa9bc55521c44eae5279e830a32a254336ce472d62c1c
|
4
|
+
data.tar.gz: f428e7b17dc7add1e1ababe905b5e7ef01b634535320f6af2e1a13c559b80adf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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&.
|
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
|