SPARCWindowStatsImpl.mesa
Copyright Ó 1991 by Xerox Corporation. All rights reserved.
Michael Plass, September 27, 1991 12:31 pm PDT
DIRECTORY Convert, Process, UnixSpawn, Rope, Commander, IOClasses, IO, SPARCWindowStats, CommanderOps;
SPARCWindowStatsImpl: CEDAR MONITOR
IMPORTS Convert, Process, UnixSpawn, Commander, IOClasses, IO, CommanderOps
EXPORTS SPARCWindowStats
~ BEGIN
inpush, inpull: IO.STREAM ¬ NIL;
outpush, outpull: IO.STREAM ¬ NIL;
Helper: PROC ~ {
[] ¬ UnixSpawn.Spawn[
command: "crash",
wd: "/tmp",
stdin: inpull,
stdout: outpush,
stderr: outpush,
exec: FALSE,
tty: FALSE,
debug: FALSE
];
IO.PutRope[outpush, " DONE "];
IO.Close[outpush];
};
Start: INTERNAL PROC ~ {
IF inpush = NIL THEN {
[push:inpush, pull:inpull] ¬ IOClasses.CreatePipe[];
[push:outpush, pull:outpull] ¬ IOClasses.CreatePipe[];
Process.Detach[FORK Helper[]];
};
};
GetSPARCWindowStats: PUBLIC ENTRY PROC RETURNS [overflowcnt, underflowcnt: CARD ¬ 0] ~ {
ENABLE UNWIND => NULL;
IF inpush = NIL THEN Start[];
IO.PutRope[inpush, "od -d overflowcnt 2\n"];
UNTIL IO.GetChar[outpull] = ': DO ENDLOOP;
overflowcnt ¬ IO.GetCard[outpull];
underflowcnt ¬ IO.GetCard[outpull];
};
SPARCWindowStatsCommand: Commander.CommandProc ~ {
overflowcnt, underflowcnt: CARD;
[overflowcnt, underflowcnt] ¬ GetSPARCWindowStats[];
IO.PutF[cmd.out, "%g %g\n", [cardinal[overflowcnt]], [cardinal[underflowcnt]]];
};
SPARCWindowDeltaCommand: Commander.CommandProc ~ {
overflowcnt, underflowcnt: CARD ¬ 0;
postoverflowcnt, postunderflowcnt: CARD ¬ 0;
[overflowcnt, underflowcnt] ¬ GetSPARCWindowStats[];
[result: result, msg: msg] ¬ CommanderOps.ExecuteCommand[cmd, cmd.commandLine];
[postoverflowcnt, postunderflowcnt] ¬ GetSPARCWindowStats[];
IO.PutFL[cmd.out, "%L-- Register window overflows: %g, underflows: %g%L\n", LIST[[rope["i"]], [cardinal[postoverflowcnt-overflowcnt]], [cardinal[postunderflowcnt-underflowcnt]], [rope["I"]]]];
};
SPARCWindowThrashCommand: Commander.CommandProc ~ {
ENABLE Convert.Error => CommanderOps.Failed[cmd.procData.doc];
count: CARD ¬ Convert.CardFromRope[CommanderOps.NextArgument[cmd]];
calldepth: CARD ¬ Convert.CardFromRope[CommanderOps.NextArgument[cmd]];
Inner: PROC [d: CARD] ~ {
IF count # 0 AND d > 1 THEN Inner[d - 1];
IF count # 0 THEN count ¬ count - 1;
};
UNTIL count = 0 DO
Inner[calldepth];
ENDLOOP;
};
Commander.Register["SPARCWindowStats", SPARCWindowStatsCommand, "get overflowcnt/underflowcnt statistics"];
Commander.Register["SPARCWindowDelta", SPARCWindowDeltaCommand, "Do a command, measuring overflowcnt/underflowcnt statistics (uninterpreted)", NIL, FALSE];
Commander.Register["SPARCWindowThrash", SPARCWindowThrashCommand, "Beat on register windows. args: count calldepth"];
END.