-- File: StatsHot.mesa - last edit:
-- AOF                  6-Jun-86 10:18:22
-- Copyright (C) 1982, 1986 by Xerox Corporation. All rights reserved. 

DIRECTORY
  CommFlags USING [doStats],
  CommHeap USING [zone],
  Stats USING [StatCounterIndex],
  StatsOps USING [];

StatsHot: PROGRAM IMPORTS CommHeap EXPORTS Stats, StatsOps =
  BEGIN

  <<
  These are the master counters.  They are the only ones that get bumped
  by StatIncr and StatBump.  The numbers that StatSince prints out are
  obtained by subtracting two copies of statGrand.
  >>

  statGrand: PUBLIC LONG POINTER TO StatGrand ← NIL;
  StatGrand: TYPE = ARRAY Stats.StatCounterIndex OF LONG CARDINAL;

  StatIncr: PUBLIC PROCEDURE [which: Stats.StatCounterIndex] =
    {IF CommFlags.doStats THEN statGrand[which] ← statGrand[which] + 1};

  StatBump: PUBLIC PROCEDURE [which: Stats.StatCounterIndex, howmuch: CARDINAL] =
    {IF CommFlags.doStats THEN statGrand[which] ← statGrand[which] + howmuch};

  StatGetCounter: PUBLIC PROCEDURE [which: Stats.StatCounterIndex]
    RETURNS [LONG CARDINAL] =
    {RETURN[IF CommFlags.doStats THEN statGrand[which] ELSE 0]};

  Start: PUBLIC  <<StatsOps>> PROC[] =
    {IF CommFlags.doStats THEN statGrand ← CommHeap.zone.NEW[StatGrand ← ALL[0]]};

  Stop: PUBLIC <<StatsOps>> PROC[] =
    {IF CommFlags.doStats THEN CommHeap.zone.FREE[@statGrand]};

  END.