rails_tracepoint_stack 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_tracepoint_stack.rb +33 -10
- 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: bf771ac87351c7b8d15333adc88f0c0aa083b249d9522d2ddcf0ded1e979a8a8
|
4
|
+
data.tar.gz: '092993f140a76382f146b2afe8c5602d0160d63098b908e089bbc04a5b0e5b53'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa4d9cfeed7f91e7207c553468ab8bdd31a58a2a57428a3a26bf5deb5c7902b3c8ac44ce2364fe2097eeb3bc242663c8c2564378e063e61c023f27d10204781
|
7
|
+
data.tar.gz: fba92e74f76914217347a89eb308f371ccc543c5b69271be363f90585801826787dbf0ba9898d40a5510681502f86598537158e4ba4ae89555b00b59ae1c1a70
|
@@ -1,17 +1,40 @@
|
|
1
|
-
gem_paths = Bundler.load.specs.map(&:full_gem_path)
|
2
|
-
ruby_lib_path = RbConfig::CONFIG['rubylibdir']
|
3
1
|
|
4
|
-
|
5
|
-
|
2
|
+
class TracepointStack
|
3
|
+
def initialize
|
4
|
+
@gem_paths = Bundler.load.specs.map(&:full_gem_path)
|
5
|
+
@ruby_lib_path = RbConfig::CONFIG['rubylibdir']
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def tracer
|
9
|
+
@trace ||= TracePoint.new(:call) do |tp|
|
10
|
+
next if start_with_to_ignore_prefixes?(tp) || from_gempath_or_lib_path?(tp)
|
11
|
+
|
12
|
+
params = fetch_params(tp)
|
13
|
+
|
14
|
+
puts "called: #{tp.defined_class}##{tp.method_id} in #{tp.path}:#{tp.lineno} with params: #{params}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
attr_reader :gem_paths, :ruby_lib_path
|
20
|
+
|
21
|
+
def fetch_params(tp)
|
22
|
+
tp.binding.local_variables.map { |var|
|
23
|
+
[var, tp.binding.local_variable_get(var)]
|
24
|
+
}.to_h
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_with_to_ignore_prefixes?(tp)
|
28
|
+
tp.path.start_with?('<internal:') || tp.path == '(eval)'
|
29
|
+
end
|
30
|
+
|
31
|
+
def from_gempath_or_lib_path?(tp)
|
32
|
+
gem_paths.any? { |path| tp.path.start_with?(path) } || tp.path.start_with?(ruby_lib_path)
|
33
|
+
end
|
12
34
|
end
|
13
35
|
|
14
|
-
|
36
|
+
tracer = TracepointStack.new.tracer
|
37
|
+
tracer.enable
|
15
38
|
|
16
39
|
at_exit do
|
17
40
|
trace.disable
|