Class: TraceTree::Point
- Inherits:
-
Object
show all
- Includes:
- TreeGraphable, TreeHtmlable
- Defined in:
- lib/trace_tree/point.rb,
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]
- NativeThreadCall =
[CcallClassthreadNew,
CreturnClassthreadNew,
CcallThreadInitialize,
CreturnThreadInitialize,
Threadbegin,
Threadend]
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.
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/trace_tree/point.rb', line 73
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?
if thread?
@thread = trace_point.self
else
there = trace_point.binding.of_caller(3)
@current = BindingOfCallers::Revealed.new there
@frame_env = current.frame_env.to_sym
@thread = current.send(:eval, 'Thread.current')
end
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
69
70
71
|
# File 'lib/trace_tree/point.rb', line 69
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.
53
54
55
|
# File 'lib/trace_tree/point.rb', line 53
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
|
#frame_env ⇒ Object
Returns the value of attribute frame_env.
10
11
12
|
# File 'lib/trace_tree/point.rb', line 10
def frame_env
@frame_env
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
|
.cache_event_class_method! ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/trace_tree/point.rb', line 55
def cache_event_class_method!
bases.each do |base|
base.class_eval " class << self\n alias_method :_event_class_method, :event_class_method\n def self.event_class_method\n @ecm ||= _event_class_method.freeze\n end\n end\n"
end
end
|
.class_of?(point) ⇒ Boolean
42
43
44
45
|
# File 'lib/trace_tree/point.rb', line 42
def class_of? point
e, c, m = event_class_method
point.method_id == m && point.event == e && point.defined_class == c
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
37
38
39
40
|
# File 'lib/trace_tree/point.rb', line 29
def hashify point
h = {}
h[:event] = point.event
h[:defined_class] = point.defined_class
h[:method_id] = point.method_id
h[:frame_env] = point.frame_env unless point.thread?
h[:path] = point.path
h[:lineno] = point.lineno
h[:thread] = point.thread
h[:return_value] = point.return_value if point.event =~ /return/
h
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
47
48
49
50
51
|
# File 'lib/trace_tree/point.rb', line 47
def initialize_clone proto
super.tap do
instance_variable_set :@proto, proto
end
end
|
Instance Method Details
#<<(node) ⇒ Object
148
149
150
|
# File 'lib/trace_tree/point.rb', line 148
def << node
callees << node
end
|
#_class_and_method ⇒ Object
160
161
162
|
# File 'lib/trace_tree/point.rb', line 160
def _class_and_method
@km ||= "#{class_name}#{call_symbol}#{method_name}"
end
|
#arg ⇒ Object
184
185
186
|
# File 'lib/trace_tree/point.rb', line 184
def arg
respond_to?(:parameters) ? "(#{parameters})" : nil
end
|
#b_call? ⇒ Boolean
92
93
94
|
# File 'lib/trace_tree/point.rb', line 92
def b_call?
event == :b_call
end
|
#c_call? ⇒ Boolean
96
97
98
|
# File 'lib/trace_tree/point.rb', line 96
def c_call?
event == :c_call
end
|
#call_symbol ⇒ Object
176
177
178
|
# File 'lib/trace_tree/point.rb', line 176
def call_symbol
c_call? ? '#' : current.call_symbol
end
|
#callees ⇒ Object
152
153
154
|
# File 'lib/trace_tree/point.rb', line 152
def callees
@callees ||= []
end
|
#class? ⇒ Boolean
100
101
102
|
# File 'lib/trace_tree/point.rb', line 100
def class?
event == :class
end
|
#class_and_method ⇒ Object
156
157
158
|
# File 'lib/trace_tree/point.rb', line 156
def class_and_method
"#{_class_and_method}#{arg}"
end
|
#class_name ⇒ Object
164
165
166
167
168
|
# File 'lib/trace_tree/point.rb', line 164
def class_name
c_call? ? defined_class : current.klass
rescue => e
puts event
end
|
#end_of_trace? ⇒ Boolean
112
113
114
115
116
117
|
# File 'lib/trace_tree/point.rb', line 112
def end_of_trace?
MainFile == path && (
(:c_return == event && :instance_eval == method_id) ||
(:c_call == event && :disable == method_id)
)
end
|
#ending?(point) ⇒ Boolean
140
141
142
143
144
145
146
|
# File 'lib/trace_tree/point.rb', line 140
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
124
125
126
|
# File 'lib/trace_tree/point.rb', line 124
def inspect
to_h.inspect
end
|
#method_defined_by_define_method? ⇒ Boolean
230
231
232
233
|
# File 'lib/trace_tree/point.rb', line 230
def method_defined_by_define_method?
(event == :call || event == :return) &&
method_id != frame_env
end
|
#method_name ⇒ Object
170
171
172
173
174
|
# File 'lib/trace_tree/point.rb', line 170
def method_name
return method_id if c_call?
return frame_env if b_call? || class?
(method_id == frame_env) ? method_id : "#{method_id} -> #{frame_env}"
end
|
#return_value ⇒ Object
119
120
121
122
|
# File 'lib/trace_tree/point.rb', line 119
def return_value
raise RuntimeError.new('RuntimeError: not supported by this event') unless x_return?
@return_value
end
|
#same_method?(point) ⇒ Boolean
136
137
138
|
# File 'lib/trace_tree/point.rb', line 136
def same_method? point
point.defined_class == defined_class and point.method_id == method_id
end
|
#source_location ⇒ Object
180
181
182
|
# File 'lib/trace_tree/point.rb', line 180
def source_location
"#{path}:#{lineno}"
end
|
#terminate?(point) ⇒ Boolean
132
133
134
|
# File 'lib/trace_tree/point.rb', line 132
def terminate? point
same_method?(point) and ending?(point)
end
|
#thread? ⇒ Boolean
108
109
110
|
# File 'lib/trace_tree/point.rb', line 108
def thread?
event =~ /thread/
end
|
#thread_relative? ⇒ Boolean
225
226
227
228
|
# File 'lib/trace_tree/point.rb', line 225
def thread_relative?
NativeThreadCall.any?{ |k| k.class_of? self } ||
Thread == defined_class
end
|
#to_h ⇒ Object
128
129
130
|
# File 'lib/trace_tree/point.rb', line 128
def to_h
self.class.hashify(self)
end
|
#x_return? ⇒ Boolean
104
105
106
|
# File 'lib/trace_tree/point.rb', line 104
def x_return?
event =~ /return/
end
|