MAINPM User's Guide, Chapter 6

previous   next   top   contents   index   framed top   this page unframed


6. User-Specified Resource Monitoring

The MAINPM command TIMING takes an optional argument that specifies what quantity is to be regarded as time. If no TIMING command is given, CPU time is the default. The available arguments are:

TIMING Argument Effect
TIME monitor CPU time (the default)
USER monitor a user-specified time

If the TIMING command has an argument, the command must be given before the monitored program is executed.

Only a unique prefix of an argument need be specified (at present the first letter is sufficient), and case does not matter. An invalid argument (e.g., ?) causes the list of valid arguments to be displayed.

TIMING USER indicates that the user program has defined a kind of resource whose use is to be measured (called the “user-defined time”, although it can represent any resource, not just time). There must be a LONG INTEGER variable that is updated by the program as appropriate to show the passage of user-defined time. The MAINPM timing mechanism must have access to this variable throughout execution of the monitored program. The program tells MAINPM where the variable is by initializing two variables:

  1. $timerPtr, a POINTER “base”

  2. $timerDspl, a LONG INTEGER displacement from $timerPtr

The user-defined time variable must be at the ADDRESS given by displace($timerPtr,$timerDspl). $timerPtr and $timerDspl must be initialized before the monitored program starts executing (this means they cannot be initialized in a monitored MODULE's INITIAL PROCEDURE; a separate MODULE must be invoked to initialize them before the monitoring of the program starts).

For example, the program can allocate a dynamic record with a LONG INTEGER field, then initialize $timerPtr to point to the record and $timerDspl to be the displacement to that field:

CLASS timerClass (LONG INTEGER userTime);
...
$timerPtr := new(timerClass);
$timerDspl := cvli(DSP(timerClass.userTime));

To increment the time, the program does:

$timerPtr:timerClass.userTime .+ <amount to increment>;

You can also decrement the time, to indicate that a resource has been “unconsumed”. In this case, the MAINPM printout shows the net time (which may be negative) used by each PROCEDURE or MODULE.

Both shallow and deep times are maintained. If the user-defined time is updated in the body of a PROCEDURE (or MODULE), then the shallow time (and deep time) of that PROCEDURE (or MODULE) is affected. If the user-defined time is updated by a PROCEDURE called inline, the effect is as if the user-defined time were incremented in the caller.

6.1. User-Defined Time Example

The MODULE FOO in Example 6–1 uses some resource of which the programmer wishes to keep track. consumeResource is called to allocate the resource and releaseResource to deallocate it.

When run from MAINPM, the MODULE shown in Example 6–2 must be run before timing starts in order to initialize $timerPtr; see Example 6–3.

Example 6–1. A User-Timed MODULE
BEGIN "foo"

CLASS timerCls (LONG INTEGER userTime);

...

INLINE PROCEDURE consumeResource;
BEGIN
...
IF $timerPtr THEN $timerPtr:timerCls.userTime .+ 1L END;



INLINE PROCEDURE releaseResource;
BEGIN
...
IF $timerPtr THEN $timerPtr:timerCls.userTime .- 1L END;

...

END "foo"

Example 6–2. MODULE to Run before FOO
BEGIN "preFoo"

CLASS timerCls (LONG INTEGER userTime);

INITIAL PROCEDURE;
BEGIN
$timerPtr := new(timerCls);
$timerDspl := cvli(DSP(timerClass.userTime));
END;

END "preFoo"

Example 6–3. Timing FOO
MAINPMexecute prefoo<eol>
MAINPMtiming user<eol>
MAINPMexecute foo<eol>

    
... FOO executes...

MAINPMlist foo.mpm<eol>


previous   next   top   contents   index   framed top   this page unframed

MAINPM User's Guide, Chapter 6