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

Examples\Simple\Ex06_Timing_Support_2

Example 6: Timing Support (continued)

Introduction

In this example, we will look at timing support in greater detail. We will learn how you can query the time at different points in the program, perform computations on the captured values, and format the results of these computations.

Target Program

For this example we will again use the same target program Examples\Target\Hello.c, which was described in Example 1.

Writing the Probe

Suppose that, just as in Example 4, we want to find out how long each call to SayHello() takes, except that this time we would prefer that the elapsed time computations be done automatically. The following probe does what we want:

Hello.apc

probe thread
{
   probe "hello.c":"SayHello()"
   {
      ap_TimeT EntryTime;
      ap_TimeT ExitTime;
      ap_TimeT TimeDifference;

   on_entry
      EntryTime = ap_GetCurrentTime();
   on_exit

      // Get the time on exit
      ExitTime = ap_GetCurrentTime();

      // calculate the execution time of the subprogram
      TimeDifference = ap_SubTime(ExitTime, EntryTime);

      // log the time difference
      log("SayHello() completed in => ", TimeDifference);
   }
}

Note the use of probe variables: EntryTime, ExitTime, and TimeDifference. They were declared inside the subprogram probe, so these variables will be alive only for the duration of the probe's target. This means that they are created for each call to "SayHello", and cease to exist after exiting from it. These variables could therefore be viewed as extensions of the local variable declaration list for the subprogram "SayHello".

This probe also takes advantage of a number of standard Aprobe types and functions defined in aprobe.h and described in Appendix C of the Aprobe User's Guide. Also see Chapter 3, Time Support for a discussion of the timing support functions and types.

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 something like the following output (of course the time value will vary):
SayHello() completed in => 00:00:00.000681861

Exercise

Modify "hello.apc" to compute and log time measurement overhead on entry to program. You can do this by capturing the value of the current time twice in succession, and subtracting the difference. Since no real action has been performed during this period of time, the resulting value should represent the time measurement overhead.

Summary

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