Class: Google::Cloud::Debugger::BreakpointManager
- Inherits:
-
Object
- Object
- Google::Cloud::Debugger::BreakpointManager
- Includes:
- MonitorMixin
- Defined in:
- lib/google/cloud/debugger/breakpoint_manager.rb
Overview
BreakpointManager
Responsible for querying Stackdriver Debugger service for any active breakpoints and keep an accurate local copies of the breakpoints.
It correctly remembers which breakpoints are currently active and watched by the debugger agent, and which breakpoints are already completed. The BreakpointManager holds the record of truth for debugger breakpoints
Instance Attribute Summary collapse
-
#app_root ⇒ String
readonly
Application root directory, in absolute file path form.
-
#on_breakpoints_change ⇒ Method
Callback function invoked when new breakpoints are added or removed.
Instance Method Summary collapse
-
#active_breakpoints ⇒ Array<Google::Cloud::Debugger::Breakpoint>
Get a list of all active breakpoints.
-
#all_complete? ⇒ Boolean
Check whether any active breakpoints haven't been completed yet.
-
#breakpoints ⇒ Array<Google::Cloud::Debugger::Breakpoint>
Get a list of all breakpoints, both active and completed.
-
#clear_breakpoints ⇒ Object
Clear local breakpoints cache.
-
#completed_breakpoints ⇒ Array<Google::Cloud::Debugger::Breakpoint>
Get a list of all completed breakpoints.
-
#mark_off(breakpoint) ⇒ Google::Cloud::Debugger::Breakpoint, NilClass
Mark a given active breakpoint as completed.
-
#sync_active_breakpoints(debuggee_id) ⇒ Boolean
Sync active breakpoints with Stackdriver Debugger service for a given debuggee application.
-
#update_breakpoints(server_breakpoints) ⇒ Object
Update the local breakpoints cache with a list of server active breakpoints.
Instance Attribute Details
#app_root ⇒ String (readonly)
Application root directory, in absolute file path form.
42 43 44 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 42 def app_root @app_root end |
#on_breakpoints_change ⇒ Method
Callback function invoked when new breakpoints are added or removed
47 48 49 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 47 def on_breakpoints_change @on_breakpoints_change end |
Instance Method Details
#active_breakpoints ⇒ Array<Google::Cloud::Debugger::Breakpoint>
Get a list of all active breakpoints.
188 189 190 191 192 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 188 def active_breakpoints synchronize do @active_breakpoints end end |
#all_complete? ⇒ Boolean
Check whether any active breakpoints haven't been completed yet.
199 200 201 202 203 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 199 def all_complete? synchronize do @active_breakpoints.empty? end end |
#breakpoints ⇒ Array<Google::Cloud::Debugger::Breakpoint>
Get a list of all breakpoints, both active and completed.
166 167 168 169 170 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 166 def breakpoints synchronize do @active_breakpoints | @completed_breakpoints end end |
#clear_breakpoints ⇒ Object
Clear local breakpoints cache. Remove all active and completed breakpoints
208 209 210 211 212 213 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 208 def clear_breakpoints synchronize do @active_breakpoints.clear @completed_breakpoints.clear end end |
#completed_breakpoints ⇒ Array<Google::Cloud::Debugger::Breakpoint>
Get a list of all completed breakpoints.
177 178 179 180 181 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 177 def completed_breakpoints synchronize do @completed_breakpoints end end |
#mark_off(breakpoint) ⇒ Google::Cloud::Debugger::Breakpoint, NilClass
Mark a given active breakpoint as completed. Meaning moving it from list of active breakpoints to completed breakpoints.
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 148 def mark_off breakpoint synchronize do breakpoint = @active_breakpoints.delete breakpoint if breakpoint.nil? nil else @completed_breakpoints << breakpoint breakpoint end end end |
#sync_active_breakpoints(debuggee_id) ⇒ Boolean
Sync active breakpoints with Stackdriver Debugger service for a given debuggee application. Each request to the debugger service returns the full list of all active breakpoints. This method makes sure the local cache of active breakpoints is consistent with server breakpoints set.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 78 def sync_active_breakpoints debuggee_id begin response = service.list_active_breakpoints debuggee_id, @wait_token rescue return false end return true if response.wait_expired @wait_token = response.next_wait_token server_breakpoints = response.breakpoints || [] server_breakpoints = server_breakpoints.map do |grpc_b| Breakpoint.from_grpc grpc_b end update_breakpoints server_breakpoints true end |
#update_breakpoints(server_breakpoints) ⇒ Object
Update the local breakpoints cache with a list of server active breakpoints. New breakpoints will be added to local cache, and deleted breakpoints will be removed from local cache.
It also correctly identifies evaluated active breakpoints from the server set of breakpoints, and does not re-add such evaluated breakpoints to the active list again.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 111 def update_breakpoints server_breakpoints synchronize do new_breakpoints = server_breakpoints - @active_breakpoints - @completed_breakpoints before_breakpoints_count = @active_breakpoints.size + @completed_breakpoints.size # Remember new active breakpoints from server @active_breakpoints += new_breakpoints unless new_breakpoints.empty? # Forget old breakpoints @completed_breakpoints &= server_breakpoints @active_breakpoints &= server_breakpoints after_breakpoints_acount = @active_breakpoints.size + @completed_breakpoints.size breakpoints_updated = !new_breakpoints.empty? || (before_breakpoints_count != after_breakpoints_acount) on_breakpoints_change.call(@active_breakpoints) if on_breakpoints_change.respond_to?(:call) && breakpoints_updated end end |