Class: Google::Cloud::Debugger::BreakpointManager

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#app_rootString (readonly)

Application root directory, in absolute file path form.

Returns:

  • (String)


42
43
44
# File 'lib/google/cloud/debugger/breakpoint_manager.rb', line 42

def app_root
  @app_root
end

#on_breakpoints_changeMethod

Callback function invoked when new breakpoints are added or removed

Returns:

  • (Method)


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_breakpointsArray<Google::Cloud::Debugger::Breakpoint>

Get a list of all active breakpoints.

Returns:



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.

Returns:

  • (Boolean)

    True if no more active breakpoints are left. False otherwise.



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

#breakpointsArray<Google::Cloud::Debugger::Breakpoint>

Get a list of all breakpoints, both active and completed.

Returns:



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_breakpointsObject

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_breakpointsArray<Google::Cloud::Debugger::Breakpoint>

Get a list of all completed breakpoints.

Returns:



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.

Parameters:

Returns:

  • (Google::Cloud::Debugger::Breakpoint, NilClass)

    The same breakpoint if successfully marked off as completed. Nil if this breakpoint isn't found in the list of active breakpoints or failed to mark off as completed.



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.

Parameters:

  • debuggee_id (String)

    Debuggee application ID

Returns:

  • (Boolean)

    True if synced successfully; otherwise false.



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.

Parameters:



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