*-----------------------------------------------------------
Title[CpaStats.mc...May 15, 1986 2:10:19 pm PDT...Willie-Sue];
*
* gathers statistics for function calls, monitor entries, etc
*
*-----------------------------------------------------------
%
CONTENTS, by order of occurence
CPA   Enable/Disable statictics gathering
EFCStats  ExternalFunctionCall[n], T contains n
EFCBStats ExternalFunctionCallByte, ignore T
LFCStats  LocalFunctionCall[n], T contains 2*(n+1)
LFCBStats LocalFunctionCallByte, ignore T
KFCBStats KernelFunctionCallByte
SFCStats  StackFunctionCall
PortIStats  PortIn
PortoStats  PortOut
MeStats  MonitorEntry
MesStats  MonitorEntrySuccess
MreStats  MonitorReEntry
MresStats  MonitorReEntrySuccess
MxdStats  MonitorExitAndDepart
MxwStats  MonitorExitAndWait
NotifyStats Notify
BCastStatsBroadcast
ReqStats  Requeue
SwitchStats MesaReschedule
%
*-----------------------------------------------------------
* Stats offsets, must agree with CPA.mesa
MC[EFCOffset, 0];   * ExternalFunctionCall[n]
MC[EFCBOffset, 40];  * ExternalFunctionCallByte
MC[LFCOffset, 42];   * LocalFunctionCall[n]
MC[LFCBOffset, 102];  * LocalFunctionCallByte
MC[SFCOffset, 104];  * StackFunctionCall
MC[KFCBOffset, 106];  * KernelFunctionCallByte
MC[PortiOffset, 110];  * PortIn
MC[PortoOffset, 112];  * PortOut
MC[MEOffset, 114];  * MonitorEntrySuccess
MC[MESOffset, 116];  * MonitorEntryWait
MC[MREOffset, 120];  * MonitorReEntrySuccess
MC[MRESOffset, 122];  * MonitorReEntryWait
MC[MXWOffset, 124];  * MonitorExitAndWait
MC[MXDOffset, 126];  * MonitorExitAndDepart
MC[NOTIFYOffset, 130]; * Notify
MC[BCASTOffset, 132];  * Broadcast
MC[REQOffset, 134];  * Requeue
MC[SwitchOffset, 136];  * MesaReschedule
SetRMRegion[CPARegion];
RVN[CpaFlag];  * we hope it starts out >= 0
RVN[CpaTemp];
RVN[CpaSaveT];
RVN[CpaSavePointers];  * save membase & rbase, to restore
  TopLevel;
*-----------------------------------------------------------
* CPA[ptr: LONG POINTER TO CpaRecord]
* IF ptr = NIL, disables statistics gathering
* IF ptr # NIL, put it into BRforCPA and set CpaFlag non-zero
* T has TOS, StkP has been advanced
*-----------------------------------------------------------
DontKnowRBase;
CPA: MiscTable[245], StkP-2;
pd ← T OR (Stack);  * test for NIL
Branch[.+3, alu # 0], Membase ← BRforCPA;
CpaFlag ← A0;
StkP-1, IFUNext0;  * leave stack empty
T ← Stack, BrHi ← T;
BrLo ← T, StkP-1;
CpaFlag ← T - T - 1, IFUNext0;
*-----------------------------------------------------------
  Subroutine;
* All of the following restore T & membase
* rbase is left as RMforIFU (RTemp0 region)
* CpaFlag >=0 if not collecting stats - test this first
*-----------------------------------------------------------
EFCStats:
* T holds n
* saved in BRforCPA[EFCOffset+2*n]
*-----------------------------------------------------------
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
 KnowRBase[CpaFlag];
CpaSaveT ← T;
pd ← T - (17C);
T ← T + T, branch[.+2, alu <=0];
T ← EFCBOffset, branch[DoStat];
T ← T + (EFCOffset), branch[DoStat];
*-----------------------------------------------------------
EFCBStats:
* saved in BRforCPA[EFCBOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← EFCBOffset, branch[DoStat];
*-----------------------------------------------------------
LFCStats:
* T has 2*(n+1)
* saved in BRforCPA[LFCOffset+2*n]
*-----------------------------------------------------------
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
pd ← T - (42C);
branch[.+2, alu<=0];
T ← LFCBOffset, branch[DoStat];
T ← T - (2C);  * LFCOffset = 0
T ← T + (LFCOffset), branch[DoStat];
*-----------------------------------------------------------
LFCBStats:
* saved in BRforCPA[LFCBOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← LFCBOffset, branch[DoStat];
*-----------------------------------------------------------
KFCBStats:
* saved in BRforCPA[KFCBOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← KFCBOffset, branch[DoStat];
*-----------------------------------------------------------
SFCStats:
* saved in BRforCPA[SFCOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← SFCOffset, branch[DoStat];
*-----------------------------------------------------------
PortiStats:
* saved in BRforCPA[PortiOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← PortiOffset, branch[DoStat];
*-----------------------------------------------------------
PortoStats:
* saved in BRforCPA[PortoOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← PortoOffset, branch[DoStat];
*-----------------------------------------------------------
MeStats:
* saved in BRforCPA[MEOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← MEOffset, branch[DoStat];
*-----------------------------------------------------------
MesStats:
* saved in BRforCPA[MESOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← MESOffset, branch[DoStat];
*-----------------------------------------------------------
MreStats:
* saved in BRforCPA[MREOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← MREOffset, branch[DoStat];
*-----------------------------------------------------------
MresStats:
* saved in BRforCPA[MRESOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← MRESOffset, branch[DoStat];
*-----------------------------------------------------------
MxdStats:
* saved in BRforCPA[MXDOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← MXDOffset, branch[DoStat];
*-----------------------------------------------------------
MxwStats:
* saved in BRforCPA[MXWOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← MXWOffset, branch[DoStat];
*-----------------------------------------------------------
NotifyStats:
* saved in BRforCPA[NOTIFYOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← NOTIFYOffset, branch[DoStat];
*-----------------------------------------------------------
BcastStats:
* saved in BRforCPA[BCASTOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← BCASTOffset, branch[DoStat];
*-----------------------------------------------------------
ReqStats:
* saved in BRforCPA[REQOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← REQOffset, branch[DoStat];
*-----------------------------------------------------------
SwitchStats:
* saved in BRforCPA[SwitchOffset]
*-----------------------------------------------------------
Nop;
RBase ← RBase[CpaFlag];
Branch[.+2, R<0], CpaFlag;
RBase ← RBase[RTemp0], Return;
KnowRBase[CpaFlag];
CpaSaveT ← T;
T ← SwitchOffset, branch[DoStat];
*-----------------------------------------------------------
* LONG CARDINALs are stored with the low word first
*-----------------------------------------------------------
KnowRBase[cpaTemp];
DoStat:
CpaSavePointers ← Pointers;
Membase ← BRforCPA;
Fetch ← T;
cpaTemp ← MD + 1;
Branch[statExit, alu#0], T ← (Store ← T) + 1, DBuf ← cpaTemp;
Fetch ← T;
cpaTemp ← MD + 1;
Store ← T, DBuf ← cpaTemp;
StatExit: T ← CpaSaveT;
membase ← CpaSavePointers;
RBase ← RBase[RTemp0], Return;
TopLevel;