trace_tree 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/trace_tree/node.rb +4 -19
- data/lib/trace_tree/tree_graphable.rb +25 -0
- data/lib/trace_tree/tree_htmlable.rb +16 -0
- data/lib/trace_tree/version.rb +1 -1
- data/lib/trace_tree.rb +32 -23
- data/trace_tree.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecfcbcac41a1a8ec231bc7c72ea1263e8c046e47
|
4
|
+
data.tar.gz: 8a7041736a6b9944c85bb294027308f9fdaddacf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fff3e8f0fcc69ba556033c9f527309d3b38d5dbae074da4dff962782afc804e0a63449d8fd0b10ebaf6d0efdf233c6e0fdf5fcc5b2991dc765e490d89809b92
|
7
|
+
data.tar.gz: 13bcc734c2dde452234e6b1865f054c46253f40d6a5139380c657e6d714e7e3e4fd05b67555459850f9206adf7a6d2b8dc6f9c583cf961482e3ce2a6f343ce05
|
data/README.md
CHANGED
@@ -41,6 +41,7 @@ end
|
|
41
41
|
* `file == STDOUT` by default. You can give it a File object or anything responds to `puts`.
|
42
42
|
* `:color => true` by default. It makes method names have different color than source_location in output. When you print the output to file, you may want to set it false to discard those color ANSI escape sequences.
|
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
|
+
* `:html => nil` by default. Set it true to generate a html in which a tree constructed with `<ul>`, `<li>`.
|
44
45
|
|
45
46
|
### Example
|
46
47
|
|
data/lib/trace_tree/node.rb
CHANGED
@@ -1,26 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'trace_tree/tree_graphable'
|
2
|
+
require 'trace_tree/tree_htmlable'
|
2
3
|
|
3
4
|
class TraceTree
|
4
5
|
class Node
|
5
6
|
|
6
|
-
include
|
7
|
-
|
8
|
-
def parent_for_tree_graph
|
9
|
-
parent
|
10
|
-
end
|
11
|
-
|
12
|
-
def is_last_for_tree_graph
|
13
|
-
return true unless parent
|
14
|
-
parent.callees.index(self) == (parent.callees.count - 1)
|
15
|
-
end
|
16
|
-
|
17
|
-
def label_for_tree_graph
|
18
|
-
"#{class_and_method} #{source_location}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def children_for_tree_graph
|
22
|
-
callees
|
23
|
-
end
|
7
|
+
include TreeGraphable
|
8
|
+
include TreeHtmlable
|
24
9
|
|
25
10
|
attr_reader :bindings
|
26
11
|
attr_accessor :parent
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'tree_graph'
|
2
|
+
|
3
|
+
class TraceTree
|
4
|
+
module TreeGraphable
|
5
|
+
|
6
|
+
include TreeGraph
|
7
|
+
|
8
|
+
def parent_for_tree_graph
|
9
|
+
parent
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_last_for_tree_graph
|
13
|
+
return true unless parent
|
14
|
+
parent.callees.index(self) == (parent.callees.count - 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
def label_for_tree_graph
|
18
|
+
"#{class_and_method} #{source_location}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def children_for_tree_graph
|
22
|
+
callees
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'tree_html'
|
2
|
+
|
3
|
+
class TraceTree
|
4
|
+
module TreeHtmlable
|
5
|
+
|
6
|
+
include TreeHtml
|
7
|
+
|
8
|
+
def label_for_tree_html
|
9
|
+
"<span class='highlight'>#{class_and_method}</span> #{source_location}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def children_for_tree_html
|
13
|
+
callees
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/trace_tree/version.rb
CHANGED
data/lib/trace_tree.rb
CHANGED
@@ -4,40 +4,38 @@ require 'trace_tree/node'
|
|
4
4
|
require 'trace_tree/short_gem_path'
|
5
5
|
require 'trace_tree/color'
|
6
6
|
|
7
|
+
class Binding
|
8
|
+
def trace_tree *log, **opt, &to_do
|
9
|
+
TraceTree.new(self).generate *log, **opt, &to_do
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
7
13
|
class TraceTree
|
8
14
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
unless hash.empty?
|
13
|
-
parent = hash[call.parent_stack]
|
14
|
-
parent << call if parent
|
15
|
-
end
|
16
|
-
hash[call.whole_stack] = call
|
17
|
-
end
|
18
|
-
stack[0]
|
15
|
+
def initialize bi
|
16
|
+
@bi = bi
|
17
|
+
@trace_points = []
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
class Binding
|
24
|
-
def trace_tree *log, **opt, &to_do
|
25
|
-
log = log.empty? ? STDOUT : log[0]
|
20
|
+
def generate *log, **opt, &to_do
|
21
|
+
@log = log.empty? ? STDOUT : log[0]
|
26
22
|
node_class = optional_node opt
|
23
|
+
@build = opt[:html] ? [:tree_html_full, '.highlight{color: blue;}'] : [:tree_graph]
|
27
24
|
|
28
|
-
trace_points = []
|
29
25
|
tp = TracePoint.trace(:call, :b_call, :raise, :c_call) do |point|
|
30
26
|
trace_points << node_class.new(point) if wanted? point
|
31
27
|
end
|
32
28
|
|
33
|
-
eval('self').instance_eval &to_do
|
29
|
+
bi.eval('self').instance_eval &to_do
|
34
30
|
ensure
|
35
31
|
tp.disable
|
36
|
-
|
32
|
+
dump_trace_tree
|
37
33
|
end
|
38
34
|
|
39
35
|
private
|
40
36
|
|
37
|
+
attr_reader :bi, :trace_points, :log, :build
|
38
|
+
|
41
39
|
def optional_node opt
|
42
40
|
Class.new TraceTree::Node do
|
43
41
|
prepend TraceTree::ShortGemPath unless opt[:gem] == false
|
@@ -45,15 +43,26 @@ class Binding
|
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
def
|
49
|
-
tree =
|
50
|
-
sort(trace_points).
|
51
|
-
tree_graph
|
52
|
-
|
46
|
+
def dump_trace_tree
|
47
|
+
tree = sort(trace_points).send *build
|
53
48
|
log.puts tree
|
54
49
|
end
|
55
50
|
|
56
51
|
def wanted? trace_point
|
57
52
|
trace_point.event != :c_call or trace_point.method_id == :throw
|
58
53
|
end
|
54
|
+
|
55
|
+
def sort stack
|
56
|
+
hash = {}
|
57
|
+
stack.each do |call|
|
58
|
+
unless hash.empty?
|
59
|
+
parent = hash[call.parent_stack]
|
60
|
+
parent << call if parent
|
61
|
+
end
|
62
|
+
hash[call.whole_stack] = call
|
63
|
+
end
|
64
|
+
stack[0]
|
65
|
+
end
|
66
|
+
|
59
67
|
end
|
68
|
+
|
data/trace_tree.gemspec
CHANGED
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.1
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tree_html
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.1.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.1.0
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- block24block@gmail.com
|
@@ -101,6 +115,8 @@ files:
|
|
101
115
|
- lib/trace_tree/gem_paths.rb
|
102
116
|
- lib/trace_tree/node.rb
|
103
117
|
- lib/trace_tree/short_gem_path.rb
|
118
|
+
- lib/trace_tree/tree_graphable.rb
|
119
|
+
- lib/trace_tree/tree_htmlable.rb
|
104
120
|
- lib/trace_tree/version.rb
|
105
121
|
- trace_tree.gemspec
|
106
122
|
homepage: https://github.com/turnon/trace_tree
|