vmstat.c (1a0fda2b547365c9453523592a445dfe21266d4b) vmstat.c (8b10473d306790f1c5feeff564aa27f59a9a36e4)
1/*
2 * Copyright (c) 1980, 1986, 1991, 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

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

52#include <sys/uio.h>
53#include <sys/namei.h>
54#include <sys/malloc.h>
55#include <sys/signal.h>
56#include <sys/fcntl.h>
57#include <sys/ioctl.h>
58#include <sys/resource.h>
59#include <sys/sysctl.h>
1/*
2 * Copyright (c) 1980, 1986, 1991, 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

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

52#include <sys/uio.h>
53#include <sys/namei.h>
54#include <sys/malloc.h>
55#include <sys/signal.h>
56#include <sys/fcntl.h>
57#include <sys/ioctl.h>
58#include <sys/resource.h>
59#include <sys/sysctl.h>
60#include <sys/time.h>
60#include <sys/vmmeter.h>
61#include <sys/pcpu.h>
62
63#include <vm/vm_param.h>
64
65#include <ctype.h>
66#include <devstat.h>
67#include <err.h>

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

176
177static char **getdrivedata(char **);
178
179int
180main(int argc, char *argv[])
181{
182 int c, todo;
183 unsigned int interval;
61#include <sys/vmmeter.h>
62#include <sys/pcpu.h>
63
64#include <vm/vm_param.h>
65
66#include <ctype.h>
67#include <devstat.h>
68#include <err.h>

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

177
178static char **getdrivedata(char **);
179
180int
181main(int argc, char *argv[])
182{
183 int c, todo;
184 unsigned int interval;
185 float f;
184 int reps;
185 char *memf, *nlistf;
186 char errbuf[_POSIX2_LINE_MAX];
187
188 memf = nlistf = NULL;
189 interval = reps = todo = 0;
190 maxshowdevs = 2;
191 hflag = isatty(1);

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

238 case 't':
239#ifdef notyet
240 todo |= TIMESTAT;
241#else
242 errx(EX_USAGE, "sorry, -t is not (re)implemented yet");
243#endif
244 break;
245 case 'w':
186 int reps;
187 char *memf, *nlistf;
188 char errbuf[_POSIX2_LINE_MAX];
189
190 memf = nlistf = NULL;
191 interval = reps = todo = 0;
192 maxshowdevs = 2;
193 hflag = isatty(1);

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

240 case 't':
241#ifdef notyet
242 todo |= TIMESTAT;
243#else
244 errx(EX_USAGE, "sorry, -t is not (re)implemented yet");
245#endif
246 break;
247 case 'w':
246 interval = atoi(optarg);
248 /* Convert to milliseconds. */
249 f = atof(optarg);
250 interval = f * 1000;
247 break;
248 case 'z':
249 todo |= ZMEMSTAT;
250 break;
251 case '?':
252 default:
253 usage();
254 }

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

293
294
295 argv = getdrivedata(argv);
296 }
297
298#define BACKWARD_COMPATIBILITY
299#ifdef BACKWARD_COMPATIBILITY
300 if (*argv) {
251 break;
252 case 'z':
253 todo |= ZMEMSTAT;
254 break;
255 case '?':
256 default:
257 usage();
258 }

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

297
298
299 argv = getdrivedata(argv);
300 }
301
302#define BACKWARD_COMPATIBILITY
303#ifdef BACKWARD_COMPATIBILITY
304 if (*argv) {
301 interval = atoi(*argv);
305 f = atof(*argv);
306 interval = f * 1000;
302 if (*++argv)
303 reps = atoi(*argv);
304 }
305#endif
306
307 if (interval) {
308 if (!reps)
309 reps = -1;
310 } else if (reps)
307 if (*++argv)
308 reps = atoi(*argv);
309 }
310#endif
311
312 if (interval) {
313 if (!reps)
314 reps = -1;
315 } else if (reps)
311 interval = 1;
316 interval = 1 * 1000;
312
313 if (todo & FORKSTAT)
314 doforkst();
315 if (todo & MEMSTAT)
316 domemstat_malloc();
317 if (todo & ZMEMSTAT)
318 domemstat_zone();
319 if (todo & SUMSTAT)

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

647dovmstat(unsigned int interval, int reps)
648{
649 struct vmtotal total;
650 time_t uptime, halfuptime;
651 struct devinfo *tmp_dinfo;
652 size_t size;
653 int ncpus, maxid;
654 u_long cpumask;
317
318 if (todo & FORKSTAT)
319 doforkst();
320 if (todo & MEMSTAT)
321 domemstat_malloc();
322 if (todo & ZMEMSTAT)
323 domemstat_zone();
324 if (todo & SUMSTAT)

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

652dovmstat(unsigned int interval, int reps)
653{
654 struct vmtotal total;
655 time_t uptime, halfuptime;
656 struct devinfo *tmp_dinfo;
657 size_t size;
658 int ncpus, maxid;
659 u_long cpumask;
660 int rate_adj;
655
656 uptime = getuptime();
657 halfuptime = uptime / 2;
661
662 uptime = getuptime();
663 halfuptime = uptime / 2;
664 rate_adj = 1;
658
659 /*
660 * If the user stops the program (control-Z) and then resumes it,
661 * print out the header again.
662 */
663 (void)signal(SIGCONT, needhdr);
664
665 /*

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

761 break;
762 }
763
764 fill_vmmeter(&sum);
765 fill_vmtotal(&total);
766 (void)printf("%2d %1d %1d",
767 total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
768#define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10))
665
666 /*
667 * If the user stops the program (control-Z) and then resumes it,
668 * print out the header again.
669 */
670 (void)signal(SIGCONT, needhdr);
671
672 /*

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

768 break;
769 }
770
771 fill_vmmeter(&sum);
772 fill_vmtotal(&total);
773 (void)printf("%2d %1d %1d",
774 total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
775#define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10))
769#define rate(x) (((x) + halfuptime) / uptime) /* round */
776#define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */
770 if (hflag) {
771 printf(" ");
772 prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7);
773 printf(" ");
774 prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6);
775 printf(" ");
776 } else {
777 printf(" %7d ", vmstat_pgtok(total.t_avm));

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

801 else
802 cpustats();
803 (void)printf("\n");
804 (void)fflush(stdout);
805 if (reps >= 0 && --reps <= 0)
806 break;
807 osum = sum;
808 uptime = interval;
777 if (hflag) {
778 printf(" ");
779 prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7);
780 printf(" ");
781 prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6);
782 printf(" ");
783 } else {
784 printf(" %7d ", vmstat_pgtok(total.t_avm));

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

808 else
809 cpustats();
810 (void)printf("\n");
811 (void)fflush(stdout);
812 if (reps >= 0 && --reps <= 0)
813 break;
814 osum = sum;
815 uptime = interval;
816 rate_adj = 1000;
809 /*
810 * We round upward to avoid losing low-frequency events
817 /*
818 * We round upward to avoid losing low-frequency events
811 * (i.e., >= 1 per interval but < 1 per second).
819 * (i.e., >= 1 per interval but < 1 per millisecond).
812 */
813 if (interval != 1)
814 halfuptime = (uptime + 1) / 2;
815 else
816 halfuptime = 0;
820 */
821 if (interval != 1)
822 halfuptime = (uptime + 1) / 2;
823 else
824 halfuptime = 0;
817 (void)sleep(interval);
825 (void)usleep(interval * 1000);
818 }
819}
820
821static void
822printhdr(int ncpus, u_long cpumask)
823{
824 int i, num_shown;
825

--- 534 unchanged lines hidden ---
826 }
827}
828
829static void
830printhdr(int ncpus, u_long cpumask)
831{
832 int i, num_shown;
833

--- 534 unchanged lines hidden ---