?? RIGHT := 110 ??
MODULE mmm$log_caller_r1;

{ This module should be compiled to OSF$SYSTEM_CORE_113 and, if necessary, OSF$BOOT_JOB.

*copyc mmv$benchmark_run

{ The following TYPE is a version of the minimum save area.  It defines only the fields which will be
{ useful in the procedure MMP$LOG_CALLER_R1.

*copyc oss$mainframe_wired

  TYPE
    sfsa_type = RECORD
      fill1: 0 .. 0ffff(16),
      p: ^cell,
      a0: integer,
      a1: integer,
      fill2: 0 .. 0ffff(16),
      a2: ^sfsa_type,
    RECEND;

  TYPE
    proc_id_type = RECORD
      fill0: 0..0ffff(16),
      p0: ^cell,
      fill1: 0..0ffff(16),
      p1: ^cell,
      fill2: 0..0ffff(16),
      p2: ^cell,
      fill3: 0..0ffff(16),
      p3: ^cell,
    RECEND,

    proc_info_type = RECORD
      id: proc_id_type,
      count: integer,
    RECEND;

  CONST
    pid_size = 300;


  VAR
    count: integer,
    start_time: integer,
    last_time: integer,
    mmv$log_enable_r1: [XREF] integer,
    max_pid_r1: [XREF] integer,
    pid_r1: [XREF] array [0 .. pid_size] of proc_info_type;

?? EJECT ??

  PROCEDURE [XDCL, #GATE] mmp$log_caller_r1;

    VAR
      offset,
      i: integer,
      id: proc_id_type,
      sfsa_p: ^sfsa_type,
      null_id: [STATIC] proc_id_type := [0, NIL, 0, NIL, 0, NIL, 0, NIL];


{ If we are not specifically collecting this data at this time, return without processing.

    IF mmv$benchmark_run = 0 THEN
      RETURN;
    ELSEIF mmv$log_enable_r1 <= 1 THEN

{ Initialize the data array.

      count := 0;
      start_time := #free_running_clock (0);
      mmv$log_enable_r1 := 2;
      FOR i := 0 TO pid_size DO
        pid_r1 [i].id := null_id;
        pid_r1 [i].count := 0;
      FOREND;
      max_pid_r1 := 0;
    IFEND;

    count := count + 1;
    last_time := #free_running_clock (0);
    sfsa_p := #previous_save_area ();
    id := null_id;
    i := 0;
    WHILE (sfsa_p <> NIL) AND (i < 4) DO
      CASE i OF
       = 0 =
         id.p0:=sfsa_p^.p;
       = 1 =
         id.p1:=sfsa_p^.p;
       = 2 =
         id.p2:=sfsa_p^.p;
       = 3 =
         id.p3:=sfsa_p^.p;
      CASEND;
      sfsa_p := sfsa_p^.a2;
      i := i + 1;
    WHILEND;

    i := 0;
    WHILE pid_r1 [i].id  <> id DO
      IF i = max_pid_r1 THEN
        IF i = pid_size THEN
          RETURN;
        IFEND;
        pid_r1 [i].id := id;
        max_pid_r1 := i + 1;
      ELSE
        i := i + 1;
      IFEND;
    WHILEND;

    pid_r1 [i].count := pid_r1 [i].count + 1;

  PROCEND mmp$log_caller_r1;
MODEND mmm$log_caller_r1;
