Tutorial for the Command-Line Debugger (Deprecated)

This topic steps you through a StreamBase debugging session using the legacy StreamBase command-line debugger, sbdb. This debugger runs in a UNIX terminal window or StreamBase Command Prompt.

Note

The sbdb debugger is deprecated and is likely to be removed from StreamBase in a future release. Use the visual debugger instead.

Introduction

The sbdb debugger allows you to see what is going on inside your StreamBase application, by inspecting and affecting the internal processing of your data.

This topic steps you through a sample debugging application that will cover most of the sbdb commands. If you have used program debuggers such as GDB before, the concepts will be familiar.

This tutorial assumes you will be running StreamBase Server and sbdb on the same physical machine, although sbdb can also be used to debug remote servers.

About the sbdb Tutorial

The StreamBase installation includes a sample application file that we will use throughout this sbdb tutorial, sbdbtutorial.sbapp. You can find it in streambase-install-dir/sample/sbdbtutorial. This application is small and simple for ease of this tutorial, but sbdb can be used to debug applications of any size and complexity, whether they are receiving live feeds of data or simulated streams via the StreamBase Feed Simulator.

Understanding the Application

Here is a brief description of the sbdbtutorial sample application we will be debugging.

  • There is one input stream, named InputStream. It consists of tuples of data with a single integer field, myint.

  • The first operator, SourceTagger, is a Map operator that adds a field called source with the constant value test. The next operator (Filter5K) filters the data according to the value of myint. Values of 5000 or less are sent to a Map operator (MapDouble) which doubles the value of myint. The output of both Filter5K and MapDouble are unioned back together with a Union operator before being output onto the output stream OutputStream.

Preparing to Run sbdb

Loading the Application onto StreamBase Server

We will now start the server and load the sbdbtutorial.sbapp application in a way that enables us to use sbdb with that application.

  1. Open a terminal window or StreamBase Command Prompt and navigate to the sbdbtutorial sample directory. (Paths to this directory are shown in About the sbdb Tutorial.)

  2. Type sbd -d sbdbtutorial.sbapp

    This causes StreamBase Server on the remote host machine to start in debug mode. A server in debug mode starts up ready to process tuples.

  3. Open another terminal window or StreamBase Command Prompt and enter the sbdb command.

Note

Do not run a production server in debug mode, as it will affect the performance of your application.

For a summary of the sbdb commands, see the sbdb reference topic.

Pausing the Server

Since StreamBase Server starts up in running mode, pause it before proceeding.

In the window where sbdb is running, type: pause.

sbdb> pause

Pause: OK
sbdb>

Generating Sample Data

sbdb allows debugging an application regardless of whether data is streaming into the server. For this tutorial, we will send a small amount of data from a file and step through the processing of those tuples.

Open a third terminal window or StreamBase Command Prompt and send the contents of input.csv to the application by entering:

sbc enqueue InputStream < input.csv

We are now ready to learn how to use sbdb. Return to the window running sbdb.

Using sbdb

sbdb starts with the following prompt:

sbdb> 

The sbdb> prompt indicates that sbdb is ready to receive your next command. You can see the complete list of commands by typing help in the Debugger. Let's begin our tutorial by using the status to find out some information about the server we are debugging.

sbdb> status

Status: Server is paused
0 breakpoints set
Thread 'main' is paused in i0:SourceTagger on (myint=2300)
sbdb>

Basic Commands

This section introduces the sbdb commands.

Status Command

The status command provides information about the server. Let's break down the status lines in the preceding example:

  • Server is paused: tells us that StreamBase Server is paused, and will not process data. Input data streaming into the server is buffered at the input streams, and clients consuming the output of the application can still continue to transfer data, but no internal processing of tuples will take place. Note that many debugging commands require the server to be paused.

  • 0 breakpoints set: tells us there are no breakpoints installed on the server. We will learn about breakpoints later in this tutorial.

  • Thread 'main' is paused in i0:SourceTagger on (myint=2300): tells us that the first operator in the thread, SourceTagger, is waiting to process data. The expression in parentheses that follows shows us the data that will be processed.

List Command

The list commands allow us to find out more about the loaded application. Let's try three of them now:

  • sbdb> list operators

    List: OK; 'default.Filter5K';'default.MapDouble';'default.SourceTagger';'default.Union';
    

    The output has listed all the operators in our application, alphabetically.

  • sbdb> list ports

    List: OK; 'i0:default.Filter5K';'i0:default.MapDouble';'i0:default.Union';'i1:default.Union';
    

    We have listed all the internal ports in our application. Each port represents an input port of an operator, where tuples are stored before processing by the operator. In the example, i0:default.Union represents the first input port of the operator called Union in the default container. This input port receives tuples output from the first port of the Filter5K operator.

  • sbdb> list threads

    List: OK;  'default';
    

    Only one thread is available in this application. Each application has one thread (default) for the top-level modules. Additonal threads are created for each parallelized operator or module reference.

We will look at the list breakpoints command in more detail later in this tutorial.

Step Command

The step command allows us to control the execution of operators and observe the flow of data within an application. The step command instructs the processing engine to execute the next operator in the current thread. The operator receives tuples on its input port or ports, and outputs any results. The number of tuples it will consume is not specified. Let's use the step command to trace the execution of this application:

  1. sbdb> step

    Step: OK; Now paused in i0:default.Filter5K on (myint=2300, source="test")
    

    This output confirms that the operation succeeded, then identifies the operator name and input port where the tuples were received. Observe that processing has advanced to the next operator in the thread. The output also lists the tuples that were consumed and produced by the operator.

  2. sbdb> step

    Step: OK; Now paused in i0:default.MapDouble on (myint=2300, source="test")
    

    Observe that our tuple pauses at the first input port of the MapDouble operator. This is predictable given the application design: the value of myint in this tuple is less than 5000, so it was released by the Filter5K operator on its first output port, which is connected to the MapDouble operator.

  3. sbdb> step

    Step: OK; Now paused in i1:default.Union on (myint=4600, source="test")
    

    This step executes the MapDouble operator, which multiplies myint by 2, and releases the result to the Union operator. Notice that the tuple is waiting on the Union operator's second input port (i1). This happened because the value of myinit is less than 5000; therefore the MapDouble operator releases the tuple on its second port. We will see this analysis confirmed again in the next section.

  4. sbdb> step

    Step: OK; Processing completed.
    

    This step executes the Union operator, which releases the tuple on the output stream. Finally, notice in the Debugger message that the next tuple in the feed simulation has been entered on the first operator. We will see that tuple executed in the next section.

Advanced Commands

The commands we have used up to this point allowed very fine, manual control over the processing of tuples. This may not be ideal if you wish to process a large number of tuples before inspecting StreamBase Server, or if you are operating on streaming input data that you do not know the contents of in advance. Breakpoints are a way of letting StreamBase Server pause for you when a certain condition on any input port is met. Let's work through an example.

Break Command

The break command is used to add a breakpoint on some input port, by placing a condition that is evaluated against every tuple entering this port. If the condition ever becomes true, the processing engine pauses itself, and sbdb sessions are notified of this event. Let's see an example of this in action.

Imagine that the value of myint should never exceed 8000, even after the doubling operation done by the MapDouble operator. To check for this condition, we will add a breakpoint on both input ports of the Union operator, as follows:

sbdb> break i0:default.Union myint>8000

Breakpoint: OK; Breakpoint 1 at i0:default.Union added.

sbdb> break i1:default.Union myint>8000

Breakpoint: OK; Breakpoint 2 at i0:default.Union added.
sbdb> 

We can confirm the breakpoints we added by using the list breakpoints command, which lists the breakpoint id, the break condition, and the location:

sbdb> list breakpoints

List: OK; 
[1]: myint>8000 on i0:default.Union
[2]: myint>8000 on i1:default.Union
sbdb>

Now we will unpause the server, allowing tuples to be processed until the moment one of our breakpoints is triggered. The trigger should be a tuple, entering either input port of the Union operator, whose myint field has a value greater than 8,000. To unpause the server, enter the following command. (You may have to restart the sbc enqueue command in another window.)

sbdb> continue

Continue: OK; 
sbdb>
Breakpoint 2 hit at i1:default.Union (myint=8010, source="test"); server is pausing
(Ctrl+L to redisplay your input line)
sbdb> 

This message indicates where a breakpoint was hit.

Although this message was displayed in response to your continue command, breakpoints can be triggered at any time during exectution. For UNIX, if a message is displayed while you were typing on the Debug command line, you can press Ctrl-L to redisplay the sbdb> prompt and any text you might have been typing when you were interrupted. For Windows, just type on the unprompted line that follows the last output.

Now run the status command.

sbdb> status

Status: Server paused
2 breakpoints set
Thread 'main' is paused in i1:default.Union on breakpoint 2 on (myint=8010, source="test")
sbdb> 

The server pauses right after the tuple triggered the breakpoint, and we can see the triggering tuple at the Union operator's second input port.

We can see that a tuple was output from the MapDouble operator with a value for myint of 8010, which triggered the breakpoint. Breakpoints can be set to handle a condition, or to pause the server as soon as any tuple enters some input port. (See help break for the exact syntax.)

Cleaning Up

Let's allow the application to process all of its data, by issuing the continue command now:

sbdb> continue

Continue: OK
sbdb> 

One last point to understand is that the paused state of the server and breakpoints are independent of your sbdb session. To demonstrate this, let's quit sbdb by typing the quit command:

sbdb> quit

Now startup sbdb again, and type status:

sbdb> status

Status: Server is not paused
2 breakpoints set

sbdb>

As you can see, the server remains in the last state it was in. Let's pause it, and view the server status and list any active breakpoints:

sbdb> pause

Pause: OK

sbdb> status

Status: Server is paused
2 breakpoints set
Thread 'default' is idle

sbdb> list breakpoints

List: OK; 
[1]: myint>8000 on i0:Union
[2]: myint>8000 on i1:Union
sbdb> 

As you can see, breakpoints remain installed on the server (until the next server shutdown). Let's remove them now:

sbdb> delete 1

Delete breakpoint: OK; Deleted breakpoint 1
sbdb> 

sbdb> delete 2

Delete breakpoint: OK; Deleted breakpoint 2
sbdb> 

Conclusion

This concludes our tutorial on using sbdb. We encourage you to try using sbdb on any other sample application. Refer to the sbdb reference topic for usage information.

Related Topics

  • sbdb topic in the StreamBase Command Reference

Back to Top ^