Debugging a Program With dbx HomeContentsPreviousNextIndex


Chapter 10

Data Visualization

If you need a way to display your data graphically as you debug your program from Sun WorkShop, you can use data visualization.

You can use data visualization during debugging to help you explore and comprehend large and complex data sets, simulate results, or interactively steer computations. The Data Graph window lets you "see" program data and analyze that data graphically. The graphs can be printed or printed to a file.

This chapter contains the following sections:

Specifying Proper Array Expressions

To display your data, you must specify the array and how it should be displayed. You can open the Data Graph window from the Sun WorkShop Debugging window by typing an array name in the Expression text box. (See "Evaluating an Array" in the Using the Debugging Window section of the Sun WorkShop online help.) All scalar array types are supported except for complex (Fortran) array types.

Single-dimensional arrays are graphed (a vector graph) with the x-axis indicating the index and the y-axis indicating the array values. In the default graphic representation of a two-dimensional array (an area graph), the x-axis indicates the index of the first dimension, the y-axis indicates the index of the second dimension, while the z-axis represents the array values. You can visualize arrays of n dimensions, but at most, only two of those dimensions can vary.

You do not have to examine an entire data set. You can specify slices of an array, as shown in the following examples. FIGURE 10-1 and FIGURE 10-2 show the bf array from the sample Fortran program given at the end of this chapter.


FIGURE 10-1   (left) bf Array Name Only; (right) bf(0:3,1:20)

The next two figures show the array with a range of values:


FIGURE 10-2   Array bf: (left) bf(-3:3,:); (right) bf(:,-7:7)

Graphing an Array

You can compare different points during the execution of an application by graphing selected expressions in the source code. You can use the graph to observe where problems occur in the program. The Data Graph window enables you to graph arrays and examine different views of the same data. (See "Data Graph Window" in the Using the Debugging Window section of the Sun WorkShop online help.)

All arrays, except complex Fortran arrays, are supported.

Getting Ready

Before you can graph an array, you must:

1. Load a program into the Sun WorkShop Debugging window by doing one of the following:

2. Set at least one breakpoint in the program.

You can set a single breakpoint at the end of the program, or you can set one or more at points of interest in your program (see "Breaking at a Location" in the Using the Debugging Window section of the Sun WorkShop online help).

3. Run your program.

(See "Starting Your Program Using Start" in the Using the Debugging Window section of the Sun WorkShop online help.)
When the program stops at the breakpoint, decide which array you want to examine.

Multiple Ways to Graph an Array

Now you can graph the array. Sun WorkShop provides multiple ways to graph an array through Sun WorkShop:

Automatic Updating of Array Displays

The value of an array expression can change as the program runs. You can choose whether to show the array expression's new values at specific points within the program or at fixed time intervals in the Update section on the Data Grapher tab of the Sun WorkShop Debugging Options dialog box. (See "Data Grapher Defaults in the Using the Debugging Window section of the Sun WorkShop online help.)

If you want the values of an array updated each time the program stops at a breakpoint, you must turn on the Update at: Program stops option. As you step through the program, you can observe the change in array value at each stop. Use this option when you want to view the data change at each breakpoint. The default setting for this feature is off.

If you have a long-running program, choose the Update at: Fixed time interval option to observe changes in the array value over time. With a fixed time update, a timer is automatically set for every nth period. The default time is set for one second intervals. To change the default setting, choose Graph Default Options and change the time interval in the Debugging Options dialog box. (See "Displaying Updated Array Values" in the Using the Debugging Window section of the Sun WorkShop online help).


Note – Every time the timer reaches the nth period, Sun WorkShop tries to update the graph display; however, the array could be out of scope at that particular time and no update can be made.

Because the timer is also used in collecting data and when checking for memory leaks and access checking, you cannot use the Update at Fixed time interval setting when you are running the Sampling Collector or the runtime checking feature.

Changing Your Display

Once your data is graphically displayed, you can adjust and customize the display using the controls in the Data Graph window. This section presents examples of some of graph displays that you can examine.

The Data Graph window opens with the Magnify and Shrink options present when graphing any type of array. With an area graph, the window includes the Axis Rotation and Perspective Depth fields. These options let you change your view of the graph by rotating its axis or increasing or decreasing the depth perspective. To quickly rotate the graph, hold down the right mouse button with the cursor on the graph and drag to turn the graph. You can also enter the degree of rotation for each axis in the Axis Rotation field.

Click Show Options for more options. If the options are already shown, click Hide to hide the additional options.

FIGURE 10-3 shows two displays of the same array. The figure on the left shows the array with a Surface graph type with the Wire Mesh texture. The figure on the right shows the array with a Contour graph type delineated by range lines.


FIGURE 10-3   Two Displays of the Same Array

When you choose a Contour graph type, the range options let you see areas of change in the data values.

The display options for the Surface graph type are texture, shading, and fill.

Texture choices for the Surface graph type are Wire Mesh and Range Lines as shown in FIGURE 10-4 .

FIGURE 10-4   Surface graph with Wire Mesh (left) and Range Lines (right)

Shading choices for the Surface graph type are Light Source and Range Colors as shown in FIGURE 10-5 .

FIGURE 10-5   Surface Graph with Light Source (left) and Range Colors (right)

Turn on Fill to shade in areas of a graph or to create a solid surface graph as shown in FIGURE 10-6.

FIGURE 10-6   Surface Graph shaded in areas (left) or with a Solid Surface (right)

Choose Contour as the graph type to display an area graph using data range lines. With the Contour graph type, you have the additional options of displaying the graph in lines, in color, or both, as shown in FIGURE 10-7.


FIGURE 10-7   Contour Graph with Lines (left), in Color (center), or Both (right)

You can change the number of data value ranges being shown (see FIGURE 10-8) by changing the value in the Ranges: No. of steps text box.


FIGURE 10-8   Contour Graph with Number of Steps (left to right): 5, 10, 15

If you choose a large number of steps, you can adversely affect the color map.

Click the Show range legend check box if you want a legend to display your range intervals.

Analyzing Visualized Data

There are different ways to update the data being visualized, depending on what you are trying to accomplish. For example, you can update on demand, at breakpoints, or at specified time intervals. You can observe changes or analyze final results. This section provides several scenarios illustrating different situations.

Two sample programs, dg_fexamp (Fortran) and dg_cexamp (C), are included with Sun WorkShop. These sample programs are used in the following scenarios to illustrate data visualization.

You can also use these programs for practice. They are located in install-dir/Sunrises/WS6/examples/gatecrasher, where the default install-dir is /opt. To use the programs, change to this directory and type make, the executable programs are created for you.

Scenario 1: Comparing Different Views of the Same Data

The same data can be graphed multiple times, letting you compare different graph types and different segments of data.

1. Load the C or Fortran sample program.

2. Set a breakpoint at the end of the program.

(See "Breaking at a Location'" in the Using the Debugging Window section of the Sun WorkShop online help.)

3. Start the program, running the program to that breakpoint.

(See "Starting Your Program Using Start" in the Using the Debugging Window section of the Sun WorkShop online help.)

4. Type bf in the Expression text box in the Debugging window.

5. Choose Data Graph Expression.

A surface graph of both dimensions of the bf array is displayed.

6. Choose Data Graph Expressions again to display a duplicate graph.

7. Click Show Options and click the Contour radio button for the graph type in one of the Data Graph windows.

Now you can compare different views of the same data (Surface versus Contour).

8. Type bf(1,:) for the Fortran or bf[1][..] for the C example program in the Expression text box.

9. Choose Data Graph Expression to display a graph of a section of the data contained in the bf array.

You can now compare these different views of the data.

Scenario 2: Updating Graphs of Data Automatically

You can control the updating of a graph automatically by turning on the Update at: Program stops option on the Data Grapher tab of the Sun WorkShop Debugging Options dialog box. This feature lets you make comparisons of data as it changes during the execution of the program.

1. Load the C or Fortran sample program.

2. Set a breakpoint at the end of the outer loop of the bf function.

(See "Breaking at a Location'" in the Using the Debugging Window section of the Sun WorkShop online help.)

3. Start the program, running the program to that breakpoint.

(See "Starting Your Program Using Start" in the Using the Debugging Window section of the Sun WorkShop online help.)

4. Type bf into the Expression text box in the Debugging window.

5. Choose Data Graph Expression.

A graph of the values in the bf array after the first loop iteration is displayed.

6. Click Show Options and select the Update At: Program stops checkbox.

7. Choose Execute Continue to cause the execution of several other loop iterations of the program.

Each time the program stops at the breakpoint, the graph is updated with the values set in the previous loop iteration.

Using the automatic update feature can save time when you want an up-to-date view of the data at each breakpoint.

Scenario 3: Comparing Data Graphs at Different Points in a Program

You can manually control the updating of a graph.

1. Load the C or Fortran example program.

2. Set a breakpoint at the end of the outer loop of the af function.

(See "Breaking at a Location'" in the Using the Debugging Window section of the Sun WorkShop online help.)

3. Start the program, running the program to that breakpoint.

(See "Starting Your Program Using Start" in the Using the Debugging Window section of the Sun WorkShop online help.)

4. Type af in the Expression text box in the Debugging window.

5. Choose Data Graph Expression.

A graph of the values in the af array after the first loop iteration is displayed. Make sure automatic updating is turned off on this graph (the default setting).

6. Execute another loop iteration of the program by choosing Execute Continue.

7. Display another graph of the af array by choosing Data Graph Expression.

This graph contains the data values set in the second iteration of the outer loop.

You can now compare the data contained in the two loop iterations of the af array. You can use any graph with automatic updating turned off as a reference graph to a graph that is continually being updated automatically or manually.

Scenario 4: Comparing Data Graphs from Different Runs of the Same Program

Data graphs persist between different runs of the same program. Graphs from previous runs are not overwritten unless they are manually updated or automatic updating is turned on.

1. Load the C or Fortran example program.

2. Set a breakpoint at the end of the program.

(See "Breaking at a Location'" in the Using the Debugging Window section of the Sun WorkShop online help.)

3. Start the program, running the program to the breakpoint.

(See "Starting Your Program Using Start" in the Using the Debugging Window section of the Sun WorkShop online help.)

4. Type vec in the Expression text box in the Debugging window.

5. Choose Data Graph Expression.

A graph of the vec array is displayed (as a sine curve).

6. Now you can edit the program (for example, replace sin with cos).

Use fix and continue (see Chapter 11) to recompile the program and continue (click the Fix tool bar button).

7. Restart the program.

Because automatic updating is turned off, the previous graph is not updated when the program reaches the breakpoint.

8. Choose Data Graph Expression (vec is still in the Expression text box).

A graph of the current vec values is displayed beside the graph of the previous run.

You can now compare the data from the two runs. The graph of the previous run changes only if it is updated manually using the update button or if automatic updating is turned on.

Fortran Program Example

real x,y,z,ct
real vec(100)
real af(50,50)
real bf(-3:3,-10:20)
real cf(50, 100, 200)
 
do x = 1,100
            ct = ct + 0.1
            vec(x) = sin(ct)
enddo
 
do x = 1,50
           do y = 1,50
              af(x,y) = (sin(x)+sin(y))*(20-abs(x+y))
           enddo
 enddo
 
do x = -3,3
          do y = -10,20
            bf(x,y) = y*(y-1)*(y-1.1)-10*x*x*(x*x-1)
          enddo
enddo
 
do x = 1,50
          do y = 1,100
            do z = 1,200
              cf(x,y,z) = 3*x*y*z - x*x*x - y*y*y - z*z*z
            enddo
          enddo
enddo
 
end

C Program Example

#include <math.h>
main()
{
    int x,y,z;
    float ct=0;
    float vec[100];
    float af[50][50];
    float bf[10][20];
    float cf[50][100][200];
 
    for (x=0; x<100; x++)
    {
          ct = ct + 0.1;
          vec[x] = sin(ct);
    }
    for (x=0; x<50; x++)
    {
          for (y=0; y<50; y++)
          {
          af[x][y] = (sin(x)+sin(y))*(20-abs(x+y));
          }
    }
    for (x=0; x<10; x++)
    {
          for (y=0; y<20; y++)
          {
            bf[x][y] = y*(y-1)*(y-1.1)-10*x*x*(x*x-1);
          }
    }
    for (x=0; x<50; x++)
    {
          for (y=0; y<100; y++)
          {
          for (z=0; z<200; z++)
          {
                    cf[x][y][z] = 3*x*y*z - x*x*x - y*y*y - z*z*z ;
          }
          }
    }
}


Sun Microsystems, Inc.
Copyright information. All rights reserved.
Feedback
Library   |   Contents   |   Previous   |   Next   |   Index