rails_tracepoint_stack 0.1.1 → 0.1.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/rails_tracepoint_stack.rb +34 -11
- 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: eeb97f7192b4379bdebd15da84477298535c897236b3a3acb2735f89db5ebd7b
|
4
|
+
data.tar.gz: 809557f925e2fd9e85302eef08497792ccc525b3f5b25662266fc4f6cc76e770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a903d86229c926bbfcbcbeb75971c3aa2891b35327fe6608ce29c6b88f2c7f3e97c135d66c9783f0632fd9286a88df558be187389b9332f0407431878ff65cdc
|
7
|
+
data.tar.gz: d65ba8f3c6fb40c9c2a505dd8cc771f8de357dc0dc5de724ba7a118f8f772dd66773c4dd6cf087d8c3c3bce4c05d75bc35fa0cf7d52c98cb874213204b8b70ac
|
@@ -1,18 +1,41 @@
|
|
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
|
+
tracer.disable
|
18
41
|
end
|