leak_profiler 0.7.0 → 0.7.2
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 +15 -4
- 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: 4617e25a441cc0afc52ee22fd4e6cc809f0461b0ded79b7dfd691465a00ffb01
|
4
|
+
data.tar.gz: 9c1fdcad31276d8995a3c21de17d6467177460c22971e65a9739aef0b549f54a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c3ffc40e9df1d8531b3833d90306979b8ea79a2574335ae38fcce4104d6574c85d46b54ac42725a67cccca51690972f029e947985d14a8e76a3efdcbdd4892
|
7
|
+
data.tar.gz: 145340854bcfee96d1a94f86ed669f83bbe374f1bdf62d4bc78afc375a0600059024b7b339664ecaa9f9329e02cec0ef9325a1d8c3a9a302be92d6b7cdb9cbf0
|
@@ -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)
|
@@ -46,6 +46,12 @@ class LeakProfiler
|
|
46
46
|
report_allocations_class(allocations_by_class)
|
47
47
|
report_allocations(allocations)
|
48
48
|
report_referrer_objects(allocations)
|
49
|
+
|
50
|
+
allocations.each_value(&:clear)
|
51
|
+
allocations.clear
|
52
|
+
allocations_by_class.clear
|
53
|
+
rescue StandardError => e
|
54
|
+
@logger.add(Logger::Severity::ERROR, "Error occurred: #{e.message}, backtrace: #{e.backtrace.join("\n")}")
|
49
55
|
end
|
50
56
|
end
|
51
57
|
end
|
@@ -79,7 +85,8 @@ class LeakProfiler
|
|
79
85
|
referrer_objects = detect_referrer_objects(value[:sample_object])
|
80
86
|
|
81
87
|
logs = referrer_objects.map do |r|
|
82
|
-
|
88
|
+
klass = obj_class(r[:referrer_object])
|
89
|
+
" #{klass} (allocated at #{r[:referrer_object_allocated_line]})"
|
83
90
|
end
|
84
91
|
|
85
92
|
@logger.add(Logger::Severity::INFO, "#{key} object is referred at:")
|
@@ -115,5 +122,9 @@ class LeakProfiler
|
|
115
122
|
def sort(allocations)
|
116
123
|
allocations.sort_by { |_, v| -v[:metrics][:bytes] }
|
117
124
|
end
|
125
|
+
|
126
|
+
def obj_class(obj)
|
127
|
+
obj.respond_to?(:class) ? obj.class : BasicObject
|
128
|
+
end
|
118
129
|
end
|
119
130
|
end
|