trace_tree 0.2.18 → 0.2.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0e3749fd5cfe77879935127aff043e0f0e1dd824
4
- data.tar.gz: f198631aa1b43c03471a8ad64726b18360399f86
2
+ SHA256:
3
+ metadata.gz: bd5d8139275c2476c088b09d3206025594e2b90a19862fbfc547068104b1b35f
4
+ data.tar.gz: 8a98934c3db1b3c889bd7ae37e694f0bc75d2ea5cc2e499b21927d761023881c
5
5
  SHA512:
6
- metadata.gz: aa48ccce8ea838085360474808485d59ce3e1f3db4251084f8d9b3c7a6615803db01228805bb87ef2d680adefdaad28a7730fed432463ff67dd451b0f54e98aa
7
- data.tar.gz: d5b83842c96349de9bb0f1c8a1237dfefd0f82461be4fbcfa400a7c2c49c2096d9942852e3568da2d5b2519f23aaa9d445673c89d16b60d5deb5e23665a4144e
6
+ metadata.gz: 76792e80cfd88a73e3af890b6c1c8cb3de8ce2dde25e537914b9ffce13c15157692722f6618d4b99dfb5cddfb22230a5e78676ff41de25d4ea1d647b065229f5
7
+ data.tar.gz: acbcb32253763eacaa73771a2b8bac61f4092d0525f3610437852ed19f56bc4113aeb6cd7728b21ff4b6d99dbeb7f8fc2ac58ccf1825b2888ee665f3ad7b9d16
data/README.md CHANGED
@@ -58,7 +58,8 @@ end
58
58
  * `:no_methods => nil` by default. Give it regexp(s) to hide stack under matching methods. Useful when you want to dump stack of a rack middleware but lower middlewares.
59
59
  * `:warm => nil` by default. Set it something unique to the code block so that the code block will be traced only when it's called second time, in case we dump lots of code loading and initialization.
60
60
  * `:timer => nil` by default. Set it true if you want to know how much time spent in tracing and drawing tree. Notice the `file` should be appendable, otherwise the time will overwrite the tree.
61
- * `:debug => nil` by default. Give it somthing like what for `:tmp` to output a whole list of TracePoints in file for debug.
61
+ * `:debug => nil` by default. Give it `STDOUT`/`STDERR` or anything responds to `:puts` to output a whole list of TracePoints. Or give it a file name in the default tmp dir of your system.
62
+ * `transcode => false` by default. Set it true to convert unknown character into `"?"` when you see `Encoding::UndefinedConversionError`.
62
63
 
63
64
  ### Example 1: Output to HTML
64
65
 
@@ -10,5 +10,5 @@ require "trace_tree"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
14
- IRB.start(__FILE__)
13
+ require "pry"
14
+ pry
@@ -42,7 +42,7 @@ class TraceTree
42
42
  def generate *log, **opt, &to_do
43
43
  @opt = opt
44
44
  @log = dump_location *log
45
- @debug = TmpFile.new opt[:debug] if opt[:debug]
45
+ @debug = debug_location
46
46
  enhance_point
47
47
  @build_command = (opt[:html] || opt[:htmp]) ? :tree_html_full : :tree_graph
48
48
  make_filter
@@ -66,9 +66,16 @@ class TraceTree
66
66
 
67
67
  attr_reader :bi, :trace_points, :log, :build_command, :timer, :opt, :point_loader, :config
68
68
 
69
+ def debug_location
70
+ loc = opt[:debug]
71
+ return nil unless loc
72
+ return loc if loc.respond_to? :puts
73
+ TmpFile.new loc, transcode: opt[:transcode]
74
+ end
75
+
69
76
  def dump_location *log
70
- return TmpFile.new opt[:tmp] if opt[:tmp]
71
- return TmpFile.new(opt[:htmp] + '.html') if opt[:htmp]
77
+ return TmpFile.new(opt[:tmp], transcode: opt[:transcode]) if opt[:tmp]
78
+ return TmpFile.new((opt[:htmp] + '.html'), transcode: opt[:transcode]) if opt[:htmp]
72
79
  log.empty? ? STDOUT : log[0]
73
80
  end
74
81
 
@@ -89,7 +96,7 @@ class TraceTree
89
96
  timer[:tree]
90
97
  tree = sort(trace_points_array).send build_command
91
98
  timer[:tree]
92
- @debug.puts table_of_points if defined? @debug
99
+ @debug.puts table_of_points if @debug
93
100
  log.puts tree
94
101
  log.puts timer.to_s if opt[:timer]
95
102
  rescue => e
@@ -105,7 +112,7 @@ class TraceTree
105
112
  if (@no_methods = Array(opt[:no_methods])).empty?
106
113
  nil
107
114
  else
108
- stack_filter = 'return false unless outside_hidden_stack?(point)'
115
+ 'return false unless outside_hidden_stack?(point)'
109
116
  end
110
117
 
111
118
  path_filter =
@@ -124,8 +131,8 @@ class TraceTree
124
131
  filter_method = <<-EOM
125
132
  def wanted? point
126
133
  return false if point.end_of_trace?
127
- return true if native?(point) || point.thread_relative?
128
134
  #{stack_filter}
135
+ return true if native?(point) || point.thread_relative?
129
136
  return true if point.method_defined_by_define_method?
130
137
  #{path_filter}
131
138
  true
@@ -144,14 +151,25 @@ class TraceTree
144
151
  stack = (point.thread[:trace_tree_no_methods_stack] ||= [])
145
152
  empty = stack.empty?
146
153
 
147
- if @no_methods.any?{ |pattern| pattern =~ point.method_name }
154
+ if point.event == :b_call || point.event == :b_return
155
+ return true if empty
156
+ if point.terminate?(stack.last)
157
+ stack.pop
158
+ else
159
+ stack << point
160
+ end
161
+ return false
162
+ end
163
+
164
+ if @no_methods.any?{ |pattern| pattern =~ point.method_id }
148
165
  if !empty && point.terminate?(stack.last)
149
166
  stack.pop
167
+ return stack.empty?
150
168
  else
151
169
  stack << point
152
170
  point << Point::Omitted.new
171
+ return empty
153
172
  end
154
- return true
155
173
  end
156
174
 
157
175
  empty
@@ -187,6 +205,8 @@ class TraceTree
187
205
  point.thread_begin = began_threads[thread]
188
206
  end
189
207
 
208
+ stacks.keys.each{ |thread| thread[:trace_tree_no_methods_stack] = nil }
209
+
190
210
  #binding.pry
191
211
 
192
212
  stacks[trace_points.first.thread][0].
@@ -18,10 +18,6 @@ class TraceTree
18
18
  bases << base
19
19
  end
20
20
 
21
- def classes
22
- @classes ||= bases.each_with_object(Hash.new{|h| h[:common]}){|c, h| h[c.event_class_method] = c}
23
- end
24
-
25
21
  def bases
26
22
  @bases ||= []
27
23
  end
@@ -77,14 +73,12 @@ EOM
77
73
  end
78
74
 
79
75
  @return_value = trace_point.return_value if x_return?
76
+ @thread = Thread.current
80
77
 
81
- if thread?
82
- @thread = trace_point.self
83
- else
78
+ unless thread?
84
79
  there = trace_point.binding.of_caller(3)
85
80
  @current = BindingOfCallers::Revealed.new there
86
81
  @frame_env = current.frame_env.to_sym
87
- @thread = current.send(:eval, 'Thread.current')
88
82
  end
89
83
  rescue => e
90
84
  puts e
@@ -194,14 +188,36 @@ EOM
194
188
 
195
189
  def initialize *enhancement, config
196
190
  @config = config
197
- return @point_classes = Point.classes if enhancement.empty?
198
- @point_classes = Point.classes.each_with_object(Point.classes.dup) do |entry, hash|
199
- hash[entry[0]] = entry[1].clone.prepend *enhancement
191
+ @bases = Point.bases
192
+ @bases = @bases.map{ |b| b = b.clone; b.prepend *enhancement; b } unless enhancement.empty?
193
+ sort_bases
194
+ end
195
+
196
+ def sort_bases
197
+ @methods = {}
198
+
199
+ @bases.each do |b|
200
+ event, klass, method = b.event_class_method
201
+ events = (@methods[method] ||= {})
202
+ klasses = (events[event] ||= {})
203
+ klasses[klass] = b
200
204
  end
205
+
206
+ @common = @methods[nil][:common][nil]
201
207
  end
202
208
 
203
209
  def create point
204
- point_klass = point_classes[[point.event, point.defined_class, point.method_id]]
210
+ point_klass =
211
+ if events = @methods[point.method_id]
212
+ if klasses = events[point.event]
213
+ klasses[point.defined_class] || @common
214
+ else
215
+ @common
216
+ end
217
+ else
218
+ @common
219
+ end
220
+
205
221
  poi = point_klass.new point
206
222
  poi.config = config
207
223
  poi
@@ -2,7 +2,8 @@ class TraceTree
2
2
  class Point
3
3
  class CcallKernelExtend < Point
4
4
  def parameters
5
- callees[0].mixin
5
+ first_callee = callees[0]
6
+ first_callee.respond_to?(:mixin) ? first_callee.mixin : first_callee.current.klass
6
7
  end
7
8
 
8
9
  def self.event_class_method
@@ -6,8 +6,10 @@ class TraceTree
6
6
  [:c_call, Module, :include]
7
7
  end
8
8
 
9
+ # first callee should be append_features(), check if it is native or custom
9
10
  def parameters
10
- callees[0].parameters
11
+ first_callee = callees[0]
12
+ Module == first_callee.class_name ? first_callee.return_value : first_callee.current.klass
11
13
  end
12
14
 
13
15
  end
@@ -7,7 +7,8 @@ class TraceTree
7
7
  end
8
8
 
9
9
  def parameters
10
- callees[0].parameters
10
+ first_callee = callees[0]
11
+ Module == first_callee.class_name ? first_callee.return_value : first_callee.current.klass
11
12
  end
12
13
 
13
14
  end
@@ -12,12 +12,15 @@ class TraceTree
12
12
 
13
13
  DefaultName = 'trace_tree.html'
14
14
 
15
- def initialize path
15
+ def initialize path, transcode: false
16
16
  path = recognize_dir path
17
17
  @tmp = custom path
18
+ @transcode = transcode
18
19
  end
19
20
 
20
21
  def puts *content
22
+ content = content.map{ |c| c.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') } if @transcode
23
+
21
24
  File.open @tmp, 'a' do |f|
22
25
  f.puts *content
23
26
  end
@@ -1,3 +1,3 @@
1
1
  class TraceTree
2
- VERSION = "0.2.18"
2
+ VERSION = "0.2.23"
3
3
  end
@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "bundler", "> 1.14"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "pry"
26
27
 
27
28
  spec.add_dependency "binding_of_callers", "~> 0.1.5"
28
29
  spec.add_dependency "tree_graph", "~> 0.2.0"
29
30
  spec.add_dependency "tree_html", "~> 0.1.7"
30
31
  spec.add_dependency "terminal-tableofhashes", "~> 0.1.0"
31
32
 
32
- spec.extensions << "ext/mkrf_conf.rb"
33
33
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: binding_of_callers
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -112,8 +126,7 @@ description:
112
126
  email:
113
127
  - block24block@gmail.com
114
128
  executables: []
115
- extensions:
116
- - ext/mkrf_conf.rb
129
+ extensions: []
117
130
  extra_rdoc_files: []
118
131
  files:
119
132
  - ".gitignore"
@@ -125,7 +138,6 @@ files:
125
138
  - Rakefile
126
139
  - bin/console
127
140
  - bin/setup
128
- - ext/mkrf_conf.rb
129
141
  - lib/trace_tree.rb
130
142
  - lib/trace_tree/args.rb
131
143
  - lib/trace_tree/color.rb
@@ -136,22 +148,16 @@ files:
136
148
  - lib/trace_tree/group_by_file.js
137
149
  - lib/trace_tree/native_console.js
138
150
  - lib/trace_tree/point.rb
139
- - lib/trace_tree/point/call_activesupportconcern_appendfeatures.rb
140
- - lib/trace_tree/point/call_modulemutexm_extendobject.rb
141
151
  - lib/trace_tree/point/ccall_classthread_new.rb
142
152
  - lib/trace_tree/point/ccall_kernel_extend.rb
143
153
  - lib/trace_tree/point/ccall_kernel_raise.rb
144
- - lib/trace_tree/point/ccall_module_appendfeatures.rb
145
154
  - lib/trace_tree/point/ccall_module_extendobject.rb
146
155
  - lib/trace_tree/point/ccall_module_include.rb
147
156
  - lib/trace_tree/point/ccall_module_prepend.rb
148
- - lib/trace_tree/point/ccall_module_prependfeatures.rb
149
157
  - lib/trace_tree/point/ccall_thread_initialize.rb
150
158
  - lib/trace_tree/point/common.rb
151
159
  - lib/trace_tree/point/creturn_classthread_new.rb
152
- - lib/trace_tree/point/creturn_module_appendfeatures.rb
153
160
  - lib/trace_tree/point/creturn_module_extendobject.rb
154
- - lib/trace_tree/point/creturn_module_prependfeatures.rb
155
161
  - lib/trace_tree/point/creturn_thread_initialize.rb
156
162
  - lib/trace_tree/point/omit.rb
157
163
  - lib/trace_tree/point/threadbegin.rb
@@ -185,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
191
  version: '0'
186
192
  requirements: []
187
193
  rubyforge_project:
188
- rubygems_version: 2.5.2.3
194
+ rubygems_version: 2.7.6
189
195
  signing_key:
190
196
  specification_version: 4
191
197
  summary: Print TracePoint(:b_call, :b_return, :c_call, :c_return, :call, :return,
@@ -1,32 +0,0 @@
1
- #This file needs to be named mkrf_conf.rb
2
- #so that rubygems will recognize it as a ruby extension
3
- #file and not think it is a C extension file
4
-
5
- require 'rubygems/dependency_installer'
6
-
7
- #Load up the rubygem's dependency installer to
8
- #installer the gems we want based on the version
9
- #of Ruby the user has installed
10
- installer = Gem::DependencyInstaller.new
11
-
12
- begin
13
- if RUBY_VERSION < "2.2.2"
14
- installer.install "activesupport", "< 5.0.0"
15
- elsif RUBY_VERSION < "2.5.0"
16
- installer.install "activesupport", "< 6.0.0"
17
- else
18
- installer.install "activesupport"
19
- end
20
-
21
- rescue => e
22
- puts e.message, e.backtrace
23
- #Exit with a non-zero value to let rubygems something went wrong
24
- exit(1)
25
- end
26
-
27
- #If this was C, rubygems would attempt to run make
28
- #Since this is Ruby, rubygems will attempt to run rake
29
- #If it doesn't find and successfully run a rakefile, it errors out
30
- f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w")
31
- f.write("task :default\n")
32
- f.close
@@ -1,17 +0,0 @@
1
- require 'active_support/concern'
2
-
3
- class TraceTree
4
- class Point
5
- class CallActivesupportconcernAppendfeatures < Point
6
-
7
- def self.event_class_method
8
- [:call, ActiveSupport::Concern, :append_features]
9
- end
10
-
11
- def parameters
12
- current.lv.values.first
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- require 'mutex_m'
2
-
3
- class TraceTree
4
- class Point
5
- class CallModuleMutexmExtendobject < Point
6
-
7
- def mixin
8
- Mutex_m
9
- end
10
-
11
- def self.event_class_method
12
- [:call, Mutex_m.singleton_class, :extend_object]
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- class TraceTree
2
- class Point
3
- class CcallModuleAppendfeatures < Point
4
-
5
- def self.event_class_method
6
- [:c_call, Module, :append_features]
7
- end
8
-
9
- def parameters
10
- terminal.return_value
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- class TraceTree
2
- class Point
3
- class CcallModulePrependfeatures < Point
4
-
5
- def self.event_class_method
6
- [:c_call, Module, :prepend_features]
7
- end
8
-
9
- def parameters
10
- terminal.return_value
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- class TraceTree
2
- class Point
3
- class CreturnModuleAppendfeatures < Point
4
-
5
- def self.event_class_method
6
- [:c_return, Module, :append_features]
7
- end
8
-
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- class TraceTree
2
- class Point
3
- class CreturnModulePrependfeatures < Point
4
-
5
- def self.event_class_method
6
- [:c_return, Module, :prepend_features]
7
- end
8
-
9
- end
10
- end
11
- end