-- AltoMesaPerfMonitor.Mesa; edited by
-- Sandman on September 15, 1980  3:09 PM  
-- Karlton on June 20, 1980  4:00 PM  

DIRECTORY
  ControlDefs USING [Port],
  FrameDefs USING [MakeCodeResident],
  MiscDefs USING [Zero],
  OsStaticDefs USING [OsStatics],
  PerfBreakHandler USING [
    activeFudge, breakBlock, BreakBlock, currentState, fudge, legTab, machine,
    MonitorBreaks, nodeTab, perfRecord, WBPort],
  PerfDefs USING [],
  PerfPrivate USING [
    HistIndex, HistSpaceSize, LegTab, MaxLegs, MaxNodes, NodeTab, NullHist,
    NullID, NullNode, PerfControlRecord, VersionID],
  SDDefs USING [sBreakBlock, sBreakBlockSize, sCoreSwap, SD, sPerfMonitor],
  Storage USING [Words],
  TimingDefs USING [Fudges];

AltoMesaPerfMonitor: PROGRAM
  IMPORTS FrameDefs, MiscDefs, PerfBreakHandler, Storage
  EXPORTS PerfDefs
  SHARES PerfBreakHandler =

  BEGIN OPEN PerfPrivate, PerfBreakHandler;


  InitPerfData: PROCEDURE =
    BEGIN OPEN Storage;
    i: CARDINAL;
    p: POINTER ← Words[SIZE[NodeTab] + SIZE[LegTab] + HistSpaceSize];
    nodes: POINTER TO NodeTab ← p;
    legs: POINTER TO LegTab ← p + SIZE[NodeTab];
    MiscDefs.Zero[p, SIZE[NodeTab] + SIZE[LegTab] + HistSpaceSize];
    perfRecord ← PerfControlRecord[
      version: VersionID, measuringNow: FALSE, newSession: TRUE, addLeg: none,
      trackLeg: all, totalBreaks: 0, perfTime: 0, totalTime: 0, self: NIL,
      saveBreakHandler: NIL, nextNode: 0, process: NIL, nodeTable: nodes,
      nextLeg: 0, legTable: legs, lastID: NullNode, pulseConversion: 3810,
      histBase: p + SIZE[NodeTab] + SIZE[LegTab], lastCall: normal,
      histFree: FIRST[HistIndex]];
    SDDefs.SD[SDDefs.sPerfMonitor] ← @perfRecord;
    SDDefs.SD[SDDefs.sBreakBlock] ← @breakBlock;
    SDDefs.SD[SDDefs.sBreakBlockSize] ← SIZE[BreakBlock];
    breakBlock.count ← 0;
    FOR i IN [0..MaxNodes) DO
      nodes[i] ←
	[id: NullID, hitsLow: 0, hitsHigh: 0, overflowed: FALSE, hist: NullHist];
      ENDLOOP;
    FOR i IN [0..MaxLegs) DO
      legs[i] ←
	[start: 0, from: NullNode, to: NullNode, owner: NIL, hitsLow: 0,
	  hitsHigh: 0, sum: 0, lock: FALSE, overflowed: FALSE, someIgnored: FALSE,
	  hist: NullHist];
      ENDLOOP;
    SELECT OsStaticDefs.OsStatics.AltoVersion.engineeringnumber FROM
      2, 3, 5 => BEGIN machine ← altoII; fudge ← TimingDefs.Fudges[altoII] END;
      4 => BEGIN machine ← d0; fudge ← TimingDefs.Fudges[d0] END;
      ENDCASE => BEGIN machine ← altoI; fudge ← TimingDefs.Fudges[altoI] END;
    activeFudge ← fudge[currentState ← hi];
    nodeTab ← nodes;
    legTab ← legs;
    END;

  FrameDefs.MakeCodeResident[LOOPHOLE[PerfBreakHandler]];
  START PerfBreakHandler;
  InitPerfData[];
  LOOPHOLE[WBPort, ControlDefs.Port] ←
    [representation[in: 0, out: SDDefs.SD[SDDefs.sCoreSwap]]];
  MonitorBreaks[];

  END...