xref: /freebsd/usr.sbin/sa/pdb.c (revision 4d65a7c6951cea0333f1a0c1b32c38489cdfa6c5)
1*1de7b4b8SPedro F. Giffuni /*-
2*1de7b4b8SPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3*1de7b4b8SPedro F. Giffuni  *
4b1069b52SDavid Greenman  * Copyright (c) 1994 Christopher G. Demetriou
5b1069b52SDavid Greenman  * All rights reserved.
6b1069b52SDavid Greenman  *
7b1069b52SDavid Greenman  * Redistribution and use in source and binary forms, with or without
8b1069b52SDavid Greenman  * modification, are permitted provided that the following conditions
9b1069b52SDavid Greenman  * are met:
10b1069b52SDavid Greenman  * 1. Redistributions of source code must retain the above copyright
11b1069b52SDavid Greenman  *    notice, this list of conditions and the following disclaimer.
12b1069b52SDavid Greenman  * 2. Redistributions in binary form must reproduce the above copyright
13b1069b52SDavid Greenman  *    notice, this list of conditions and the following disclaimer in the
14b1069b52SDavid Greenman  *    documentation and/or other materials provided with the distribution.
15b1069b52SDavid Greenman  * 3. All advertising materials mentioning features or use of this software
16b1069b52SDavid Greenman  *    must display the following acknowledgement:
17b1069b52SDavid Greenman  *      This product includes software developed by Christopher G. Demetriou.
18b1069b52SDavid Greenman  * 4. The name of the author may not be used to endorse or promote products
19b1069b52SDavid Greenman  *    derived from this software without specific prior written permission
20b1069b52SDavid Greenman  *
21b1069b52SDavid Greenman  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22b1069b52SDavid Greenman  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23b1069b52SDavid Greenman  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24b1069b52SDavid Greenman  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25b1069b52SDavid Greenman  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26b1069b52SDavid Greenman  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27b1069b52SDavid Greenman  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28b1069b52SDavid Greenman  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29b1069b52SDavid Greenman  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30b1069b52SDavid Greenman  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31b1069b52SDavid Greenman  */
32b1069b52SDavid Greenman 
33b1069b52SDavid Greenman #include <sys/types.h>
34b1069b52SDavid Greenman #include <sys/acct.h>
35b1069b52SDavid Greenman #include <err.h>
36b1069b52SDavid Greenman #include <errno.h>
37b1069b52SDavid Greenman #include <fcntl.h>
38fdbe5babSDiomidis Spinellis #include <stdbool.h>
3972d78aeaSDag-Erling Smørgrav #include <stdint.h>
40b1069b52SDavid Greenman #include <stdio.h>
41553072f3SMike Pritchard #include <string.h>
42b1069b52SDavid Greenman #include "extern.h"
43b1069b52SDavid Greenman #include "pathnames.h"
44b1069b52SDavid Greenman 
4569315c6fSXin LI static int check_junk(const struct cmdinfo *);
4669315c6fSXin LI static void add_ci(const struct cmdinfo *, struct cmdinfo *);
4769315c6fSXin LI static void print_ci(const struct cmdinfo *, const struct cmdinfo *);
48b1069b52SDavid Greenman 
49b1069b52SDavid Greenman static DB	*pacct_db;
50b1069b52SDavid Greenman 
51fdbe5babSDiomidis Spinellis /* Legacy format in AHZV1 units. */
52fdbe5babSDiomidis Spinellis struct cmdinfov1 {
53fdbe5babSDiomidis Spinellis 	char		ci_comm[MAXCOMLEN+2];	/* command name (+ '*') */
54fdbe5babSDiomidis Spinellis 	uid_t		ci_uid;			/* user id */
55fdbe5babSDiomidis Spinellis 	u_quad_t	ci_calls;		/* number of calls */
56fdbe5babSDiomidis Spinellis 	u_quad_t	ci_etime;		/* elapsed time */
57fdbe5babSDiomidis Spinellis 	u_quad_t	ci_utime;		/* user time */
58fdbe5babSDiomidis Spinellis 	u_quad_t	ci_stime;		/* system time */
59fdbe5babSDiomidis Spinellis 	u_quad_t	ci_mem;			/* memory use */
60fdbe5babSDiomidis Spinellis 	u_quad_t	ci_io;			/* number of disk i/o ops */
61fdbe5babSDiomidis Spinellis 	u_int		ci_flags;		/* flags; see below */
62fdbe5babSDiomidis Spinellis };
63fdbe5babSDiomidis Spinellis 
64fdbe5babSDiomidis Spinellis /*
65fdbe5babSDiomidis Spinellis  * Convert a v1 data record into the current version.
66fdbe5babSDiomidis Spinellis  * Return 0 if OK, -1 on error, setting errno.
67fdbe5babSDiomidis Spinellis  */
68fdbe5babSDiomidis Spinellis static int
v1_to_v2(DBT * key __unused,DBT * data)69fdbe5babSDiomidis Spinellis v1_to_v2(DBT *key __unused, DBT *data)
70fdbe5babSDiomidis Spinellis {
71fdbe5babSDiomidis Spinellis 	struct cmdinfov1 civ1;
72fdbe5babSDiomidis Spinellis 	static struct cmdinfo civ2;
73fdbe5babSDiomidis Spinellis 
74fdbe5babSDiomidis Spinellis 	if (data->size != sizeof(civ1)) {
75fdbe5babSDiomidis Spinellis 		errno = EFTYPE;
76fdbe5babSDiomidis Spinellis 		return (-1);
77fdbe5babSDiomidis Spinellis 	}
78fdbe5babSDiomidis Spinellis 	memcpy(&civ1, data->data, data->size);
79fdbe5babSDiomidis Spinellis 	memset(&civ2, 0, sizeof(civ2));
80fdbe5babSDiomidis Spinellis 	memcpy(civ2.ci_comm, civ1.ci_comm, sizeof(civ2.ci_comm));
81fdbe5babSDiomidis Spinellis 	civ2.ci_uid = civ1.ci_uid;
82fdbe5babSDiomidis Spinellis 	civ2.ci_calls = civ1.ci_calls;
83fdbe5babSDiomidis Spinellis 	civ2.ci_etime = ((double)civ1.ci_etime / AHZV1) * 1000000;
84fdbe5babSDiomidis Spinellis 	civ2.ci_utime = ((double)civ1.ci_utime / AHZV1) * 1000000;
85fdbe5babSDiomidis Spinellis 	civ2.ci_stime = ((double)civ1.ci_stime / AHZV1) * 1000000;
86fdbe5babSDiomidis Spinellis 	civ2.ci_mem = civ1.ci_mem;
87fdbe5babSDiomidis Spinellis 	civ2.ci_io = civ1.ci_io;
88fdbe5babSDiomidis Spinellis 	civ2.ci_flags = civ1.ci_flags;
89fdbe5babSDiomidis Spinellis 	data->size = sizeof(civ2);
90fdbe5babSDiomidis Spinellis 	data->data = &civ2;
91fdbe5babSDiomidis Spinellis 	return (0);
92fdbe5babSDiomidis Spinellis }
93fdbe5babSDiomidis Spinellis 
94fdbe5babSDiomidis Spinellis /* Copy pdb_file to in-memory pacct_db. */
95b1069b52SDavid Greenman int
pacct_init(void)9610bc3a7fSEd Schouten pacct_init(void)
97b1069b52SDavid Greenman {
98fdbe5babSDiomidis Spinellis 	return (db_copy_in(&pacct_db, pdb_file, "process accounting",
99fdbe5babSDiomidis Spinellis 	    NULL, v1_to_v2));
100b1069b52SDavid Greenman }
101b1069b52SDavid Greenman 
102b1069b52SDavid Greenman void
pacct_destroy(void)10310bc3a7fSEd Schouten pacct_destroy(void)
104b1069b52SDavid Greenman {
105fdbe5babSDiomidis Spinellis 	db_destroy(pacct_db, "process accounting");
106b1069b52SDavid Greenman }
107b1069b52SDavid Greenman 
108b1069b52SDavid Greenman int
pacct_add(const struct cmdinfo * ci)10969315c6fSXin LI pacct_add(const struct cmdinfo *ci)
110b1069b52SDavid Greenman {
111b1069b52SDavid Greenman 	DBT key, data;
112b1069b52SDavid Greenman 	struct cmdinfo newci;
113b1069b52SDavid Greenman 	char keydata[sizeof ci->ci_comm];
114b1069b52SDavid Greenman 	int rv;
115b1069b52SDavid Greenman 
116b1069b52SDavid Greenman 	bcopy(ci->ci_comm, &keydata, sizeof keydata);
117b1069b52SDavid Greenman 	key.data = &keydata;
118b1069b52SDavid Greenman 	key.size = strlen(keydata);
119b1069b52SDavid Greenman 
120b1069b52SDavid Greenman 	rv = DB_GET(pacct_db, &key, &data, 0);
121b1069b52SDavid Greenman 	if (rv < 0) {
122b1069b52SDavid Greenman 		warn("get key %s from process accounting stats", ci->ci_comm);
123b1069b52SDavid Greenman 		return (-1);
124b1069b52SDavid Greenman 	} else if (rv == 0) {	/* it's there; copy whole thing */
125b1069b52SDavid Greenman 		/* XXX compare size if paranoid */
126b1069b52SDavid Greenman 		/* add the old data to the new data */
127b1069b52SDavid Greenman 		bcopy(data.data, &newci, data.size);
128b1069b52SDavid Greenman 	} else {		/* it's not there; zero it and copy the key */
129b1069b52SDavid Greenman 		bzero(&newci, sizeof newci);
130b1069b52SDavid Greenman 		bcopy(key.data, newci.ci_comm, key.size);
131b1069b52SDavid Greenman 	}
132b1069b52SDavid Greenman 
133b1069b52SDavid Greenman 	add_ci(ci, &newci);
134b1069b52SDavid Greenman 
135b1069b52SDavid Greenman 	data.data = &newci;
136b1069b52SDavid Greenman 	data.size = sizeof newci;
137b1069b52SDavid Greenman 	rv = DB_PUT(pacct_db, &key, &data, 0);
138b1069b52SDavid Greenman 	if (rv < 0) {
139b1069b52SDavid Greenman 		warn("add key %s to process accounting stats", ci->ci_comm);
140b1069b52SDavid Greenman 		return (-1);
141b1069b52SDavid Greenman 	} else if (rv == 1) {
142b1069b52SDavid Greenman 		warnx("duplicate key %s in process accounting stats",
143b1069b52SDavid Greenman 		    ci->ci_comm);
144b1069b52SDavid Greenman 		return (-1);
145b1069b52SDavid Greenman 	}
146b1069b52SDavid Greenman 
147b1069b52SDavid Greenman 	return (0);
148b1069b52SDavid Greenman }
149b1069b52SDavid Greenman 
150fdbe5babSDiomidis Spinellis /* Copy in-memory pacct_db to pdb_file. */
151b1069b52SDavid Greenman int
pacct_update(void)15210bc3a7fSEd Schouten pacct_update(void)
153b1069b52SDavid Greenman {
154fdbe5babSDiomidis Spinellis 	return (db_copy_out(pacct_db, pdb_file, "process accounting",
155fdbe5babSDiomidis Spinellis 	    NULL));
156b1069b52SDavid Greenman }
157b1069b52SDavid Greenman 
158b1069b52SDavid Greenman void
pacct_print(void)15910bc3a7fSEd Schouten pacct_print(void)
160b1069b52SDavid Greenman {
161b1069b52SDavid Greenman 	BTREEINFO bti;
162b1069b52SDavid Greenman 	DBT key, data, ndata;
163b1069b52SDavid Greenman 	DB *output_pacct_db;
164b1069b52SDavid Greenman 	struct cmdinfo *cip, ci, ci_total, ci_other, ci_junk;
165b1069b52SDavid Greenman 	int rv;
166b1069b52SDavid Greenman 
167b1069b52SDavid Greenman 	bzero(&ci_total, sizeof ci_total);
168b1069b52SDavid Greenman 	strcpy(ci_total.ci_comm, "");
169b1069b52SDavid Greenman 	bzero(&ci_other, sizeof ci_other);
170b1069b52SDavid Greenman 	strcpy(ci_other.ci_comm, "***other");
171b1069b52SDavid Greenman 	bzero(&ci_junk, sizeof ci_junk);
172b1069b52SDavid Greenman 	strcpy(ci_junk.ci_comm, "**junk**");
173b1069b52SDavid Greenman 
174b1069b52SDavid Greenman 	/*
175b1069b52SDavid Greenman 	 * Retrieve them into new DB, sorted by appropriate key.
176b1069b52SDavid Greenman 	 * At the same time, cull 'other' and 'junk'
177b1069b52SDavid Greenman 	 */
178b1069b52SDavid Greenman 	bzero(&bti, sizeof bti);
179b1069b52SDavid Greenman 	bti.compare = sa_cmp;
180b1069b52SDavid Greenman 	output_pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti);
181b1069b52SDavid Greenman 	if (output_pacct_db == NULL) {
182b1069b52SDavid Greenman 		warn("couldn't sort process accounting stats");
183b1069b52SDavid Greenman 		return;
184b1069b52SDavid Greenman 	}
185b1069b52SDavid Greenman 
186b1069b52SDavid Greenman 	ndata.data = NULL;
187b1069b52SDavid Greenman 	ndata.size = 0;
188b1069b52SDavid Greenman 	rv = DB_SEQ(pacct_db, &key, &data, R_FIRST);
189b1069b52SDavid Greenman 	if (rv < 0)
190b1069b52SDavid Greenman 		warn("retrieving process accounting stats");
191b1069b52SDavid Greenman 	while (rv == 0) {
192b1069b52SDavid Greenman 		cip = (struct cmdinfo *) data.data;
193b1069b52SDavid Greenman 		bcopy(cip, &ci, sizeof ci);
194b1069b52SDavid Greenman 
195b1069b52SDavid Greenman 		/* add to total */
196b1069b52SDavid Greenman 		add_ci(&ci, &ci_total);
197b1069b52SDavid Greenman 
198b1069b52SDavid Greenman 		if (vflag && ci.ci_calls <= cutoff &&
199b1069b52SDavid Greenman 		    (fflag || check_junk(&ci))) {
200b1069b52SDavid Greenman 			/* put it into **junk** */
201b1069b52SDavid Greenman 			add_ci(&ci, &ci_junk);
202b1069b52SDavid Greenman 			goto next;
203b1069b52SDavid Greenman 		}
204b1069b52SDavid Greenman 		if (!aflag &&
205b1069b52SDavid Greenman 		    ((ci.ci_flags & CI_UNPRINTABLE) != 0 || ci.ci_calls <= 1)) {
206b1069b52SDavid Greenman 			/* put into ***other */
207b1069b52SDavid Greenman 			add_ci(&ci, &ci_other);
208b1069b52SDavid Greenman 			goto next;
209b1069b52SDavid Greenman 		}
210b1069b52SDavid Greenman 		rv = DB_PUT(output_pacct_db, &data, &ndata, 0);
211b1069b52SDavid Greenman 		if (rv < 0)
212b1069b52SDavid Greenman 			warn("sorting process accounting stats");
213b1069b52SDavid Greenman 
214b1069b52SDavid Greenman next:		rv = DB_SEQ(pacct_db, &key, &data, R_NEXT);
215b1069b52SDavid Greenman 		if (rv < 0)
216b1069b52SDavid Greenman 			warn("retrieving process accounting stats");
217b1069b52SDavid Greenman 	}
218b1069b52SDavid Greenman 
219b1069b52SDavid Greenman 	/* insert **junk** and ***other */
220b1069b52SDavid Greenman 	if (ci_junk.ci_calls != 0) {
221b1069b52SDavid Greenman 		data.data = &ci_junk;
222b1069b52SDavid Greenman 		data.size = sizeof ci_junk;
223b1069b52SDavid Greenman 		rv = DB_PUT(output_pacct_db, &data, &ndata, 0);
224b1069b52SDavid Greenman 		if (rv < 0)
225b1069b52SDavid Greenman 			warn("sorting process accounting stats");
226b1069b52SDavid Greenman 	}
227b1069b52SDavid Greenman 	if (ci_other.ci_calls != 0) {
228b1069b52SDavid Greenman 		data.data = &ci_other;
229b1069b52SDavid Greenman 		data.size = sizeof ci_other;
230b1069b52SDavid Greenman 		rv = DB_PUT(output_pacct_db, &data, &ndata, 0);
231b1069b52SDavid Greenman 		if (rv < 0)
232b1069b52SDavid Greenman 			warn("sorting process accounting stats");
233b1069b52SDavid Greenman 	}
234b1069b52SDavid Greenman 
235b1069b52SDavid Greenman 	/* print out the total */
236b1069b52SDavid Greenman 	print_ci(&ci_total, &ci_total);
237b1069b52SDavid Greenman 
238b1069b52SDavid Greenman 	/* print out; if reversed, print first (smallest) first */
239b1069b52SDavid Greenman 	rv = DB_SEQ(output_pacct_db, &data, &ndata, rflag ? R_FIRST : R_LAST);
240b1069b52SDavid Greenman 	if (rv < 0)
241b1069b52SDavid Greenman 		warn("retrieving process accounting report");
242b1069b52SDavid Greenman 	while (rv == 0) {
243b1069b52SDavid Greenman 		cip = (struct cmdinfo *) data.data;
244b1069b52SDavid Greenman 		bcopy(cip, &ci, sizeof ci);
245b1069b52SDavid Greenman 
246b1069b52SDavid Greenman 		print_ci(&ci, &ci_total);
247b1069b52SDavid Greenman 
248b1069b52SDavid Greenman 		rv = DB_SEQ(output_pacct_db, &data, &ndata,
249b1069b52SDavid Greenman 		    rflag ? R_NEXT : R_PREV);
250b1069b52SDavid Greenman 		if (rv < 0)
251b1069b52SDavid Greenman 			warn("retrieving process accounting report");
252b1069b52SDavid Greenman 	}
253b1069b52SDavid Greenman 	DB_CLOSE(output_pacct_db);
254b1069b52SDavid Greenman }
255b1069b52SDavid Greenman 
256b1069b52SDavid Greenman static int
check_junk(const struct cmdinfo * cip)25769315c6fSXin LI check_junk(const struct cmdinfo *cip)
258b1069b52SDavid Greenman {
259b1069b52SDavid Greenman 	char *cp;
260b1069b52SDavid Greenman 	size_t len;
261b1069b52SDavid Greenman 
26272d78aeaSDag-Erling Smørgrav 	fprintf(stderr, "%s (%ju) -- ", cip->ci_comm, (uintmax_t)cip->ci_calls);
263b1069b52SDavid Greenman 	cp = fgetln(stdin, &len);
264b1069b52SDavid Greenman 
265b1069b52SDavid Greenman 	return (cp && (cp[0] == 'y' || cp[0] == 'Y')) ? 1 : 0;
266b1069b52SDavid Greenman }
267b1069b52SDavid Greenman 
268b1069b52SDavid Greenman static void
add_ci(const struct cmdinfo * fromcip,struct cmdinfo * tocip)26969315c6fSXin LI add_ci(const struct cmdinfo *fromcip, struct cmdinfo *tocip)
270b1069b52SDavid Greenman {
271b1069b52SDavid Greenman 	tocip->ci_calls += fromcip->ci_calls;
272b1069b52SDavid Greenman 	tocip->ci_etime += fromcip->ci_etime;
273b1069b52SDavid Greenman 	tocip->ci_utime += fromcip->ci_utime;
274b1069b52SDavid Greenman 	tocip->ci_stime += fromcip->ci_stime;
275b1069b52SDavid Greenman 	tocip->ci_mem += fromcip->ci_mem;
276b1069b52SDavid Greenman 	tocip->ci_io += fromcip->ci_io;
277b1069b52SDavid Greenman }
278b1069b52SDavid Greenman 
279b1069b52SDavid Greenman static void
print_ci(const struct cmdinfo * cip,const struct cmdinfo * totalcip)28069315c6fSXin LI print_ci(const struct cmdinfo *cip, const struct cmdinfo *totalcip)
281b1069b52SDavid Greenman {
282b1069b52SDavid Greenman 	double t, c;
283b1069b52SDavid Greenman 	int uflow;
284b1069b52SDavid Greenman 
285b1069b52SDavid Greenman 	c = cip->ci_calls ? cip->ci_calls : 1;
286fdbe5babSDiomidis Spinellis 	t = (cip->ci_utime + cip->ci_stime) / 1000000;
287b1069b52SDavid Greenman 	if (t < 0.01) {
288b1069b52SDavid Greenman 		t = 0.01;
289b1069b52SDavid Greenman 		uflow = 1;
290b1069b52SDavid Greenman 	} else
291b1069b52SDavid Greenman 		uflow = 0;
292b1069b52SDavid Greenman 
29372d78aeaSDag-Erling Smørgrav 	printf("%8ju ", (uintmax_t)cip->ci_calls);
294b1069b52SDavid Greenman 	if (cflag) {
295b1069b52SDavid Greenman 		if (cip != totalcip)
296999b7fd4SDiomidis Spinellis 			printf(" %4.1f%%  ", cip->ci_calls /
297999b7fd4SDiomidis Spinellis 			    (double)totalcip->ci_calls * 100);
298b1069b52SDavid Greenman 		else
299b1069b52SDavid Greenman 			printf(" %4s   ", "");
300b1069b52SDavid Greenman 	}
301b1069b52SDavid Greenman 
302b1069b52SDavid Greenman 	if (jflag)
303fdbe5babSDiomidis Spinellis 		printf("%11.3fre ", cip->ci_etime / (1000000 * c));
304b1069b52SDavid Greenman 	else
305fdbe5babSDiomidis Spinellis 		printf("%11.3fre ", cip->ci_etime / (60.0 * 1000000));
306b1069b52SDavid Greenman 	if (cflag) {
307b1069b52SDavid Greenman 		if (cip != totalcip)
308999b7fd4SDiomidis Spinellis 			printf(" %4.1f%%  ", cip->ci_etime /
309fdbe5babSDiomidis Spinellis 			    totalcip->ci_etime * 100);
310b1069b52SDavid Greenman 		else
311b1069b52SDavid Greenman 			printf(" %4s   ", "");
312b1069b52SDavid Greenman 	}
313b1069b52SDavid Greenman 
314b1069b52SDavid Greenman 	if (!lflag) {
315b1069b52SDavid Greenman 		if (jflag)
316fdbe5babSDiomidis Spinellis 			printf("%11.3fcp ", t / (double) cip->ci_calls);
317b1069b52SDavid Greenman 		else
318b1069b52SDavid Greenman 			printf("%11.2fcp ", t / 60.0);
319b1069b52SDavid Greenman 		if (cflag) {
320b1069b52SDavid Greenman 			if (cip != totalcip)
321999b7fd4SDiomidis Spinellis 				printf(" %4.1f%%  ",
322fdbe5babSDiomidis Spinellis 				    (cip->ci_utime + cip->ci_stime) /
323999b7fd4SDiomidis Spinellis 				    (totalcip->ci_utime + totalcip->ci_stime) *
324999b7fd4SDiomidis Spinellis 				    100);
325b1069b52SDavid Greenman 			else
326b1069b52SDavid Greenman 				printf(" %4s   ", "");
327b1069b52SDavid Greenman 		}
328b1069b52SDavid Greenman 	} else {
329b1069b52SDavid Greenman 		if (jflag)
330fdbe5babSDiomidis Spinellis 			printf("%11.3fu ", cip->ci_utime / (1000000 * c));
331b1069b52SDavid Greenman 		else
332fdbe5babSDiomidis Spinellis 			printf("%11.2fu ", cip->ci_utime / (60.0 * 1000000));
333b1069b52SDavid Greenman 		if (cflag) {
334b1069b52SDavid Greenman 			if (cip != totalcip)
335999b7fd4SDiomidis Spinellis 				printf(" %4.1f%%  ", cip->ci_utime /
336999b7fd4SDiomidis Spinellis 				    (double)totalcip->ci_utime * 100);
337b1069b52SDavid Greenman 			else
338b1069b52SDavid Greenman 				printf(" %4s   ", "");
339b1069b52SDavid Greenman 		}
340b1069b52SDavid Greenman 		if (jflag)
341fdbe5babSDiomidis Spinellis 			printf("%11.3fs ", cip->ci_stime / (1000000 * c));
342b1069b52SDavid Greenman 		else
343fdbe5babSDiomidis Spinellis 			printf("%11.2fs ", cip->ci_stime / (60.0 * 1000000));
344b1069b52SDavid Greenman 		if (cflag) {
345b1069b52SDavid Greenman 			if (cip != totalcip)
346999b7fd4SDiomidis Spinellis 				printf(" %4.1f%%  ", cip->ci_stime /
347999b7fd4SDiomidis Spinellis 				    (double)totalcip->ci_stime * 100);
348b1069b52SDavid Greenman 			else
349b1069b52SDavid Greenman 				printf(" %4s   ", "");
350b1069b52SDavid Greenman 		}
351b1069b52SDavid Greenman 	}
352b1069b52SDavid Greenman 
3537fa658d9SAlfred Perlstein 	if (tflag) {
354b1069b52SDavid Greenman 		if (!uflow)
3557fa658d9SAlfred Perlstein 			printf("%8.2fre/cp ",
3567fa658d9SAlfred Perlstein 			    cip->ci_etime /
357fdbe5babSDiomidis Spinellis 			    (cip->ci_utime + cip->ci_stime));
358b1069b52SDavid Greenman 		else
359553072f3SMike Pritchard 			printf("*ignore*      ");
3607fa658d9SAlfred Perlstein 	}
361b1069b52SDavid Greenman 
362b1069b52SDavid Greenman 	if (Dflag)
363fdbe5babSDiomidis Spinellis 		printf("%10.0fio ", cip->ci_io);
364b1069b52SDavid Greenman 	else
365b1069b52SDavid Greenman 		printf("%8.0favio ", cip->ci_io / c);
366b1069b52SDavid Greenman 
367b1069b52SDavid Greenman 	if (Kflag)
368fdbe5babSDiomidis Spinellis 		printf("%10.0fk*sec ", cip->ci_mem);
369b1069b52SDavid Greenman 	else
370b1069b52SDavid Greenman 		printf("%8.0fk ", cip->ci_mem / t);
371b1069b52SDavid Greenman 
372b1069b52SDavid Greenman 	printf("  %s\n", cip->ci_comm);
373b1069b52SDavid Greenman }
374