{$M-,X+}
program msure;

{ Measurement subroutines for JEEVES }

include {NOLIST} 'domain:jsys.def';
include {NOLIST} 'domain:mdep.def';
include {NOLIST} 'domain:master.def';
include {NOLIST} 'domain:eutil.hdr';
include {NOLIST} 'domain:msub.hdr';

var	sticky:integer;

procedure ruse(var data:fruse; (* cumulative data *)
	       var base:fruse);	(* base data for start of this session *)

{ This routine is used to keep cumulative resource information for a fork }

var ac1,ac2,ac3:integer;

begin
jsys(gtrpi;fhslf;ac1,ac2,ac3); (* record pager information *)
data.elpgt:=base.elpgt+ac1; (* page traps *)
data.elpgf:=base.elpgf+ac2; (* page faults *)
data.elpgrt:=base.elpgrt+ac3; (* time spent in pager routines *)

jsys(runtm;fhslf;ac1,ac2,ac3);
data.elrun:=base.elrun+ac1;

data.elwall:=base.elwall+ac3-data.elwb;
end; { ruse }
function hlook(     thost:integer;
		 var  myhgraph:hgraph):hgraph_index;

{ The purpose of this function is to find the hgraph entry for
the specified host, or a open entry, or default to the last
table entry if all else fails }

var done:boolean;
    search:hgraph_index;

begin
search:=1;
done:=false;
if (sticky>0) and (sticky<=hslots)
then if myhgraph[sticky].host=thost
     then begin done:=true; search:=sticky; end;
while not done
do with myhgraph[search]
   do if host=thost
      then done:=true
      else if host=0
	   then begin
		    done:=true;
		    host:=thost;
		    touts:=0;
		    tbacks:=0;
		    ttotal:=0
		end
	   else	begin
		    if search=hslots
		    then begin
			     done:=true;
			     host:=thost
			 end
		    else search:=search+1
		end;
hlook:=search;
sticky:=search;
end; { HLOOK }
procedure hhisto(var myhgraph:hgraph;
		     tvalue:integer;
		     thost:integer);
begin
with myhgraph[hlook(thost,myhgraph)]
do begin
       tbacks:=tbacks+1;
       ttotal:=ttotal+tvalue
   end
end; { HHISTO }
procedure thisto(var mytgraph:tgraph;
		     tvalue:integer);

var	    i:integer;
begin
with mytgraph
do begin
       tbacks:=tbacks+1;
       ttotal:=ttotal+tvalue;
       if tquanta<>0
       then begin
		i:=min(tvalue div tquanta,tslots);
		tdelay[i]:=tdelay[i]+1
	    end;
   end;

end. { THISTO }
