Class: TraceTree::Point
- Inherits:
-
Object
show all
- Includes:
- TreeGraphable, TreeHtmlable
- Defined in:
- lib/trace_tree/point.rb,
lib/trace_tree/point/common.rb,
lib/trace_tree/point/threadend.rb,
lib/trace_tree/point/threadbegin.rb,
lib/trace_tree/point/ccall_kernel_extend.rb,
lib/trace_tree/point/ccall_module_include.rb,
lib/trace_tree/point/ccall_module_prepend.rb,
lib/trace_tree/point/ccall_classthread_new.rb,
lib/trace_tree/point/ccall_thread_initialize.rb,
lib/trace_tree/point/creturn_classthread_new.rb,
lib/trace_tree/point/ccall_module_extendobject.rb,
lib/trace_tree/point/creturn_thread_initialize.rb,
lib/trace_tree/point/ccall_module_appendfeatures.rb,
lib/trace_tree/point/creturn_module_extendobject.rb,
lib/trace_tree/point/ccall_module_prependfeatures.rb,
lib/trace_tree/point/creturn_module_appendfeatures.rb,
lib/trace_tree/point/call_modulemutexm_extendobject.rb,
lib/trace_tree/point/creturn_module_prependfeatures.rb,
lib/trace_tree/point/call_activesupportconcern_appendfeatures.rb
Direct Known Subclasses
CallActivesupportconcernAppendfeatures, CallModuleMutexmExtendobject, CcallClassthreadNew, CcallKernelExtend, CcallModuleAppendfeatures, CcallModuleExtendobject, CcallModuleInclude, CcallModulePrepend, CcallModulePrependfeatures, CcallThreadInitialize, Common, CreturnClassthreadNew, CreturnModuleAppendfeatures, CreturnModuleExtendobject, CreturnModulePrependfeatures, CreturnThreadInitialize, Threadbegin, Threadend
Defined Under Namespace
Classes: CallActivesupportconcernAppendfeatures, CallModuleMutexmExtendobject, CcallClassthreadNew, CcallKernelExtend, CcallModuleAppendfeatures, CcallModuleExtendobject, CcallModuleInclude, CcallModulePrepend, CcallModulePrependfeatures, CcallThreadInitialize, Common, CreturnClassthreadNew, CreturnModuleAppendfeatures, CreturnModuleExtendobject, CreturnModulePrependfeatures, CreturnThreadInitialize, Loader, Threadbegin, Threadend
Constant Summary
collapse
- Interfaces =
[:event, :defined_class, :method_id, :path, :lineno]
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#children_for_tree_html, #css_for_tree_html, #label_for_tree_html
#children_for_tree_graph, #label_for_tree_graph
Constructor Details
#initialize(trace_point) ⇒ Point
Returns a new instance of Point.
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/trace_tree/point.rb', line 55
def initialize trace_point
Interfaces.each do |i|
instance_variable_set "@#{i}", trace_point.send(i)
end
@return_value = trace_point.return_value if x_return?
@current = BindingOfCallers::Revealed.new trace_point.binding.of_caller(3) unless thread?
@thread = thread? ? trace_point.self : current.send(:eval, 'Thread.current')
rescue => e
puts e
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args, &blk) ⇒ Object
51
52
53
|
# File 'lib/trace_tree/point.rb', line 51
def method_missing method_id, *args, &blk
raise NoMethodError, "NoMethodError: undefined method `#{method_id}' for #<#{self.class.proto or self.class.name}#{inspect}>"
end
|
Class Attribute Details
.proto ⇒ Object
Returns the value of attribute proto.
48
49
50
|
# File 'lib/trace_tree/point.rb', line 48
def proto
@proto
end
|
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
10
11
12
|
# File 'lib/trace_tree/point.rb', line 10
def current
@current
end
|
#terminal ⇒ Object
Returns the value of attribute terminal.
11
12
13
|
# File 'lib/trace_tree/point.rb', line 11
def terminal
@terminal
end
|
#thread ⇒ Object
Returns the value of attribute thread.
10
11
12
|
# File 'lib/trace_tree/point.rb', line 10
def thread
@thread
end
|
Class Method Details
.bases ⇒ Object
25
26
27
|
# File 'lib/trace_tree/point.rb', line 25
def bases
@bases ||= []
end
|
.class_of?(point) ⇒ Boolean
38
39
40
|
# File 'lib/trace_tree/point.rb', line 38
def class_of? point
[point.event, point.defined_class, point.method_id] == event_class_method
end
|
.classes ⇒ Object
21
22
23
|
# File 'lib/trace_tree/point.rb', line 21
def classes
@classes ||= bases.each_with_object(Hash.new{|h| h[:common]}){|c, h| h[c.event_class_method] = c}
end
|
.hashify(point) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/trace_tree/point.rb', line 29
def hashify point
attrs = Interfaces.each_with_object({}) do |attr, hash|
hash[attr] = point.send attr
end
attrs.merge!({return_value: point.return_value}) if point.event =~ /return/
attrs.merge!({thread: point.thread}) if point.respond_to? :thread
attrs
end
|
.inherited(base) ⇒ Object
17
18
19
|
# File 'lib/trace_tree/point.rb', line 17
def inherited base
bases << base
end
|
.initialize_clone(proto) ⇒ Object
42
43
44
45
46
|
# File 'lib/trace_tree/point.rb', line 42
def initialize_clone proto
super.tap do
instance_variable_set :@proto, proto
end
end
|
Instance Method Details
#<<(node) ⇒ Object
107
108
109
|
# File 'lib/trace_tree/point.rb', line 107
def << node
callees << node
end
|
#_class_and_method ⇒ Object
119
120
121
|
# File 'lib/trace_tree/point.rb', line 119
def _class_and_method
@km ||= "#{class_name}#{call_symbol}#{method_name}"
end
|
#arg ⇒ Object
141
142
143
|
# File 'lib/trace_tree/point.rb', line 141
def arg
respond_to?(:parameters) ? "(#{parameters})" : nil
end
|
#c_call? ⇒ Boolean
66
67
68
|
# File 'lib/trace_tree/point.rb', line 66
def c_call?
event == :c_call
end
|
#call_symbol ⇒ Object
133
134
135
|
# File 'lib/trace_tree/point.rb', line 133
def call_symbol
c_call? ? '#' : current.call_symbol
end
|
#callees ⇒ Object
111
112
113
|
# File 'lib/trace_tree/point.rb', line 111
def callees
@callees ||= []
end
|
#class_and_method ⇒ Object
115
116
117
|
# File 'lib/trace_tree/point.rb', line 115
def class_and_method
"#{_class_and_method}#{arg}"
end
|
#class_name ⇒ Object
123
124
125
126
127
|
# File 'lib/trace_tree/point.rb', line 123
def class_name
c_call? ? defined_class : current.klass
rescue => e
puts event
end
|
#ending?(point) ⇒ Boolean
99
100
101
102
103
104
105
|
# File 'lib/trace_tree/point.rb', line 99
def ending? point
(event == :b_return and point.event == :b_call) or
(event == :c_return and point.event == :c_call) or
(event == :return and point.event == :call) or
(event == :end and point.event == :class) or
(event == :thread_end and point.event == :thread_begin)
end
|
#inspect ⇒ Object
83
84
85
|
# File 'lib/trace_tree/point.rb', line 83
def inspect
to_h.inspect
end
|
#method_name ⇒ Object
129
130
131
|
# File 'lib/trace_tree/point.rb', line 129
def method_name
c_call? ? method_id : current.frame_env
end
|
#return_value ⇒ Object
78
79
80
81
|
# File 'lib/trace_tree/point.rb', line 78
def return_value
raise RuntimeError.new('RuntimeError: not supported by this event') unless x_return?
@return_value
end
|
#same_method?(point) ⇒ Boolean
95
96
97
|
# File 'lib/trace_tree/point.rb', line 95
def same_method? point
point.defined_class == defined_class and point.method_id == method_id
end
|
#source_location ⇒ Object
137
138
139
|
# File 'lib/trace_tree/point.rb', line 137
def source_location
"#{path}:#{lineno}"
end
|
#terminate?(point) ⇒ Boolean
91
92
93
|
# File 'lib/trace_tree/point.rb', line 91
def terminate? point
same_method?(point) and ending?(point)
end
|
#thread? ⇒ Boolean
74
75
76
|
# File 'lib/trace_tree/point.rb', line 74
def thread?
event =~ /thread/
end
|
#to_h ⇒ Object
87
88
89
|
# File 'lib/trace_tree/point.rb', line 87
def to_h
self.class.hashify(self)
end
|
#x_return? ⇒ Boolean
70
71
72
|
# File 'lib/trace_tree/point.rb', line 70
def x_return?
event =~ /return/
end
|