From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX"  9-JUN-1992 21:58:48.83
To:	INFO-VAX@KL.SRI.COM
CC:	
Subj:	re: Time manipulation in DCL

	I'm looking for some simple time manipulation routines in DCL.
	Basically I want to emulate the LIB$INIT_TIMER/LIB$SHOW_TIMER RTL
	calls in DCL.  I want to grab the current time, do a bunch of stuff,
	grab the new time and calculate the elapsed time in seconds.  It looks
	like F$GETJPI will give you the LOGINTIME but not the elapsed time (in
	seconds or hundredths of seconds).  Has anyone done the conversions to
	produce a printable delta time?  Am I going to have to do the
	multiplications myself?

I use the following little command file to time how long various things take.
It also provides you with other relevent statistics.  Use as @TIME <command>;
for example, @TIME RUN FOO.

I've included two different versions of the code.  TIME.COM is the "execut-
able", if harder to read, version.  TIME.RCL is the "source code" that is
converted to TIME.COM by a DCL preprocessor called RCL that I wrote years ago.
Actually, these days TIME.RCL could trivially be re-written to just used
block IF-THEN-ELSE's; but I don't want to start debugging the result right
now.

							-- Jerry

-------------------TIME.COM-------------------
$on error then continue
$assign/user SYS$COMMAND SYS$INPUT
$start_dirio = f$getjpi("","DIRIO")
$start_bufio = f$getjpi("","BUFIO")
$start_faults = f$getjpi("","PAGEFLTS")
$start_dt = f$time()
$start_cpu = f$getjpi("","CPUTIM")
$start_virtpeak = f$getjpi("","VIRTPEAK")
$start_wspeak = f$getjpi("","WSPEAK")
$'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8'
$end_cpu = f$getjpi("","CPUTIM")
$end_dt = f$time()
$end_dirio = f$getjpi("","DIRIO")
$end_bufio = f$getjpi("","BUFIO")
$end_faults = f$getjpi("","PAGEFLTS")
$end_virtpeak = f$getjpi("","VIRTPEAK")
$end_wspeak = f$getjpi("","WSPEAK")
$deas/user/all
$cpu = f$integer(end_cpu) - f$integer(start_cpu)
$cpu_s = cpu/100
$cpu_hu = cpu - 100*cpu_s
$if cpu_hu .lt. 10 then cpu_hu = "0" + f$string(cpu_hu)
$el_h = f$integer(f$cvtime(end_dt,"ABSOLUTE","HOUR")) - f$integer(f$cvtime(start_dt,"ABSOLUTE","HOUR"))
$el_m = f$integer(f$cvtime(end_dt,"ABSOLUTE","MINUTE")) - f$integer(f$cvtime(start_dt,"ABSOLUTE","MINUTE"))
$el_s = f$integer(f$cvtime(end_dt,"ABSOLUTE","SECOND")) - f$integer(f$cvtime(start_dt,"ABSOLUTE","SECOND"))
$el_hu = f$integer(f$cvtime(end_dt,"ABSOLUTE","HUNDREDTH")) - f$integer(f$cvtime(start_dt,"ABSOLUTE","HUNDREDTH"))
$if .NOT.(el_hu .lt. 0)THEN GOTO G_$_F1
$el_s = el_s - 1
$el_hu = el_hu + 100
$G_$_F1:
$if .NOT.(el_s .lt. 0)THEN GOTO G_$_F2
$el_m = el_m - 1
$el_s = el_s + 60
$G_$_F2:
$if .NOT.(el_m .lt. 0)THEN GOTO G_$_F3
$el_h = el_h - 1
$el_m = el_m + 60
$G_$_F3:
$if .NOT.(el_h .lt. 0)THEN GOTO G_$_F4
$write SYS$OUTPUT "Elapsed time crossed midnight:  " start_dt," - ",end_dt
$el_h = 0
$G_$_F4:
$dirio = f$integer(end_dirio) - f$integer(start_dirio)
$bufio = f$integer(end_bufio) - f$integer(start_bufio)
$faults = f$integer(end_faults) - f$integer(start_faults)
$el = "''el_h':''el_m':''el_s'.''el_hu'"
$cp = f$string(cpu_s) + "." + f$string(cpu_hu)
$if .NOT.(start_virtpeak .lt. end_virtpeak)THEN GOTO G_$_F5
$virtpeak = end_virtpeak
$GOTO G_$_T5
$G_$_F5:
$virtpeak = "could not be determined"
$G_$_T5:
$if .NOT.(start_wspeak .lt. end_wspeak)THEN GOTO G_$_F6
$wspeak = end_wspeak
$GOTO G_$_T6
$G_$_F6:
$wspeak = "could not be determined"
$G_$_T6:
$write SYS$OUTPUT "Elapsed ",f$cvtime(el,"ABSOLUTE","TIME"),", CPU ",cp
$write SYS$OUTPUT "Incremental DIRIO ''dirio', BUFIO ''bufio', Faults ''faults'"
$write SYS$OUTPUT "Peak virtual size ",virtpeak,", working set ",wspeak
-------------------TIME.RCL-------------------
$ on error then continue
$ assign/user SYS$COMMAND SYS$INPUT
$ start_dirio = f$getjpi("","DIRIO")
$ start_bufio = f$getjpi("","BUFIO")
$ start_faults = f$getjpi("","PAGEFLTS")
$ start_dt = f$time()
$ start_cpu = f$getjpi("","CPUTIM")
$ start_virtpeak = f$getjpi("","VIRTPEAK")
$ start_wspeak = f$getjpi("","WSPEAK")
$'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8'
$ end_cpu = f$getjpi("","CPUTIM")
$ end_dt = f$time()
$ end_dirio = f$getjpi("","DIRIO")
$ end_bufio = f$getjpi("","BUFIO")
$ end_faults = f$getjpi("","PAGEFLTS")
$ end_virtpeak = f$getjpi("","VIRTPEAK")
$ end_wspeak = f$getjpi("","WSPEAK")
$ deas/user/all
$ cpu = f$integer(end_cpu) - f$integer(start_cpu)
$ cpu_s = cpu/100
$ cpu_hu = cpu - 100*cpu_s
$ if cpu_hu .lt. 10 then cpu_hu = "0" + f$string(cpu_hu)
$ el_h = f$integer(f$cvtime(end_dt,"ABSOLUTE","HOUR"))			-
		- f$integer(f$cvtime(start_dt,"ABSOLUTE","HOUR"))
$ el_m = f$integer(f$cvtime(end_dt,"ABSOLUTE","MINUTE"))		-
		- f$integer(f$cvtime(start_dt,"ABSOLUTE","MINUTE"))
$ el_s = f$integer(f$cvtime(end_dt,"ABSOLUTE","SECOND"))		-
		- f$integer(f$cvtime(start_dt,"ABSOLUTE","SECOND"))
$ el_hu = f$integer(f$cvtime(end_dt,"ABSOLUTE","HUNDREDTH"))	-
		- f$integer(f$cvtime(start_dt,"ABSOLUTE","HUNDREDTH"))
$ if el_hu .lt. 0							-
{	$ el_s = el_s - 1
	$ el_hu = el_hu + 100
}
$ if el_s .lt. 0							-
{	$ el_m = el_m - 1
	$ el_s = el_s + 60
}
$ if el_m .lt. 0							-
{	$ el_h = el_h - 1
	$ el_m = el_m + 60
}
$ if el_h .lt. 0							-
{	$ write SYS$OUTPUT "Elapsed time crossed midnight:  "		-
		start_dt," - ",end_dt
	$ el_h = 0
}
$ dirio = f$integer(end_dirio) - f$integer(start_dirio)
$ bufio = f$integer(end_bufio) - f$integer(start_bufio)
$ faults = f$integer(end_faults) - f$integer(start_faults)
$ el = "''el_h':''el_m':''el_s'.''el_hu'"
$ cp = f$string(cpu_s) + "." + f$string(cpu_hu)
$ if start_virtpeak .lt. end_virtpeak					-
{	$ virtpeak = end_virtpeak	}
else
{	$ virtpeak = "could not be determined"	}
$ if start_wspeak .lt. end_wspeak					-
{	$ wspeak = end_wspeak			}
else
{	$ wspeak = "could not be determined"	}
$ write SYS$OUTPUT "Elapsed ",f$cvtime(el,"ABSOLUTE","TIME"),", CPU ",cp
$ write SYS$OUTPUT							-
	"Incremental DIRIO ''dirio', BUFIO ''bufio', Faults ''faults'"
$ write SYS$OUTPUT							-
	"Peak virtual size ",virtpeak,", working set ",wspeak

