[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
- Build the probe.
- Run the program with Aprobe.
- Format the collected data.
- 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:
- Open the Workspace->Application Settings... dialog.
- Check the Format Immediately box under Aprobe Options.
- Click OK.
- Run the program with Aprobe again.
Exercises
-
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.
Hint: add the following into your probe in hello.apc:
log ("This year was: ", $ThisYear);
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)".
Hint: add the following on_entry action into your probe:
$ThisYear = 2000;
Summary
From this example you have learned:
-
How to reference objects from the target program
-
How to use the log directive
to record data for off-line formatting
-
How to use the
apformat
command for formatting the data collected by probes
-
How to use immediate formatting
[Previous Example]
[Next Example]
[Overview of Examples]
[User's Guide]