Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Wiki Markup
{redirect:https://www.jetbrains.com/idea/help/debugging-with-chronon.html|delay=0}

Table of Contents

What this tutorial is about

This tutorial aims to walk you step-by-step through debugging a Java application with Chronon, a recorder and a "time-travelling" debugger. Chronon records changes made by your application while it is executing. The recordings are saved to files. You can later play these recordings back and share them among the team members.

What this tutorial is not about

...

Preparing an example

Let’s see how Chronon works on a simple example of a two-thread class. One thread performs quick sorting, while the second thread performs bubble sorting.

...

Open the Settings/Preferences dialog. To do that, click on the main toolbar, or press

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Alt+S{span}
. Under the IDE Settings
span
classshortcut
Wiki Markup
{span:class=shortcut}IDE Settings{span}
, click the node Plugins
span
classshortcut
Wiki Markup
{span:class=shortcut}Plugins{span}
.

The Chronon plugin is not bundled with IntelliJ IDEA, that's why you have to look for it in the JetBrains Plugins Repository. This is how it's done...

In the Plugins page, click the button

Install JetBrains
span
classshortcut
Wiki Markup
{span:class=shortcut}Install JetBrains plugin...{span}
to download and install plugins from the JetBrains repository. In the Browse JetBrains Plugins
span
classshortcut
Wiki Markup
{span:class=shortcut}Browse JetBrains Plugins{span}
dialog box, find the Chronon plugin - you can type the search string in the filter area:

...

After restart, pay attention to the following changes:

  • Dedicated Run with Chronon
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Run with Chronon{span}
    icon appears on the main toolbar. By now, this icon is disabled. It will become enabled as soon as the corresponding run/debug configuration appears.
  • Clicking this button opens the Chronon tool window (which also becomes available on launching the a run/debug configuration with Chronon, or on opening a Chronon record).
  • Chronon tab appears in the run/debug configuration of the Application type (and some other types as well).
  • Run
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Run{span}
    menu is extended with two commands:
    • span
      classshortcut
      Run <run/debug configuration name> with Chronon
    • span
      classshortcut
      Open Chronon recording
    • Wiki Markup
      {span:class=shortcut}Run &lt;run/debug configuration name&gt; with Chronon{span}
    • Wiki Markup
      {span:class=shortcut}Open Chronon recording{span}
  • Wiki Markup
    {span:class=shortcut}Run &lt;run/debug configuration name&gt; with Chronon{span}
    and
    Wiki Markup
    {span:class=shortcut}Add logging statement{span}
    commands appear on the editor's context menu.

Creating run/debug configuration

To launch our application, we need a run/debug configuration. Let's create one.

On the main menu, choose

Run→Edit Configuration
span
classshortcut
Wiki Markup
{span:class=shortcut}Run&rarr;Edit Configuration{span}
, and in the Run/Debug Configurations dialog box, click . We are going to create a new run/debug configuration of the Application type, so select this type:

...

First, give this run/debug configuration a name. Let it be ChrononDemo. Next, press

span
classshortcut
Wiki Markup
{span:class=shortcut}Shift+Enter{span}
and find the class with the main method ChrononDemo.java. This class resides in the package demo:

...

Defining include/exclude patterns

Next, click the tab

Chronon
span
classshortcut
Wiki Markup
{span:class=shortcut}Chronon{span}
. In this tab, you have to specify which classes IntelliJ IDEA should look at. This is done by Include / Exclude Patterns:

...

Now apply changes and close the dialog. The preliminary steps are ready.

Running

...

with Chronon

OK, it's time to launch our application. To do that, either click the Chronon button on the main toolbar, or choose

Run→Run with ChrononDemo with Chronon
span
classshortcut
Wiki Markup
{span:class=shortcut}Run&rarr;Run ChrononDemo with Chronon{span}
on the main menu.

Let's choose the first way:

...

First thing that you see is the Run tool window that shows Chronon messages:

It is important to note that a Chronon record is NOT created, when you terminate your application by clicking Image Added. If it is necessary to stop an application and still have a Chronon record, click the Exit button Image Added on the toolbar of the Run tool window.

Then the Chronon tool window appears - it look looks very much like the Debug tool window. In this tool window you see a record created by Chronon - ; so doing, each record shows in its own tab:

Opening an existing record

By the way, if you want to open one of the previous records, use

Wiki Markup
{span:class=shortcut}Run&rarr;Open Chronon recording{span}
on the main menu, and then choose the desired record:

Image Added

What can you do with a record?

In the Chronon tool window, you can:

Switch between threads

This is most easy - just switch to the Threads tab, and double-click the thread you are interested in. The selected thread is shown in boldface in the list of threads; besides that, the information about the currently selected thread appears in the upper-right part of the Chronon tool window:

Image Added

Note the progress bar. It shows the amount of passed events in the current thread:

Image Added

Step through the application

Actually, you can use either the stepping commands of the

Wiki Markup
{span:class=shortcut}Run{span}
menu, or the stepping buttons of the Chronon tool window. Unlike the debugger that allows only stepping forward, Chronon makes it possible to step through the applications in the reverse direction also. So, besides the traditional stepping buttons, there is Step Backwards button Image Added and Run Backwards to Cursor button Image Added.

Use bookmarks

Suppose you've stopped at a certain line, for example, in the main method of the class ChrononDemo.java:

Image Added

You want to memorize this place with its event number, to be able to return to it from any other location. This is where the Bookmarks tab becomes helpful. Switch to this tab, and click Image Added. A bookmark for the current event, thread and method is created:

Image Added

So doing, the bookmark memorizes the event number, thread and method name. Next, when you are in a different place of the code, clicking this bookmark in the Bookmarks tab will return you to this particular place.

Explore methods

If you look at the editor, you notice the icons Image Added in the left gutter next to the method declarations. Hovering the mouse pointer over such an icon shows a tooltip with the number of the recorded calls.

However, if you want to see a particular call event, then select the desired thread in the Threads tab (remember - the selected thread is shown in upper right part of the Chronon tool window), switch to the Method History tab, and track the execution history of a method:

Image Added

Thus you can explore the method execution, with the input and output data, which makes it easy to see how and where a method has been invoked.

Log values

What is the Logging tab for? By default, it is empty. However, using this tab makes it possible to define custom logging statements and track their output during application run.

This is how logging works. In the editor, right-click the statement of interest, and choose

Wiki Markup
{span:class=shortcut}Add logging statement{span}
on the context menu. Then, in the dialog box that opens, specify the variable you want to watch in the format

Code Block

${variable name}

Image Added

Next, to make use of this logging statement, click Image Added in the toolbar of the Logging tab. In the right-hand side of the Logging tab, the output of the logged statement is displayed:

Image Added

Note that such logging is equivalent to adding an output statement to your application; you could have added

Code Block

System.out.println(<variable name>);

However, this would require application rebuild and rerun. With Chronon's logging facility, such complications are avoided.

Explore exceptions

Suppose you want to find out how and when an exception has occurred. The Exceptions tab shows all exceptions that took place during the application execution. If you double click an exception, IntelliJ IDEA will bring you directly to the place of the exception occurrence:

Image Added

Summary

You've learned how to:

  • Download and install Chronon plugin for IntelliJ IDEA
  • Launch an application with Chronon recording.
  • Open existing Chronon recordings.
  • Work with the Chronon tool window. By the way, refer to the Hide/Restore Toolbar section of the Debug tool window reference to learn how to show/hide tabs.

This tutorial is over - congrats!