vmstat.c (164718) | vmstat.c (175387) |
---|---|
1/*- 2 * Copyright (c) 1983, 1989, 1992, 1993 3 * The Regents of the University of California. 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 --- 19 unchanged lines hidden (view full) --- 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#include <sys/cdefs.h> 35 | 1/*- 2 * Copyright (c) 1983, 1989, 1992, 1993 3 * The Regents of the University of California. 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 --- 19 unchanged lines hidden (view full) --- 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#include <sys/cdefs.h> 35 |
36__FBSDID("$FreeBSD: head/usr.bin/systat/vmstat.c 164718 2006-11-28 12:46:02Z ru $"); | 36__FBSDID("$FreeBSD: head/usr.bin/systat/vmstat.c 175387 2008-01-16 19:27:43Z delphij $"); |
37 38#ifdef lint 39static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; 40#endif 41 42/* 43 * Cursed vmstat -- from Robert Elz. 44 */ --- 104 unchanged lines hidden (view full) --- 149static long *intrloc; 150static char **intrname; 151static int nextintsrow; 152 153struct utmp utmp; 154 155 156WINDOW * | 37 38#ifdef lint 39static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; 40#endif 41 42/* 43 * Cursed vmstat -- from Robert Elz. 44 */ --- 104 unchanged lines hidden (view full) --- 149static long *intrloc; 150static char **intrname; 151static int nextintsrow; 152 153struct utmp utmp; 154 155 156WINDOW * |
157openkre() | 157openkre(void) |
158{ 159 160 ut = open(_PATH_UTMP, O_RDONLY); 161 if (ut < 0) 162 error("No utmp"); 163 return (stdscr); 164} 165 166void | 158{ 159 160 ut = open(_PATH_UTMP, O_RDONLY); 161 if (ut < 0) 162 error("No utmp"); 163 return (stdscr); 164} 165 166void |
167closekre(w) 168 WINDOW *w; | 167closekre(WINDOW *w) |
169{ 170 171 (void) close(ut); 172 if (w == NULL) 173 return; 174 wclear(w); 175 wrefresh(w); 176} --- 24 unchanged lines hidden (view full) --- 201#define DISKROW 18 /* uses 5 rows and 47 cols (for 7 drives) */ 202#define DISKCOL 0 203 204#define DRIVESPACE 7 /* max # for space */ 205 206#define MAXDRIVES DRIVESPACE /* max # to display */ 207 208int | 168{ 169 170 (void) close(ut); 171 if (w == NULL) 172 return; 173 wclear(w); 174 wrefresh(w); 175} --- 24 unchanged lines hidden (view full) --- 200#define DISKROW 18 /* uses 5 rows and 47 cols (for 7 drives) */ 201#define DISKCOL 0 202 203#define DRIVESPACE 7 /* max # for space */ 204 205#define MAXDRIVES DRIVESPACE /* max # to display */ 206 207int |
209initkre() | 208initkre(void) |
210{ 211 char *cp, *cp1, *cp2, *intrnamebuf, *nextcp; 212 int i; 213 size_t sz; 214 215 if ((num_devices = devstat_getnumdevs(NULL)) < 0) { 216 warnx("%s", devstat_errbuf); 217 return(0); --- 73 unchanged lines hidden (view full) --- 291 allocinfo(&z); 292 } 293 getinfo(&s2); 294 copyinfo(&s2, &s1); 295 return(1); 296} 297 298void | 209{ 210 char *cp, *cp1, *cp2, *intrnamebuf, *nextcp; 211 int i; 212 size_t sz; 213 214 if ((num_devices = devstat_getnumdevs(NULL)) < 0) { 215 warnx("%s", devstat_errbuf); 216 return(0); --- 73 unchanged lines hidden (view full) --- 290 allocinfo(&z); 291 } 292 getinfo(&s2); 293 copyinfo(&s2, &s1); 294 return(1); 295} 296 297void |
299fetchkre() | 298fetchkre(void) |
300{ 301 time_t now; 302 struct tm *tp; 303 static int d_first = -1; 304 305 if (d_first < 0) 306 d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); 307 308 time(&now); 309 tp = localtime(&now); 310 (void) strftime(buf, sizeof(buf), 311 d_first ? "%e %b %R" : "%b %e %R", tp); 312 getinfo(&s); 313} 314 315void | 299{ 300 time_t now; 301 struct tm *tp; 302 static int d_first = -1; 303 304 if (d_first < 0) 305 d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); 306 307 time(&now); 308 tp = localtime(&now); 309 (void) strftime(buf, sizeof(buf), 310 d_first ? "%e %b %R" : "%b %e %R", tp); 311 getinfo(&s); 312} 313 314void |
316labelkre() | 315labelkre(void) |
317{ 318 int i, j; 319 320 clear(); 321 mvprintw(STATROW, STATCOL + 6, "users Load"); 322 mvprintw(MEMROW, MEMCOL, "Mem:KB REAL VIRTUAL"); 323 mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); 324 mvprintw(MEMROW + 2, MEMCOL, "Act"); --- 86 unchanged lines hidden (view full) --- 411} while (0) 412#define MAXFAIL 5 413 414static char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' }; 415static char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE, 416 CP_IDLE }; 417 418void | 316{ 317 int i, j; 318 319 clear(); 320 mvprintw(STATROW, STATCOL + 6, "users Load"); 321 mvprintw(MEMROW, MEMCOL, "Mem:KB REAL VIRTUAL"); 322 mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); 323 mvprintw(MEMROW + 2, MEMCOL, "Act"); --- 86 unchanged lines hidden (view full) --- 410} while (0) 411#define MAXFAIL 5 412 413static char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' }; 414static char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE, 415 CP_IDLE }; 416 417void |
419showkre() | 418showkre(void) |
420{ 421 float f1, f2; 422 int psiz, inttotal; 423 int i, l, lc; 424 static int failcnt = 0; 425 426 etime = 0; 427 for(i = 0; i < CPUSTATES; i++) { --- 135 unchanged lines hidden (view full) --- 563 NAMEIROW + 2, NAMEICOL + 17, 3, 0, 1); 564 putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 21, 7); 565 putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), 566 NAMEIROW + 2, NAMEICOL + 29, 3, 0, 1); 567#undef nz 568} 569 570int | 419{ 420 float f1, f2; 421 int psiz, inttotal; 422 int i, l, lc; 423 static int failcnt = 0; 424 425 etime = 0; 426 for(i = 0; i < CPUSTATES; i++) { --- 135 unchanged lines hidden (view full) --- 562 NAMEIROW + 2, NAMEICOL + 17, 3, 0, 1); 563 putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 21, 7); 564 putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), 565 NAMEIROW + 2, NAMEICOL + 29, 3, 0, 1); 566#undef nz 567} 568 569int |
571cmdkre(cmd, args) 572 const char *cmd, *args; | 570cmdkre(const char *cmd, const char *args) |
573{ 574 int retval; 575 576 if (prefix(cmd, "run")) { 577 retval = 1; 578 copyinfo(&s2, &s1); 579 switch (devstat_getdevs(NULL, &run)) { 580 case -1: --- 47 unchanged lines hidden (view full) --- 628 if (retval == 2) 629 labelkre(); 630 631 return(retval); 632} 633 634/* calculate number of users on the system */ 635static int | 571{ 572 int retval; 573 574 if (prefix(cmd, "run")) { 575 retval = 1; 576 copyinfo(&s2, &s1); 577 switch (devstat_getdevs(NULL, &run)) { 578 case -1: --- 47 unchanged lines hidden (view full) --- 626 if (retval == 2) 627 labelkre(); 628 629 return(retval); 630} 631 632/* calculate number of users on the system */ 633static int |
636ucount() | 634ucount(void) |
637{ 638 int nusers = 0; 639 640 if (ut < 0) 641 return (0); 642 while (read(ut, &utmp, sizeof(utmp))) 643 if (utmp.ut_name[0] != '\0') 644 nusers++; 645 646 lseek(ut, 0L, L_SET); 647 return (nusers); 648} 649 650static float | 635{ 636 int nusers = 0; 637 638 if (ut < 0) 639 return (0); 640 while (read(ut, &utmp, sizeof(utmp))) 641 if (utmp.ut_name[0] != '\0') 642 nusers++; 643 644 lseek(ut, 0L, L_SET); 645 return (nusers); 646} 647 648static float |
651cputime(indx) 652 int indx; | 649cputime(int indx) |
653{ 654 double lt; 655 int i; 656 657 lt = 0; 658 for (i = 0; i < CPUSTATES; i++) 659 lt += s.time[i]; 660 if (lt == 0.0) 661 lt = 1.0; 662 return (s.time[indx] * 100.0 / lt); 663} 664 665static void | 650{ 651 double lt; 652 int i; 653 654 lt = 0; 655 for (i = 0; i < CPUSTATES; i++) 656 lt += s.time[i]; 657 if (lt == 0.0) 658 lt = 1.0; 659 return (s.time[indx] * 100.0 / lt); 660} 661 662static void |
666putint(n, l, lc, w) 667 int n, l, lc, w; | 663putint(int n, int l, int lc, int w) |
668{ 669 int snr; 670 char b[128]; 671 672 move(l, lc); 673#ifdef DEBUG 674 while (w-- > 0) 675 addch('*'); --- 13 unchanged lines hidden (view full) --- 689 while (w-- > 0) 690 addch('*'); 691 return; 692 } 693 addstr(b); 694} 695 696static void | 664{ 665 int snr; 666 char b[128]; 667 668 move(l, lc); 669#ifdef DEBUG 670 while (w-- > 0) 671 addch('*'); --- 13 unchanged lines hidden (view full) --- 685 while (w-- > 0) 686 addch('*'); 687 return; 688 } 689 addstr(b); 690} 691 692static void |
697putfloat(f, l, lc, w, d, nz) 698 double f; 699 int l, lc, w, d, nz; | 693putfloat(double f, int l, int lc, int w, int d, int nz) |
700{ 701 int snr; 702 char b[128]; 703 704 move(l, lc); 705#ifdef DEBUG 706 while (--w >= 0) 707 addch('*'); --- 11 unchanged lines hidden (view full) --- 719 while (--w >= 0) 720 addch('*'); 721 return; 722 } 723 addstr(b); 724} 725 726static void | 694{ 695 int snr; 696 char b[128]; 697 698 move(l, lc); 699#ifdef DEBUG 700 while (--w >= 0) 701 addch('*'); --- 11 unchanged lines hidden (view full) --- 713 while (--w >= 0) 714 addch('*'); 715 return; 716 } 717 addstr(b); 718} 719 720static void |
727putlongdouble(f, l, lc, w, d, nz) 728 long double f; 729 int l, lc, w, d, nz; | 721putlongdouble(long double f, int l, int lc, int w, int d, int nz) |
730{ 731 int snr; 732 char b[128]; 733 734 move(l, lc); 735#ifdef DEBUG 736 while (--w >= 0) 737 addch('*'); --- 11 unchanged lines hidden (view full) --- 749 while (--w >= 0) 750 addch('*'); 751 return; 752 } 753 addstr(b); 754} 755 756static void | 722{ 723 int snr; 724 char b[128]; 725 726 move(l, lc); 727#ifdef DEBUG 728 while (--w >= 0) 729 addch('*'); --- 11 unchanged lines hidden (view full) --- 741 while (--w >= 0) 742 addch('*'); 743 return; 744 } 745 addstr(b); 746} 747 748static void |
757getinfo(ls) 758 struct Info *ls; | 749getinfo(struct Info *ls) |
759{ 760 struct devinfo *tmp_dinfo; 761 size_t size; 762 int mib[2]; 763 764 GETSYSCTL("kern.cp_time", ls->time); 765 GETSYSCTL("kern.cp_time", cur.cp_time); 766 GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch); --- 61 unchanged lines hidden (view full) --- 828 cmdkre("refresh", NULL); 829 break; 830 default: 831 break; 832 } 833} 834 835static void | 750{ 751 struct devinfo *tmp_dinfo; 752 size_t size; 753 int mib[2]; 754 755 GETSYSCTL("kern.cp_time", ls->time); 756 GETSYSCTL("kern.cp_time", cur.cp_time); 757 GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch); --- 61 unchanged lines hidden (view full) --- 819 cmdkre("refresh", NULL); 820 break; 821 default: 822 break; 823 } 824} 825 826static void |
836allocinfo(ls) 837 struct Info *ls; | 827allocinfo(struct Info *ls) |
838{ 839 840 ls->intrcnt = (long *) calloc(nintr, sizeof(long)); 841 if (ls->intrcnt == NULL) 842 errx(2, "out of memory"); 843} 844 845static void | 828{ 829 830 ls->intrcnt = (long *) calloc(nintr, sizeof(long)); 831 if (ls->intrcnt == NULL) 832 errx(2, "out of memory"); 833} 834 835static void |
846copyinfo(from, to) 847 struct Info *from, *to; | 836copyinfo(struct Info *from, struct Info *to) |
848{ 849 long *intrcnt; 850 851 /* 852 * time, wds, seek, and xfer are malloc'd so we have to 853 * save the pointers before the structure copy and then 854 * copy by hand. 855 */ 856 intrcnt = to->intrcnt; 857 *to = *from; 858 859 bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); 860} 861 862static void | 837{ 838 long *intrcnt; 839 840 /* 841 * time, wds, seek, and xfer are malloc'd so we have to 842 * save the pointers before the structure copy and then 843 * copy by hand. 844 */ 845 intrcnt = to->intrcnt; 846 *to = *from; 847 848 bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int)); 849} 850 851static void |
863dinfo(dn, lc, now, then) 864 int dn, lc; 865 struct statinfo *now, *then; | 852dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then) |
866{ 867 long double transfers_per_second; 868 long double kb_per_transfer, mb_per_second; 869 long double elapsed_time, device_busy; 870 int di; 871 872 di = dev_select[dn].position; 873 --- 24 unchanged lines hidden --- | 853{ 854 long double transfers_per_second; 855 long double kb_per_transfer, mb_per_second; 856 long double elapsed_time, device_busy; 857 int di; 858 859 di = dev_select[dn].position; 860 --- 24 unchanged lines hidden --- |