tracia 0.2.7 → 0.2.16

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: 978a7b204dede4d5be2b8a78975266d59a16c0e93363b3e831d05b4d2cab7584
4
- data.tar.gz: eb99548c2f027ca0242c513bb95369b3737fa12adf827c61eeb742341e16bee8
3
+ metadata.gz: b8d300497cc3f967c73f989925819a051d16ab7a9948b38068d37042aef2058d
4
+ data.tar.gz: 279e441cef317891df0030997cf88078292bee6544975635abf519d4cfc0f006
5
5
  SHA512:
6
- metadata.gz: 990222bdcf8274d78bf63d68e97d3a7255c04a6da833f3638a6d82cbebb13f0a5f28aaa4039316975fa1543fac96b4771f630d96633c4bce54e6043c6e8eaea7
7
- data.tar.gz: b613ca56e63b58cce4bb5cfca0a91f2c9113a00fbb6206d5f6bab3e7f6010c953c6fdd35966b2de3520477a04cff416188acc22df93b22c2214baacb0485c92e
6
+ metadata.gz: 194d257a120813ad1a7a676f12652bb1cd5ff25a226314217d7c0657fe526a2100ebe18b095561371d8dbd9fc1cdcb601cff38674dd89a2eb1c614cf9d2269f3
7
+ data.tar.gz: 7c4d3c5b3cb21bf6299f1358d1fd40ff450fcb073043de436f43332801e48712820a32f2bb9657cf472f99ad7d2307b5be5aaac9d1e8f0bd7ea84fc9eebf7a5d
data/README.md CHANGED
@@ -76,6 +76,16 @@ Tracia.start(logger: MyLogger.new(db_connection)) do
76
76
  end
77
77
  ```
78
78
 
79
+ ### Log `raise`
80
+
81
+ By default, Tracia log `raise` event via `TracePoint`. You can disable this feature by `trace_point: false`
82
+
83
+ ```ruby
84
+ Tracia.start(trace_point: false) do
85
+ # ...
86
+ end
87
+ ```
88
+
79
89
  ## Development
80
90
 
81
91
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,9 @@
1
+ class Tracia
2
+ class FakeTracePoint
3
+ def enable
4
+ end
5
+
6
+ def disable
7
+ end
8
+ end
9
+ end
@@ -4,9 +4,7 @@ class Tracia
4
4
  module GemPaths
5
5
  ABSTRACTS = {}
6
6
 
7
- ::YAML.load(`gem env`.gsub(/=>/, ':'))['RubyGems Environment']
8
- .detect{ |hash| hash.has_key?('GEM PATHS') }['GEM PATHS']
9
- .each_with_index { |path, i| ABSTRACTS["GemPath#{i}"] = path }
7
+ ::Gem.path.each_with_index { |path, i| ABSTRACTS["GemPath#{i}"] = path }
10
8
 
11
9
  class << self
12
10
  def shorten(location)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Tracia
4
- VERSION = "0.2.7"
4
+ VERSION = "0.2.16"
5
5
  end
data/lib/tracia.rb CHANGED
@@ -4,6 +4,7 @@ require "tracia/version"
4
4
  require "tracia/gem_paths"
5
5
  require "tracia/frame"
6
6
  require "tracia/default_logger"
7
+ require "tracia/fake_trace_point"
7
8
 
8
9
  require "binding_of_callers"
9
10
 
@@ -52,12 +53,17 @@ class Tracia
52
53
  @backtraces = []
53
54
  @level = 0
54
55
 
55
- enable_trace_point
56
+ enable_trace_point(opt[:trace_point])
56
57
  end
57
58
 
58
- def enable_trace_point
59
+ def enable_trace_point(trace_point_opt)
60
+ return @trace_point = FakeTracePoint.new if trace_point_opt == false
61
+
59
62
  current_thread = Thread.current
60
63
  @trace_point = TracePoint.new(:raise) do |point|
64
+ if Proc === trace_point_opt
65
+ next if trace_point_opt.call(point, self) == false
66
+ end
61
67
  bd = point.binding
62
68
  next unless current_thread == bd.eval('Thread.current')
63
69
  backtrace = bd.eval("binding.partial_callers(-#{depth})")
@@ -90,13 +96,33 @@ class Tracia
90
96
 
91
97
  root = @stack[0]
92
98
  if root
93
- non_tail_recursion!([root]) if @non_tail_recursion
99
+ eliminate_tail_recursion!([root]) if @non_tail_recursion
94
100
  @logger.call(root)
95
101
  end
96
102
  end
97
103
 
98
104
  private
99
105
 
106
+ def eliminate_tail_recursion!(stack)
107
+ @specific_recursion =
108
+ case @non_tail_recursion
109
+ when true
110
+ -> (_) { true }
111
+ else
112
+ target_recursions = Array === @non_tail_recursion ? @non_tail_recursion : [@non_tail_recursion]
113
+ target_recursions.map!{ |h| Frame.new(h[:klass], h[:call_sym], h[:method_name], nil, nil) }
114
+ -> (current) do
115
+ target_recursions.any? do |tr|
116
+ current.klass == tr.klass &&
117
+ current.call_sym == tr.call_sym &&
118
+ current.method_name == tr.method_name
119
+ end
120
+ end
121
+ end
122
+
123
+ non_tail_recursion!(stack)
124
+ end
125
+
100
126
  def non_tail_recursion!(stack)
101
127
  current_frame = stack.last
102
128
  last_idx = current_frame.children.count - 1
@@ -105,7 +131,9 @@ class Tracia
105
131
  next unless Frame === child
106
132
  next non_tail_recursion!([child]) if last_idx != idx
107
133
 
108
- recursion_idx = stack.index{ |frame| frame.same_klass_and_method?(child) }
134
+ # pp (stack + [child]).map{|f| "#{f.send(:class_and_method)}:#{f.object_id}" }
135
+
136
+ recursion_idx = @specific_recursion[child] && stack.rindex{ |frame| frame.same_klass_and_method?(child) }
109
137
  if recursion_idx
110
138
  parent = stack[recursion_idx - 1]
111
139
  parent.children << child
@@ -142,22 +170,17 @@ class Tracia
142
170
  @frames_to_reject.any?{ |rj| rj =~ raw_frame.file }
143
171
  end
144
172
 
173
+ FAKE_METHOD = Struct.new(:source_location).new([nil, 0])
174
+
145
175
  def convert_to_frames(callers)
146
176
  callers.map! do |c|
147
177
  _binding = c._binding
178
+ iseq = _binding.instance_variable_get(:@iseq)
148
179
  klass = c.klass
149
180
  call_symbol = c.call_symbol
150
181
  frame_env = c.frame_env
151
182
 
152
- source_location =
153
- if _binding.frame_type == :method
154
- meth = call_symbol == INSTANCE_METHOD_SHARP ? klass.instance_method(frame_env) : klass.method(frame_env)
155
- meth.source_location
156
- else
157
- _binding.source_location
158
- end
159
-
160
- Frame.new(klass, call_symbol, frame_env, source_location[0], source_location[1])
183
+ Frame.new(klass, call_symbol, frame_env, iseq.path, iseq.first_lineno)
161
184
  end
162
185
 
163
186
  callers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.8
47
+ version: 0.1.9
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.8
54
+ version: 0.1.9
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: binding_of_callers
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,7 @@ files:
80
80
  - Rakefile
81
81
  - lib/tracia.rb
82
82
  - lib/tracia/default_logger.rb
83
+ - lib/tracia/fake_trace_point.rb
83
84
  - lib/tracia/frame.rb
84
85
  - lib/tracia/gem_paths.rb
85
86
  - lib/tracia/version.rb