CodeTimer.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Last edited by Bier on June 18, 1986
Contents: Routines for maintaining a table of average times for user-specified operations.
DIRECTORY
BasicTime, IO;
CodeTimer: CEDAR DEFINITIONS =
BEGIN
Table: TYPE = REF TableObj;
TableObj: TYPE = RECORD [
intervals: LIST OF Interval,
name: ATOM
];
Interval: TYPE = REF IntervalObj;
IntervalObj: TYPE = RECORD [
name: ATOM,
subintervals: LIST OF Interval,
starts, stops, unmatchedStarts: CARD,
startTime: BasicTime.Pulses,
totalTime: BasicTime.Pulses,
maxTime: BasicTime.Pulses,
maxIndex: CARD,
minTime: BasicTime.Pulses
];
Getting ready to test performance.
CreateTable: PROC [name: ATOM] RETURNS [table: Table];
Creates a table and registers it in a global database, so it can be retrieved by name. If a table of this name already exists, it is reset and returned.
GetTable: PROC [name: ATOM] RETURNS [table: Table];
Retrieve a table by name. StartInterval[$IntervalName, GetTable[$TableName]] is a sensible way to start an interval that is deep in the code of a known application.
ResetTable: PROC [table: Table];
Set all of the interval times to zero.
CreateInterval: PROC [name: ATOM, subintervals: LIST OF Interval ← NIL] RETURNS [interval: Interval];
AddInterval: PROC [interval: Interval, table: Table];
AddInt: PROC [interval: Interval, tableName: ATOM];
Equivalent to AddInterval[interval, GetTable[tableName]].
ResetInterval: PROC [name: ATOM, table: Table];
Testing performance.
StartInterval: PROC [name: ATOM, table: Table];
StartInt: PROC [intervalName: ATOM, tableName: ATOM];
Equivalent to StartInterval[intervalName, GetTable[tableName]].
StopInterval: PROC [name: ATOM, table: Table];
StopInt: PROC [intervalName: ATOM, tableName: ATOM];
Equivalent to StopInterval[intervalName, GetTable[tableName]].
Printing results.
PrintTable: PROC [f: IO.STREAM, table: Table];
Calls PrintInterval for all intervals in table.
PrintInterval: PROC [f: IO.STREAM, interval: Interval, nestingLevel: NAT ← 0];
Print the statistics for interval into stream f as a single line of text. Proceed the line with nestingLevel TABS. Subintervals will be proceeded by nestingLevel+1 TABS. All times are in milli-seconds. "start" is the number of times this interval was executed. "total" is the total milli-seconds spent in the interval overall. "avg" is the average number of milli-seconds spent per interval execution, averaged over all of the executions. "min" and "max" are the times for the shortest and longest execution. "index" is the number of times the interval had been entered when the longest execution took place. "overflows" is the number of times the interval was started without being stopped; if all is well, overflows = 0.
PrintInt: PROC [f: IO.STREAM, intervalName: ATOM, tableName: ATOM, nestingLevel: NAT ← 0];
Like PrintInterval but looks up the table and interval from their names. All times are in milli-seconds.
IntervalStatistics: TYPE = REF IntervalStatisticsObj;
IntervalStatisticsObj: TYPE = RECORD [
name: ATOM,
starts: CARD,
totalMsec: CARD,
averageMsec: CARD,
minMsec: CARD,
maxMsec: CARD,
worstInterval: CARD,
startsWithoutStops: CARD
];
GetIntervalStats: PROC [interval: Interval] RETURNS [starts: CARD, totalMsec: CARD, averageMsec: CARD, minMsec: CARD, maxMsec: CARD, worstInterval: CARD, startsWithoutStops: CARD, subIntervals: LIST OF IntervalStatistics];
Like PrintInterval but returns the values for use by a client instead of writing them to a stream. Values for sub-intervals cannot currently be retrieved. All times are in milli-seconds.
GetIntStats: PROC [intervalName: ATOM, tableName: ATOM] RETURNS [starts: CARD, totalMsec: CARD, averageMsec: CARD, minMsec: CARD, maxMsec: CARD, worstInterval: CARD, startsWithoutStops: CARD, subIntervals: LIST OF IntervalStatistics];
Like PrintInt but returns the values for use by a client instead of writing them to a stream. All times are in milli-seconds.
END.