Deleted Added
full compact
main.c (141603) main.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

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

31#if 0
32#ifndef lint
33static const char copyright[] =
34"@(#) Copyright (c) 1994 Christopher G. Demetriou\n\
35 All rights reserved.\n";
36#endif
37#endif
38#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

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

31#if 0
32#ifndef lint
33static const char copyright[] =
34"@(#) Copyright (c) 1994 Christopher G. Demetriou\n\
35 All rights reserved.\n";
36#endif
37#endif
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/usr.sbin/sa/main.c 141603 2005-02-10 07:07:32Z delphij $");
39__FBSDID("$FreeBSD: head/usr.sbin/sa/main.c 141638 2005-02-10 12:43:16Z delphij $");
40
41/*
42 * sa: system accounting
43 */
44
45#include <sys/types.h>
46#include <sys/acct.h>
47#include <ctype.h>
48#include <err.h>
49#include <fcntl.h>
50#include <signal.h>
51#include <stdint.h>
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55#include <unistd.h>
56#include "extern.h"
57#include "pathnames.h"
58
40
41/*
42 * sa: system accounting
43 */
44
45#include <sys/types.h>
46#include <sys/acct.h>
47#include <ctype.h>
48#include <err.h>
49#include <fcntl.h>
50#include <signal.h>
51#include <stdint.h>
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55#include <unistd.h>
56#include "extern.h"
57#include "pathnames.h"
58
59static int acct_load(char *, int);
59static int acct_load(const char *, int);
60static u_quad_t decode_comp_t(comp_t);
61static int cmp_comm(const char *, const char *);
62static int cmp_usrsys(const DBT *, const DBT *);
63static int cmp_avgusrsys(const DBT *, const DBT *);
64static int cmp_dkio(const DBT *, const DBT *);
65static int cmp_avgdkio(const DBT *, const DBT *);
66static int cmp_cpumem(const DBT *, const DBT *);
67static int cmp_avgcpumem(const DBT *, const DBT *);

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

294usage()
295{
296 (void)fprintf(stderr,
297 "usage: sa [-abcdDfijkKlmnqrstu] [-v cutoff] [file ...]\n");
298 exit(1);
299}
300
301static int
60static u_quad_t decode_comp_t(comp_t);
61static int cmp_comm(const char *, const char *);
62static int cmp_usrsys(const DBT *, const DBT *);
63static int cmp_avgusrsys(const DBT *, const DBT *);
64static int cmp_dkio(const DBT *, const DBT *);
65static int cmp_avgdkio(const DBT *, const DBT *);
66static int cmp_cpumem(const DBT *, const DBT *);
67static int cmp_avgcpumem(const DBT *, const DBT *);

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

294usage()
295{
296 (void)fprintf(stderr,
297 "usage: sa [-abcdDfijkKlmnqrstu] [-v cutoff] [file ...]\n");
298 exit(1);
299}
300
301static int
302acct_load(pn, wr)
303 char *pn;
304 int wr;
302acct_load(const char *pn, int wr)
305{
306 struct acct ac;
307 struct cmdinfo ci;
308 ssize_t rv;
309 int fd, i;
310
311 /*
312 * open the file

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

387 while (comp--)
388 rv <<= 3;
389
390 return (rv);
391}
392
393/* sort commands, doing the right thing in terms of reversals */
394static int
303{
304 struct acct ac;
305 struct cmdinfo ci;
306 ssize_t rv;
307 int fd, i;
308
309 /*
310 * open the file

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

385 while (comp--)
386 rv <<= 3;
387
388 return (rv);
389}
390
391/* sort commands, doing the right thing in terms of reversals */
392static int
395cmp_comm(s1, s2)
396 const char *s1, *s2;
393cmp_comm(const char *s1, const char *s2)
397{
398 int rv;
399
400 rv = strcmp(s1, s2);
401 if (rv == 0)
402 rv = -1;
403 return (rflag ? rv : -rv);
404}
405
406/* sort by total user and system time */
407static int
394{
395 int rv;
396
397 rv = strcmp(s1, s2);
398 if (rv == 0)
399 rv = -1;
400 return (rflag ? rv : -rv);
401}
402
403/* sort by total user and system time */
404static int
408cmp_usrsys(d1, d2)
409 const DBT *d1, *d2;
405cmp_usrsys(const DBT *d1, const DBT *d2)
410{
411 struct cmdinfo c1, c2;
412 u_quad_t t1, t2;
413
414 memcpy(&c1, d1->data, sizeof(c1));
415 memcpy(&c2, d2->data, sizeof(c2));
416
417 t1 = c1.ci_utime + c1.ci_stime;

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

422 else if (t1 == t2)
423 return (cmp_comm(c1.ci_comm, c2.ci_comm));
424 else
425 return 1;
426}
427
428/* sort by average user and system time */
429static int
406{
407 struct cmdinfo c1, c2;
408 u_quad_t t1, t2;
409
410 memcpy(&c1, d1->data, sizeof(c1));
411 memcpy(&c2, d2->data, sizeof(c2));
412
413 t1 = c1.ci_utime + c1.ci_stime;

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

418 else if (t1 == t2)
419 return (cmp_comm(c1.ci_comm, c2.ci_comm));
420 else
421 return 1;
422}
423
424/* sort by average user and system time */
425static int
430cmp_avgusrsys(d1, d2)
431 const DBT *d1, *d2;
426cmp_avgusrsys(const DBT *d1, const DBT *d2)
432{
433 struct cmdinfo c1, c2;
434 double t1, t2;
435
436 memcpy(&c1, d1->data, sizeof(c1));
437 memcpy(&c2, d2->data, sizeof(c2));
438
439 t1 = c1.ci_utime + c1.ci_stime;

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

447 else if (t1 == t2)
448 return (cmp_comm(c1.ci_comm, c2.ci_comm));
449 else
450 return 1;
451}
452
453/* sort by total number of disk I/O operations */
454static int
427{
428 struct cmdinfo c1, c2;
429 double t1, t2;
430
431 memcpy(&c1, d1->data, sizeof(c1));
432 memcpy(&c2, d2->data, sizeof(c2));
433
434 t1 = c1.ci_utime + c1.ci_stime;

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

442 else if (t1 == t2)
443 return (cmp_comm(c1.ci_comm, c2.ci_comm));
444 else
445 return 1;
446}
447
448/* sort by total number of disk I/O operations */
449static int
455cmp_dkio(d1, d2)
456 const DBT *d1, *d2;
450cmp_dkio(const DBT *d1, const DBT *d2)
457{
458 struct cmdinfo c1, c2;
459
460 memcpy(&c1, d1->data, sizeof(c1));
461 memcpy(&c2, d2->data, sizeof(c2));
462
463 if (c1.ci_io < c2.ci_io)
464 return -1;
465 else if (c1.ci_io == c2.ci_io)
466 return (cmp_comm(c1.ci_comm, c2.ci_comm));
467 else
468 return 1;
469}
470
471/* sort by average number of disk I/O operations */
472static int
451{
452 struct cmdinfo c1, c2;
453
454 memcpy(&c1, d1->data, sizeof(c1));
455 memcpy(&c2, d2->data, sizeof(c2));
456
457 if (c1.ci_io < c2.ci_io)
458 return -1;
459 else if (c1.ci_io == c2.ci_io)
460 return (cmp_comm(c1.ci_comm, c2.ci_comm));
461 else
462 return 1;
463}
464
465/* sort by average number of disk I/O operations */
466static int
473cmp_avgdkio(d1, d2)
474 const DBT *d1, *d2;
467cmp_avgdkio(const DBT *d1, const DBT *d2)
475{
476 struct cmdinfo c1, c2;
477 double n1, n2;
478
479 memcpy(&c1, d1->data, sizeof(c1));
480 memcpy(&c2, d2->data, sizeof(c2));
481
482 n1 = (double) c1.ci_io / (double) (c1.ci_calls ? c1.ci_calls : 1);

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

487 else if (n1 == n2)
488 return (cmp_comm(c1.ci_comm, c2.ci_comm));
489 else
490 return 1;
491}
492
493/* sort by the cpu-storage integral */
494static int
468{
469 struct cmdinfo c1, c2;
470 double n1, n2;
471
472 memcpy(&c1, d1->data, sizeof(c1));
473 memcpy(&c2, d2->data, sizeof(c2));
474
475 n1 = (double) c1.ci_io / (double) (c1.ci_calls ? c1.ci_calls : 1);

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

480 else if (n1 == n2)
481 return (cmp_comm(c1.ci_comm, c2.ci_comm));
482 else
483 return 1;
484}
485
486/* sort by the cpu-storage integral */
487static int
495cmp_cpumem(d1, d2)
496 const DBT *d1, *d2;
488cmp_cpumem(const DBT *d1, const DBT *d2)
497{
498 struct cmdinfo c1, c2;
499
500 memcpy(&c1, d1->data, sizeof(c1));
501 memcpy(&c2, d2->data, sizeof(c2));
502
503 if (c1.ci_mem < c2.ci_mem)
504 return -1;
505 else if (c1.ci_mem == c2.ci_mem)
506 return (cmp_comm(c1.ci_comm, c2.ci_comm));
507 else
508 return 1;
509}
510
511/* sort by the cpu-time average memory usage */
512static int
489{
490 struct cmdinfo c1, c2;
491
492 memcpy(&c1, d1->data, sizeof(c1));
493 memcpy(&c2, d2->data, sizeof(c2));
494
495 if (c1.ci_mem < c2.ci_mem)
496 return -1;
497 else if (c1.ci_mem == c2.ci_mem)
498 return (cmp_comm(c1.ci_comm, c2.ci_comm));
499 else
500 return 1;
501}
502
503/* sort by the cpu-time average memory usage */
504static int
513cmp_avgcpumem(d1, d2)
514 const DBT *d1, *d2;
505cmp_avgcpumem(const DBT *d1, const DBT *d2)
515{
516 struct cmdinfo c1, c2;
517 u_quad_t t1, t2;
518 double n1, n2;
519
520 memcpy(&c1, d1->data, sizeof(c1));
521 memcpy(&c2, d2->data, sizeof(c2));
522

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

531 else if (n1 == n2)
532 return (cmp_comm(c1.ci_comm, c2.ci_comm));
533 else
534 return 1;
535}
536
537/* sort by the number of invocations */
538static int
506{
507 struct cmdinfo c1, c2;
508 u_quad_t t1, t2;
509 double n1, n2;
510
511 memcpy(&c1, d1->data, sizeof(c1));
512 memcpy(&c2, d2->data, sizeof(c2));
513

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

522 else if (n1 == n2)
523 return (cmp_comm(c1.ci_comm, c2.ci_comm));
524 else
525 return 1;
526}
527
528/* sort by the number of invocations */
529static int
539cmp_calls(d1, d2)
540 const DBT *d1, *d2;
530cmp_calls(const DBT *d1, const DBT *d2)
541{
542 struct cmdinfo c1, c2;
543
544 memcpy(&c1, d1->data, sizeof(c1));
545 memcpy(&c2, d2->data, sizeof(c2));
546
547 if (c1.ci_calls < c2.ci_calls)
548 return -1;
549 else if (c1.ci_calls == c2.ci_calls)
550 return (cmp_comm(c1.ci_comm, c2.ci_comm));
551 else
552 return 1;
553}
531{
532 struct cmdinfo c1, c2;
533
534 memcpy(&c1, d1->data, sizeof(c1));
535 memcpy(&c2, d2->data, sizeof(c2));
536
537 if (c1.ci_calls < c2.ci_calls)
538 return -1;
539 else if (c1.ci_calls == c2.ci_calls)
540 return (cmp_comm(c1.ci_comm, c2.ci_comm));
541 else
542 return 1;
543}