aboutsummaryrefslogtreecommitdiff
path: root/sys/etc/sysptime.x
blob: 3a2657c27113ef23f5e083e0a4168185936e780a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<ctype.h>

define	SZ_OBUF		8
define	CPU		1
define	CLK		2


# SYS_MTIME -- Mark the time, i.e., save the current clock and cpu times in
# the save buffer.

procedure sys_mtime (save_time)

long	save_time[2]			# mark time buffer

begin
	call zgtime (save_time[CLK], save_time[CPU])
end


# SYS_PTIME -- Print the cpu and clock time consumed since the last call to
# SYS_MTIME.

procedure sys_ptime (fd, opstr, save_time)

int	fd				# output file
char	opstr[ARB]			# optional operand name string
long	save_time[2]			# mark time buffer

int	op, junk
char	obuf[SZ_OBUF]
long	new_clk, new_cpu
int	d_clk, d_cpu, msec, sec, percent
int	itoc()

begin
	call zgtime (new_clk, new_cpu)
	d_clk = (new_clk - save_time[CLK]) 	# clk seconds
	d_cpu = (new_cpu - save_time[CPU])	# cpu msec

	call putline (fd, "Time ")
	if (opstr[1] != EOS) {
	    call putci (fd, '(')
	    call putline (fd, opstr)
	    call putline (fd, ") ")
	}

	# Output the cpu time in seconds.
	op = itoc (d_cpu / 1000, obuf, SZ_OBUF) + 1
	obuf[op] = '.'; op = op + 1
	msec = mod (d_cpu, 1000)
	if (msec < 100) {
	    obuf[op] = '0'; op = op + 1
	}
	if (msec < 10) {
	    obuf[op] = '0'; op = op + 1
	}
	if (msec > 0)
	    op = op + itoc (msec, obuf[op], SZ_OBUF-op+1)
	call putline (fd, obuf)

	# Output the clock time in minutes and seconds.
	call putci (fd, ' ')
	op = itoc (d_clk / 60, obuf, SZ_OBUF) + 1
	obuf[op] = ':'; op = op + 1
	sec = mod (d_clk, 60)
	obuf[op] = TO_DIGIT(sec/10); op = op + 1
	obuf[op] = TO_DIGIT(mod(sec,10)); op = op + 1
	obuf[op] = EOS
	call putline (fd, obuf)

	# Output the percent cpu utilization.
	call putci (fd, ' ')
	if (d_clk < 1)
	    call strcpy ("99", obuf, SZ_OBUF)
	else {
	    percent = min (99, d_cpu / d_clk / 10)
	    junk = itoc (percent, obuf, SZ_OBUF)
	}

	call putline (fd, obuf)
	call putline (fd, "%\n")
end