Class: AppMap::Trace::MethodEvent
- Inherits:
-
MethodEventStruct
- Object
- Struct
- MethodEventStruct
- AppMap::Trace::MethodEvent
- Defined in:
- lib/appmap/trace/tracer.rb
Direct Known Subclasses
Rails::ActionHandler::HTTPServerRequest::Call, Rails::SQLHandler::SQLCall, EventHandler::RackHandlerWebrick::Call, MethodCall, MethodReturnIgnoreValue
Constant Summary collapse
- LIMIT =
100- COUNTER_LOCK =
:nodoc:
Mutex.new
- @@id_counter =
0
Instance Attribute Summary
Attributes inherited from MethodEventStruct
#defined_class, #event, #id, #lineno, #method_id, #path, #static, #thread_id
Class Method Summary collapse
-
.build_from_tracepoint(me, tp, path) ⇒ Object
Build a new instance from a TracePoint.
-
.display_string(value) ⇒ Object
Gets a display string for a value.
-
.next_id ⇒ Object
Gets the next serial id.
-
.value_in_binding(tp, key, &block) ⇒ Object
Gets a value, by key, from the trace point binding.
Class Method Details
.build_from_tracepoint(me, tp, path) ⇒ Object
Build a new instance from a TracePoint.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/appmap/trace/tracer.rb', line 51 def build_from_tracepoint(me, tp, path) me.id = next_id me.event = tp.event if tp.defined_class.singleton_class? me.defined_class = (tp.self.is_a?(Class) || tp.self.is_a?(Module)) ? tp.self.name : tp.self.class.name else me.defined_class = tp.defined_class.name end me.method_id = tp.method_id me.path = path me.lineno = tp.lineno me.static = tp.defined_class.name.nil? me.thread_id = Thread.current.object_id end |
.display_string(value) ⇒ Object
Gets a display string for a value. This is not meant to be a machine deserializable value.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/appmap/trace/tracer.rb', line 87 def display_string(value) return nil unless value last_resort_string = lambda do warn "AppMap encountered an error inspecting a #{value.class.name}: #{$!.}" '*Error inspecting variable*' end value_string = \ begin value.to_s rescue NoMethodError begin value.inspect rescue StandardError last_resort_string.call end rescue StandardError last_resort_string.call end value_string[0...LIMIT].encode('utf-8', invalid: :replace, undef: :replace, replace: '_') end |
.next_id ⇒ Object
Gets the next serial id.
This method is thread-safe.
72 73 74 75 76 |
# File 'lib/appmap/trace/tracer.rb', line 72 def next_id COUNTER_LOCK.synchronize do @@id_counter += 1 end end |
.value_in_binding(tp, key, &block) ⇒ Object
Gets a value, by key, from the trace point binding. If the method raises an error, it can be handled by the optional block.
80 81 82 83 84 |
# File 'lib/appmap/trace/tracer.rb', line 80 def value_in_binding(tp, key, &block) tp.binding.eval(key.to_s) rescue NameError, ArgumentError yield if block_given? end |