Class: Google::Cloud::Debugger::Tracer
- Inherits:
-
Object
- Object
- Google::Cloud::Debugger::Tracer
- Defined in:
- lib/google/cloud/debugger/tracer.rb
Overview
Tracer
When active breakpoints are set for the debugger, the tracer monitors the running Ruby application and triggers evaluation when the code is executed at the breakpoint locations.
The tracer tracks the running application using several Ruby TracePoints and C level Ruby debugging API.
Instance Attribute Summary collapse
-
#agent ⇒ Google::Cloud::Debugger::Agent
readonly
The debugger agent this tracer belongs to.
-
#app_root ⇒ String
Ruby application root directory, in absolute path form.
Instance Method Summary collapse
-
#breakpoint_hit(breakpoint, call_stack_bindings) ⇒ Object
Callback function when a breakpoint is hit.
-
#start ⇒ Object
Get the sync the breakpoints cache with BreakpointManager.
-
#stop ⇒ Object
Stops all tracing.
-
#update_breakpoints_cache ⇒ Object
Update tracer's private breakpoints cache with the list of active breakpoints from BreakpointManager.
Instance Attribute Details
#agent ⇒ Google::Cloud::Debugger::Agent (readonly)
The debugger agent this tracer belongs to
35 36 37 |
# File 'lib/google/cloud/debugger/tracer.rb', line 35 def agent @agent end |
#app_root ⇒ String
Ruby application root directory, in absolute path form. The Stackdriver Debugger Service only knows the relative application file path. So the tracer needs to combine relative file path with application root directory to get full file path for tracing purpose
43 44 45 |
# File 'lib/google/cloud/debugger/tracer.rb', line 43 def app_root @app_root end |
Instance Method Details
#breakpoint_hit(breakpoint, call_stack_bindings) ⇒ Object
Callback function when a breakpoint is hit. Handover the hit breakpoint to breakpoint_manager to be evaluated.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/google/cloud/debugger/tracer.rb', line 109 def breakpoint_hit breakpoint, call_stack_bindings return if breakpoint.nil? || breakpoint.complete? agent.breakpoint_manager.breakpoint_hit breakpoint, call_stack_bindings update_breakpoints_cache # Disable all trace points and tracing if all breakpoints are complete disable_traces if @breakpoints_cache.empty? end |
#start ⇒ Object
Get the sync the breakpoints cache with BreakpointManager. Start tracing and monitoring if there are any breakpoints.
135 136 137 138 |
# File 'lib/google/cloud/debugger/tracer.rb', line 135 def start update_breakpoints_cache enable_traces unless breakpoints_cache.empty? end |
#stop ⇒ Object
Stops all tracing.
142 143 144 |
# File 'lib/google/cloud/debugger/tracer.rb', line 142 def stop disable_traces end |
#update_breakpoints_cache ⇒ Object
Update tracer's private breakpoints cache with the list of active breakpoints from BreakpointManager.
This methood is atomic for thread safety purpose.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/google/cloud/debugger/tracer.rb', line 87 def update_breakpoints_cache active_breakpoints = agent.breakpoint_manager.active_breakpoints.dup breakpoints_hash = {} active_breakpoints.each do |active_breakpoint| breakpoint_line = active_breakpoint.line breakpoint_path = full_breakpoint_path active_breakpoint.path breakpoints_hash[breakpoint_path] ||= {} breakpoints_hash[breakpoint_path][breakpoint_line] ||= [] breakpoints_hash[breakpoint_path][breakpoint_line].push( active_breakpoint) end # Tracer is explicitly designed to not have a lock. This should be the # only place writing @breakpoints_cache to ensure thread safety. @breakpoints_cache = breakpoints_hash end |