Working with snapshots

Once you have set up debugging in Stackdriver Debugger and have deployed and/or started your application, you can take or view debug snapshots in the source console.

Snapshots

Snapshots capture local variables and the call stack at a specific line location in your application source code. You can specify certain conditions and locations to return a snapshot of your application state, and view it in detail to debug your app.

A few seconds after you set the line location, the snapshot applies to all running instances of your application. The first time any instance executes the code at the snapshot location, Stackdriver Debugger takes a snapshot and makes it available for viewing. The debugger implements several strategies for minimizing the amount of latency caused when capturing the data.

Snapshots might not available during startup while the debugger initializes in the background.

Take a debug snapshot

  1. In the left panel of the console, select the file that contains the source code to watch.

  2. Click the line number of the source code location.

    Select snapshot location

  3. Select the application you want to debug when prompted.

    Select snapshot application

  4. Click Create Snapshot.

    Create snapshot

    The new snapshot appears in the bottom panel of the console.

    New snapshot

Snapshot conditions (optional)

A snapshot condition is an expression in the application language that must evaluate to true for the snapshot to be taken. Expressions in Java, Python, and Go are supported. Snapshot conditions are evaluated each time the line is executed, by any instance, until the condition evaluates to true or the snapshot times out.

The condition is a full boolean expression that can include logical operators:

travelAccessory == "Towel"
ultimateAnswer <= 42
travelAccessory == "Towel" && ultimateAnswer <= 42

Set a snapshot condition

  1. Select the snapshot in the Snapshots tab in the bottom panel of the console.

    Select snapshot

  2. Click Edit Snapshot in the right-hand panel that opens.

    Edit snapshot

  3. Enter the snapshot condition in the Conditions field where prompted.

  4. Click Update.

You can use the following language features to express conditions:

Java

Most Java expressions are supported, including:
  • Local variables: a == 8.
  • Numerical and boolean operations: x + y < 20.
  • Instance and static fields: this.counter == 20, this.myObj.isShutdown, myStatic, or com.mycompany.MyClass.staticMember.
  • String comparisons with the equality operator: myString == "abc".
  • Function calls. Only read-only functions can be used. For example, StringBuilder.indexOf() is supported, but StringBuilder.append() is not.
  • Type casting, with fully qualified types: ((com.myprod.ClassImpl) myInterface).internalField.

The following language features are not supported:

  • Unboxing of numeric types, such as Integer; use myInteger.value instead.

Python

Most Python expressions are supported, including:
  • Reading local and global variables.
  • Reading from arrays, lists, slices, dictionaries and objects.
  • Calling simple methods.

The following language features are not supported:

  • Calling functions that allocate new objects or use complex constructs.
  • Creating new objects inside the expression.

Go (Beta)

Most Go expression syntax is supported, including:
  • Reading local and global variables.
  • Reading from arrays, slices, maps, and structs.

The following language features are not supported:

  • Reading from interface values.
  • Type conversions and composite literals.
  • Function calls other than len.

Expressions (optional)

Snapshot expressions allow you to evaluate complex expressions or traverse object hierarchies when a snapshot is taken. Expressions support the same language features as snapshot conditions, described above.

Typical uses for expressions are:

  • To view static or global variables that are not part of the local variable set.

  • To easily view deeply nested member variables without having to expand a local variable in the debugger panel every time.

  • To avoid repetitive mathematical calculations. For example, calculating a duration in seconds with (endTimeMillis - startTimeMillis) / 1000.0.

Add an expression

  1. Select the snapshot in the Snapshots tab in the bottom panel of the console.

    Select snapshot

  2. Click Edit Snapshot in the right-hand panel that opens.

    Edit snapshot

  3. Enter the expression in the Expression field. Press the tab key to add additional expressions.

  4. Click Update.

View a snapshot

Snapshot data appears in the source console when the application executes the source code at the location you specified.

  1. Select the snapshot in the Snapshots tab in the bottom panel of the console.

    Select snapshot

    The Snapshot Details panel appears and displays values of instance variables and the stack trace at the snapshot code location.

    View snapshot

    You can examine the value of local variables at the moment the snapshot was taken and drill down into deeper data structures. You can also click on any call stack frame, and examine the local variables at that level in the stack.

Retake a snapshot

A snapshot is only taken once. If you want to capture another snapshot of your application state at the same location, hover over the snapshot in the Snapshots panel at the bottom of the console and click the Retake button.

Retake snapshot

Remove a snapshot location

To remove a snapshot location, hover over the snapshot in the Snapshots panel and click the trash can icon.

Share snapshots

You can share a snapshot with another project member by sharing the snapshot URL from your browser. You can also save this URL for future reference and come back to it again to view its results. Stackdriver Debugger uses a new URL for each snapshot taken. This allows you to share distinct sets of results even if they were captured at the same location in the code.

What's next

本頁內容對您是否有任何幫助?請提供意見:

傳送您對下列選項的寶貴意見...

這個網頁
Cloud Source Repositories