RESIStats.mesa;
Last Edited by: Sweet, March 4, 1985 4:29:04 pm PST
DIRECTORY
AMBridge,
AMTypes,
Basics,
Convert,
IO,
RefTab: FROM "LinkHash",
ListerUtils,
OpDebug,
PrincOps,
PrincOpsUtils,
RESInterpreter,
Rope;
RESIStats: CEDAR PROGRAM    
IMPORTS AMBridge, AMTypes, Convert, IO, LinkHash: RefTab, OpDebug, PrincOpsUtils
EXPORTS RESInterpreter =
BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
Byte: TYPE = Basics.Byte;
Machine: TYPE = RESInterpreter.Machine;
PrintByColumns: PUBLIC PROC [
os: STREAM,
PrintOne: PROC [os: STREAM, item: CARDINAL, lastOnLine: BOOL],
firstItem, nItems, nColumns, spaceBetween: CARDINAL] = {
i, j, nc: CARDINAL;
delta: CARDINAL ← (nItems + nColumns - 1) / nColumns;
last: BOOL;
FOR i IN [0..delta) DO
nc ← 0;
last ← FALSE;
FOR j ← i, j + delta WHILE ~last AND j < nItems DO
nc ← nc + 1;
last ← nc = nColumns;
PrintOne[os, firstItem + j, last];
IF ~last THEN THROUGH [0..spaceBetween] DO os.PutChar[' ]; ENDLOOP;
ENDLOOP;
os.PutChar['\n];
ENDLOOP;
};
Sort: PUBLIC PROC [
a: LONG DESCRIPTOR FOR ARRAY OF REF,
After: PROC [REF, REF] RETURNS [BOOL]] = TRUSTED {
TreeSort3, -1's to fake 1 origin arrays.
n: CARDINAL = LENGTH[a];
i: CARDINAL;
temp: REF ANY;
SiftUp: PROC [l, u: CARDINAL] = TRUSTED {
s: CARDINAL;
key: REF ANY ← a[l-1];
DO
s ← l*2;
IF s > u THEN EXIT;
IF s < u AND After[a[s+1-1], a[s-1]] THEN s ← s+1;
IF After[key, a[s-1]] THEN EXIT;
a[l-1] ← a[s-1];
l ← s;
ENDLOOP;
a[l-1] ← key};
FOR i DECREASING IN [2..n/2] DO SiftUp[i, n]; ENDLOOP;
FOR i DECREASING IN [2..n] DO
SiftUp[1, i];
temp ← a[1-1];
a[1-1] ← a[i-1];
a[i-1] ← temp;
ENDLOOP;
};
PrintOpCounts: PUBLIC PROC [os: STREAM, m: RESInterpreter.Machine] = TRUSTED {
OpItemRec: TYPE = RECORD [op: Byte, count: INT, cumPct: REAL];
OpItemSeq: TYPE = RECORD [SEQUENCE n: CARDINAL OF REF OpItemRec];
oseq: REF OpItemSeq ← NIL;
total: INT← 0;
rTotal: REAL;
nonZ: CARDINAL ← 0;
oc: REF ARRAY Byte OF INT = m.opCount;
opData: ListerUtils.OpCodeArray ← OpDebug.OpData[];
SmallerCount: PROC [i1, i2: REF OpItemRec] RETURNS [BOOL] = TRUSTED {
RETURN [i1.count < i2.count]};
PrintOpItem: PROC [os: STREAM, item: CARDINAL, lastOnLine: BOOL] = TRUSTED {
op: Byte = oseq[item].op;
count: INT = oseq[item].count;
opName: ROPE = opData[op].name;
os.PutF["%9g %5g %5g %-6g",
[integer[count]],
[rope[Convert.RopeFromReal[(oseq[item].count/rTotal)*100, 3]]],
[rope[Convert.RopeFromReal[oseq[item].cumPct, 3]]],
[rope[opName]]]};
FOR i: CARDINAL IN Byte DO
IF oc[i] # 0 THEN {
nonZ ← nonZ + 1;
total ← total + oc[i]};
ENDLOOP;
IF nonZ = 0 THEN RETURN;
rTotal ← total;
total ← 0;
oseq ← NEW [OpItemSeq[nonZ]];
nonZ ← 0;
FOR i: CARDINAL IN Byte DO
IF oc[i] # 0 THEN {
oseq[nonZ] ← NEW [OpItemRec ← [op: i, count: oc[i], cumPct: NULL]];
nonZ ← nonZ + 1};
ENDLOOP;
Sort[a: LOOPHOLE[DESCRIPTOR[oseq]], After: LOOPHOLE[SmallerCount]];
FOR i: CARDINAL IN [0..nonZ) DO
count: INT = oseq[i].count;
total ← total + count;
oseq[i].cumPct ← (total / rTotal) * 100;
ENDLOOP;
os.PutF[
" %g outward calls\n", IO.int[m.outCalls]];
PrintByColumns[
os: os, PrintOne: PrintOpItem, firstItem: 0, nItems: nonZ, nColumns: 2, spaceBetween: 0];
};
PrintProcCounts: PUBLIC PROC [os: STREAM, m: Machine] = TRUSTED {
lc: LinkHash.Ref;
LinkItemRec: TYPE = RECORD [link: PrincOps.ControlLink, count: LONG CARDINAL];
LinkItemSeq: TYPE = RECORD [SEQUENCE n: CARDINAL OF REF LinkItemRec];
ShortOctal: PROC [n: CARDINAL] RETURNS [IO.Value] = TRUSTED {
RETURN [[rope[Convert.RopeFromInt[n, 8, n>7]]]]};
SmallerCount: PROC [i1, i2: REF LinkItemRec] RETURNS [BOOL] = TRUSTED {
RETURN [i1.count < i2.count]};
lseq: REF LinkItemSeq ← NIL;
n: CARDINAL ← 0;
CountItems: LinkHash.EachPairAction = TRUSTED {IF val^ # 0 THEN n ← n+1; RETURN[FALSE]};
InsertItem: LinkHash.EachPairAction = TRUSTED {
IF val^ = 0 THEN RETURN[FALSE];
lseq[n] ← NEW[LinkItemRec ← [link: key.link, count: val^]];
n ← n+1; RETURN[FALSE]};
TRUSTED {lc ← LOOPHOLE[m.xferData]};
IF lc = NIL THEN {
os.PutRope["Not remembering Xfers"];
RETURN};
[] ← LinkHash.Pairs[lc, CountItems];
lseq ← NEW [LinkItemSeq[n]];
n ← 0;
[] ← LinkHash.Pairs[lc, InsertItem];
Sort[a: LOOPHOLE[DESCRIPTOR[lseq]], After: LOOPHOLE[SmallerCount]];
os.PutF["\n Outward Calls from interpreter (%g total)\n", [integer[m.outCalls]]];
FOR i: CARDINAL IN [0..n) DO
item: REF LinkItemRec = lseq[i];
tv: AMTypes.TV ← AMBridge.TVForProc[LOOPHOLE[item.link]];
gfTv: AMTypes.TV ← AMBridge.TVForGFHReferent[PrincOpsUtils.GlobalFrame[item.link]];
os.PutF["%8g %8g %4g\t%g\t(%g)\n",
[cardinal[item.count]],
ShortOctal[LOOPHOLE[item.link]],
[integer[item.link.gfi]],
[rope[AMTypes.TVToName[tv]]],
[rope[AMTypes.TVToName[gfTv]]]];
ENDLOOP;
os.PutRope["~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"];
};
END.