[Previous Example] [Next Example] [Overview of Examples] [User's Guide]

Examples\Simple\Ex03_Logging_Data

Example 3: Logging Data

Introduction

So far, we have attached our probe actions to various points in the program, without accessing any of its data. In this example, we will learn how to access and record the values of global variables and parameters from your target program. We will also learn how to use the log directive to automate the recording and formatting of data.

The basic idea of logging data is to record the dynamic part of the data, and defer the formatting until after the program is finished (when time is no longer critical). The data is logged to an APD file. After runtime, the apformat tool takes the raw data produced by the probe and makes it readable. Logging is described in detail in Chapter 3, "Logging and Formatting Data".

Target Program

For this as well as all other examples in the Simple folder, we will be using the same target program Examples\Target\Hello.c, which was described in Example 1.

Writing the Probe

Here is a probe which will record the value of parameter Year on entry to subprogram SayHello:

Hello.apc

probe thread
{
   probe "hello.c":"SayHello()"
   {
   on_entry
      log("Calling SayHello(", $Year, ")");
   }
}

Running The Example

  1. Build the probe.
  2. Run the program with Aprobe.
  3. Format the collected data.
  4. Examine the output of the formatting process in the window inside the Aprobe workspace labeled hello-0.apd.
You should see the following output:
    Calling SayHello(1999)

Immediate Formatting

Normally, you'd run apformat to format the data in the APD file after your program has ended. But Aprobe gives you the option of forcing the formatting at the same time as the data is logged. This is called immediate formatting. It is an alternative to running apformat. This is done using the -if option on the aprobe command line, or in the Aprobe Workspace as follows:
  1. Open the Workspace->Application Settings... dialog.
  2. Check the Format Immediately box under Aprobe Options.
  3. Click OK.
  4. Run the program with Aprobe again.

Exercises

  1. Modify hello.apc to log the value of static variable ThisYear. Note that ThisYear is a static variable, and will be initialized before the program starts. Therefore you can log its value on entry to a program or thread.
  2. Hint: add the following into your probe in hello.apc:

    log ("This year was: ", $ThisYear);

  3. Fix the Y2K problem: assign '2000' to the parameter "Year". Rerun the example. You should see a new output from your target program now, "Calling SayHello(2000)".

  4. Hint: add the following on_entry action into your probe:

    $ThisYear = 2000;

Summary

From this example you have learned:
[Previous Example] [Next Example] [Overview of Examples] [User's Guide]