Hide
Tools

Using the Cloud Debugger

After you have deployed or started your application, you can open the Cloud Debugger in the Google Developers Console. The debugger allows you to capture and inspect the call stack and local variables in your application without stopping or slowing it down.

Contents

Snapshots

A snapshot captures the local variables and call stack at a specific line location in your source code. The snapshot location applies to all running instances of your application. The first time any instance executes the code at the location, the Cloud Debugger takes a snapshot and makes it available for viewing. You can then examine the snapshot and use the data to debug your application. The debugger implements several strategies for minimizing the amount of latency caused when capturing the data.

Set a snapshot location

To set a snapshot location:

  1. Select Source Code > Browse in the left-hand navigation panel of the Google Developers Console.
  2. Navigate to the file that contains the source code you want to watch.
  3. Click the Debug button Debug button. The Cloud Debugger panel opens.
  4. Click the line number of the source code location.

Set a snapshot location

Snapshot condition

A snapshot condition is a simple expression in the application language (Java) that tells the Cloud Debugger to take a snapshot only when it evaluates to true. Snapshot conditions are evaluated separately for each application instance. You can only have one condition per snapshot.

You can specify a snapshot condition after you have set the snapshot location. To specify the condition:

  1. Click the Plus button next to the Condition label in the snapshot panel.
  2. Enter an expression.
  3. Press the Enter key or the Snapshot button.

The following are examples of snapshot conditions:

travelAccessory == “Towel”
ultimateAnswer <= 42

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

travelAccessory == “Towel” && ultimateAnswer <= 42

You can use the following language features to express conditions:

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

The following language features are not supported:

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

Watch expressions

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

Typical uses for watch 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.

You can specify a watch expression after you have set the snapshot location. To specify the watch expression:

  1. Click the Plus button next to the Add Expression label in the snapshot panel.
  2. Enter the expression in the Expression field.
  3. Press the Enter key or the Snapshot button. The result of the watch expression is shown when the snapshot is taken.

View a snapshot

Snapshot data appears in the Cloud Debugger when the application executes the source code at the location you specified. Instance variables and local variables appear in the Local section of the panel. The stack trace appears in the Call Stack section of the panel.

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 function further up the call stack, 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 data at the same location, you must manually retake it.

To retake a snapshot, click the Snapshot button near the top of the debugger panel.

Snapshot button

Remove a snapshot location

You can remove a snapshot location by clicking the snapshot icon next to the line number in your code.

Snapshot icon

Share snapshots

You can share a snapshot with another project member by copying the snapshot URL from your browser and giving it to another user who has access to your project. You can also save this URL for future reference and come back to it again to view its results. The Cloud 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. Sharing expires thirty days after the snapshot has been taken.

Close the Cloud Debugger

Click the Debug button again (Debug button) to close the Cloud Debugger panel and return to normal source code browsing.