Deleted Added
full compact
pdb.c (114601) pdb.c (141638)
1/*
2 * Copyright (c) 1994 Christopher G. Demetriou
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1994 Christopher G. Demetriou
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/usr.sbin/sa/pdb.c 114601 2003-05-03 21:06:42Z obrien $");
32__FBSDID("$FreeBSD: head/usr.sbin/sa/pdb.c 141638 2005-02-10 12:43:16Z delphij $");
33
34#include <sys/types.h>
35#include <sys/acct.h>
36#include <err.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <stdint.h>
40#include <stdio.h>
41#include <string.h>
42#include "extern.h"
43#include "pathnames.h"
44
33
34#include <sys/types.h>
35#include <sys/acct.h>
36#include <err.h>
37#include <errno.h>
38#include <fcntl.h>
39#include <stdint.h>
40#include <stdio.h>
41#include <string.h>
42#include "extern.h"
43#include "pathnames.h"
44
45static int check_junk __P((struct cmdinfo *));
46static void add_ci __P((const struct cmdinfo *, struct cmdinfo *));
47static void print_ci __P((const struct cmdinfo *, const struct cmdinfo *));
45static int check_junk(const struct cmdinfo *);
46static void add_ci(const struct cmdinfo *, struct cmdinfo *);
47static void print_ci(const struct cmdinfo *, const struct cmdinfo *);
48
49static DB *pacct_db;
50
51int
52pacct_init()
53{
54 DB *saved_pacct_db;
55 int error;

--- 52 unchanged lines hidden (view full) ---

108void
109pacct_destroy()
110{
111 if (DB_CLOSE(pacct_db) < 0)
112 warn("destroying process accounting stats");
113}
114
115int
48
49static DB *pacct_db;
50
51int
52pacct_init()
53{
54 DB *saved_pacct_db;
55 int error;

--- 52 unchanged lines hidden (view full) ---

108void
109pacct_destroy()
110{
111 if (DB_CLOSE(pacct_db) < 0)
112 warn("destroying process accounting stats");
113}
114
115int
116pacct_add(ci)
117 const struct cmdinfo *ci;
116pacct_add(const struct cmdinfo *ci)
118{
119 DBT key, data;
120 struct cmdinfo newci;
121 char keydata[sizeof ci->ci_comm];
122 int rv;
123
124 bcopy(ci->ci_comm, &keydata, sizeof keydata);
125 key.data = &keydata;

--- 171 unchanged lines hidden (view full) ---

297 rflag ? R_NEXT : R_PREV);
298 if (rv < 0)
299 warn("retrieving process accounting report");
300 }
301 DB_CLOSE(output_pacct_db);
302}
303
304static int
117{
118 DBT key, data;
119 struct cmdinfo newci;
120 char keydata[sizeof ci->ci_comm];
121 int rv;
122
123 bcopy(ci->ci_comm, &keydata, sizeof keydata);
124 key.data = &keydata;

--- 171 unchanged lines hidden (view full) ---

296 rflag ? R_NEXT : R_PREV);
297 if (rv < 0)
298 warn("retrieving process accounting report");
299 }
300 DB_CLOSE(output_pacct_db);
301}
302
303static int
305check_junk(cip)
306 struct cmdinfo *cip;
304check_junk(const struct cmdinfo *cip)
307{
308 char *cp;
309 size_t len;
310
311 fprintf(stderr, "%s (%ju) -- ", cip->ci_comm, (uintmax_t)cip->ci_calls);
312 cp = fgetln(stdin, &len);
313
314 return (cp && (cp[0] == 'y' || cp[0] == 'Y')) ? 1 : 0;
315}
316
317static void
305{
306 char *cp;
307 size_t len;
308
309 fprintf(stderr, "%s (%ju) -- ", cip->ci_comm, (uintmax_t)cip->ci_calls);
310 cp = fgetln(stdin, &len);
311
312 return (cp && (cp[0] == 'y' || cp[0] == 'Y')) ? 1 : 0;
313}
314
315static void
318add_ci(fromcip, tocip)
319 const struct cmdinfo *fromcip;
320 struct cmdinfo *tocip;
316add_ci(const struct cmdinfo *fromcip, struct cmdinfo *tocip)
321{
322 tocip->ci_calls += fromcip->ci_calls;
323 tocip->ci_etime += fromcip->ci_etime;
324 tocip->ci_utime += fromcip->ci_utime;
325 tocip->ci_stime += fromcip->ci_stime;
326 tocip->ci_mem += fromcip->ci_mem;
327 tocip->ci_io += fromcip->ci_io;
328}
329
330static void
317{
318 tocip->ci_calls += fromcip->ci_calls;
319 tocip->ci_etime += fromcip->ci_etime;
320 tocip->ci_utime += fromcip->ci_utime;
321 tocip->ci_stime += fromcip->ci_stime;
322 tocip->ci_mem += fromcip->ci_mem;
323 tocip->ci_io += fromcip->ci_io;
324}
325
326static void
331print_ci(cip, totalcip)
332 const struct cmdinfo *cip, *totalcip;
327print_ci(const struct cmdinfo *cip, const struct cmdinfo *totalcip)
333{
334 double t, c;
335 int uflow;
336
337 c = cip->ci_calls ? cip->ci_calls : 1;
338 t = (cip->ci_utime + cip->ci_stime) / (double) AHZ;
339 if (t < 0.01) {
340 t = 0.01;

--- 82 unchanged lines hidden ---
328{
329 double t, c;
330 int uflow;
331
332 c = cip->ci_calls ? cip->ci_calls : 1;
333 t = (cip->ci_utime + cip->ci_stime) / (double) AHZ;
334 if (t < 0.01) {
335 t = 0.01;

--- 82 unchanged lines hidden ---