Class: Google::Cloud::Debugger::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/debugger/agent.rb

Overview

Agent

The Stackdriver Debugger Agent runs on the same system where a debuggee application is running. The agent is responsible for sending state data, such as the value of program variables and the call stack, to Stackdriver Debugger when the code at a breakpoint location is executed.

The Debugger Agent runs in its own child thread when started. It ensures the instrumented application is registered properly and constantly monitors for any active breakpoints. Once the agent gets updated with active breakpoints from Stackdriver Debugger service, it facilitates the breakpoints in application requests thread, then transport the result snapshot back to Stackdriver Debugger service asynchronously.

Examples:

require "google/cloud/debugger"

debugger = Google::Cloud::Debugger.new
agent = debugger.agent
agent.start

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, module_name:, module_version:) ⇒ Agent

Create a new Debugger Agent instance.

Parameters:

  • service (Google::Cloud::Debugger::Service)

    The gRPC Service object

  • module_name (String)

    Name for the debuggee application. Optional.

  • module_version (String)

    Version identifier for the debuggee application. Optional.



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/google/cloud/debugger/agent.rb', line 98

def initialize service, module_name:, module_version:
  super()

  @service = service
  @debuggee = Debuggee.new service, module_name: module_name,
                                    module_version: module_version
  @tracer = Debugger::Tracer.new self
  @breakpoint_manager = BreakpointManager.new service
  @breakpoint_manager.on_breakpoints_change =
    method :breakpoints_change_callback

  @transmitter = Transmitter.new service, self
end

Instance Attribute Details

#breakpoint_managerGoogle::Cloud::Debugger::BreakpointManager (readonly)

It manages syncing breakpoints between the Debugger Agent and Stackdriver Debugger service



70
71
72
# File 'lib/google/cloud/debugger/agent.rb', line 70

def breakpoint_manager
  @breakpoint_manager
end

#debuggeeGoogle::Cloud::Debugger::Debuggee (readonly)

The gRPC Debuggee representation of the debuggee application. It contains identification information to match running application to specific Cloud Source Repository code base, and correctly group same versions of the debuggee application together through a generated unique identifier.



64
65
66
# File 'lib/google/cloud/debugger/agent.rb', line 64

def debuggee
  @debuggee
end

#tracerGoogle::Cloud::Debugger::Tracer (readonly)

It monitors the debuggee application and triggers breakpoint evaluation when breakpoints are set.



76
77
78
# File 'lib/google/cloud/debugger/agent.rb', line 76

def tracer
  @tracer
end

#transmitterGoogle::Cloud::Debugger::Transmiter (readonly)

It sends evaluated breakpoints snapshot back to Stackdriver Debugger Service.

Returns:

  • (Google::Cloud::Debugger::Transmiter)


82
83
84
# File 'lib/google/cloud/debugger/agent.rb', line 82

def transmitter
  @transmitter
end

Instance Method Details

#startObject

Starts the Debugger Agent in a child thread, where debuggee application registration and breakpoints querying will take place. It also starts the transmitter in another child thread.



117
118
119
120
# File 'lib/google/cloud/debugger/agent.rb', line 117

def start
  transmitter.start
  async_start
end

#stopObject

Stops and terminates the Debugger Agent. It also properly shuts down transmitter and tracer.

Once Debugger Agent is stopped, it cannot be started again.



128
129
130
131
132
# File 'lib/google/cloud/debugger/agent.rb', line 128

def stop
  tracer.stop
  transmitter.stop
  async_stop
end

#stop_tracerObject

Stops the tracer regardless of whether any active breakpoints are present. Once the tracer stops monitoring the debuggee application, the application can return to normal performance.



138
139
140
# File 'lib/google/cloud/debugger/agent.rb', line 138

def stop_tracer
  tracer.stop
end