trace_tree 0.1.3 → 0.1.4
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/README.md +1 -0
- data/lib/trace_tree/node.rb +1 -1
- data/lib/trace_tree/timer.rb +27 -0
- data/lib/trace_tree/tmp_file.rb +1 -1
- data/lib/trace_tree/version.rb +1 -1
- data/lib/trace_tree.rb +26 -11
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ee0aca382b4cf453d1a686ee889f6dd7717bc55
|
4
|
+
data.tar.gz: 45677cc8e22cf0b570c956ef0ddb4900fab9856f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfa005442e08b5293d2c6a8b26eb98155e4c678b96e015ed41deb863dbefa9534f17fb09d8a7eaa75c5b6ba09f7d5420dd61ea6054f2b2b959df8898d6e2206a
|
7
|
+
data.tar.gz: beca1bd006605d215528f349ea34cf49dbece736d403b2e8402ce4261320370bc3641e748275e545def5b176b80ed534228074f7aebee73958845468b2815890
|
data/README.md
CHANGED
@@ -43,6 +43,7 @@ end
|
|
43
43
|
* `:gem => true` by default. Replace the gem paths in source_location with $GemPathN, can make the lines shorter. To see what are replaced, inspect `TraceTree::GemPaths`.
|
44
44
|
* `:html => nil` by default. Set it true to generate a html in which a tree constructed with `<ul>`, `<li>`. (No need to set `color`).
|
45
45
|
* `:tmp => nil` by default. Set it true or an array of string to specify a tmp file under the default tmp dir of your system. (No need to provide `file` argument)
|
46
|
+
* `: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.
|
46
47
|
|
47
48
|
### Example
|
48
49
|
|
data/lib/trace_tree/node.rb
CHANGED
@@ -13,7 +13,7 @@ class TraceTree
|
|
13
13
|
def initialize trace_point
|
14
14
|
@event = trace_point.event
|
15
15
|
@method_id = trace_point.method_id
|
16
|
-
@bindings = filter_call_stack trace_point.binding.of_callers
|
16
|
+
@bindings = filter_call_stack trace_point.binding.of_callers
|
17
17
|
end
|
18
18
|
|
19
19
|
def << node
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class TraceTree
|
2
|
+
class Timer
|
3
|
+
|
4
|
+
attr_reader :record
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@record = Hash.new do |h, k|
|
8
|
+
h[k] = []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](name)
|
13
|
+
record[name] << Time.now
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
record.map{|k,v| "#{k}: #{ftime v[0]} ~ #{ftime v[-1]} = #{v[-1] - v[0]}"}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def ftime time
|
23
|
+
time.strftime '%F %T %L'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/trace_tree/tmp_file.rb
CHANGED
data/lib/trace_tree/version.rb
CHANGED
data/lib/trace_tree.rb
CHANGED
@@ -4,6 +4,7 @@ require 'trace_tree/node'
|
|
4
4
|
require 'trace_tree/short_gem_path'
|
5
5
|
require 'trace_tree/color'
|
6
6
|
require 'trace_tree/tmp_file'
|
7
|
+
require 'trace_tree/timer'
|
7
8
|
|
8
9
|
class Binding
|
9
10
|
def trace_tree *log, **opt, &to_do
|
@@ -16,28 +17,39 @@ class TraceTree
|
|
16
17
|
def initialize bi
|
17
18
|
@bi = bi
|
18
19
|
@trace_points = []
|
20
|
+
@timer = Timer.new
|
19
21
|
end
|
20
22
|
|
21
23
|
def generate *log, **opt, &to_do
|
22
|
-
@
|
23
|
-
|
24
|
+
@opt = opt
|
25
|
+
@log = dump_location *log
|
26
|
+
@node_class = optional_node **opt
|
24
27
|
@build_command = opt[:html] ? :tree_html_full : :tree_graph
|
25
|
-
|
26
|
-
tp = TracePoint.trace(:call, :b_call, :raise, :c_call) do |point|
|
27
|
-
trace_points << node_class.new(point) if wanted? point
|
28
|
-
end
|
29
|
-
|
28
|
+
start_trace
|
30
29
|
bi.eval('self').instance_eval &to_do
|
31
30
|
ensure
|
32
|
-
|
33
|
-
dump_trace_tree
|
31
|
+
stop_trace
|
34
32
|
end
|
35
33
|
|
36
34
|
private
|
37
35
|
|
38
|
-
attr_reader :bi, :trace_points, :log, :build_command
|
36
|
+
attr_reader :bi, :trace_points, :log, :build_command, :timer, :opt
|
37
|
+
|
38
|
+
def start_trace
|
39
|
+
timer[:to_do]
|
40
|
+
@tp = TracePoint.trace(:call, :b_call, :raise, :c_call) do |point|
|
41
|
+
trace_points << @node_class.new(point) if wanted? point
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def stop_trace
|
46
|
+
return unless @tp
|
47
|
+
@tp.disable
|
48
|
+
timer[:to_do]
|
49
|
+
dump_trace_tree
|
50
|
+
end
|
39
51
|
|
40
|
-
def dump_location *log
|
52
|
+
def dump_location *log
|
41
53
|
return TmpFile.new opt[:tmp] if opt[:tmp]
|
42
54
|
log.empty? ? STDOUT : log[0]
|
43
55
|
end
|
@@ -50,8 +62,11 @@ class TraceTree
|
|
50
62
|
end
|
51
63
|
|
52
64
|
def dump_trace_tree
|
65
|
+
timer[:tree]
|
53
66
|
tree = sort(trace_points).send build_command
|
67
|
+
timer[:tree]
|
54
68
|
log.puts tree
|
69
|
+
log.puts timer.to_s if opt[:timer]
|
55
70
|
end
|
56
71
|
|
57
72
|
def wanted? trace_point
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/trace_tree/gem_paths.rb
|
116
116
|
- lib/trace_tree/node.rb
|
117
117
|
- lib/trace_tree/short_gem_path.rb
|
118
|
+
- lib/trace_tree/timer.rb
|
118
119
|
- lib/trace_tree/tmp_file.rb
|
119
120
|
- lib/trace_tree/tree_graphable.rb
|
120
121
|
- lib/trace_tree/tree_htmlable.rb
|
@@ -140,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
141
|
version: '0'
|
141
142
|
requirements: []
|
142
143
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.5.2
|
144
145
|
signing_key:
|
145
146
|
specification_version: 4
|
146
147
|
summary: Print TracePoint(normal ruby call, block call, raise call, throw call) in
|