Created
November 5, 2014 15:19
-
-
Save tuxillo/21f67c78f55ab456c0c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c | |
index ef371ce..004bb02 100644 | |
--- a/usr.bin/vmstat/vmstat.c | |
+++ b/usr.bin/vmstat/vmstat.c | |
@@ -380,13 +380,31 @@ getuptime(void) | |
int hdrcnt; | |
static void | |
+do_sysctl(struct vmmeter *vmmp, struct vmstats *vmsp, struct vmtotal *totalp) | |
+{ | |
+ size_t vmm_size = sizeof(*vmmp); | |
+ size_t vms_size = sizeof(*vmsp); | |
+ size_t vmt_size = sizeof(*totalp); | |
+ | |
+ if (sysctlbyname("vm.vmstats", vmsp, &vms_size, NULL, 0)) { | |
+ perror("sysctlbyname: vm.vmstats"); | |
+ exit(1); | |
+ } | |
+ if (sysctlbyname("vm.vmmeter", vmmp, &vmm_size, NULL, 0)) { | |
+ perror("sysctlbyname: vm.vmmeter"); | |
+ exit(1); | |
+ } | |
+ if (sysctlbyname("vm.vmtotal", totalp, &vmt_size, NULL, 0)) { | |
+ perror("sysctlbyname: vm.vmtotal"); | |
+ exit(1); | |
+ } | |
+} | |
+ | |
+static void | |
dovmstat(u_int interval, int reps) | |
{ | |
struct vmtotal total; | |
struct devinfo *tmp_dinfo; | |
- size_t vmm_size = sizeof(vmm); | |
- size_t vms_size = sizeof(vms); | |
- size_t vmt_size = sizeof(total); | |
int initial = 1; | |
signal(SIGCONT, needhdr); | |
@@ -441,18 +459,13 @@ dovmstat(u_int interval, int reps) | |
break; | |
} | |
- if (sysctlbyname("vm.vmstats", &vms, &vms_size, NULL, 0)) { | |
- perror("sysctlbyname: vm.vmstats"); | |
- exit(1); | |
+ do_sysctl(&vmm, &vms, &total); | |
+ if (initial) { | |
+ /* Wait for the specified interval for the first seq */ | |
+ usleep(interval * 1000); | |
+ ovmm = vmm; | |
+ do_sysctl(&vmm, &vms, &total); | |
} | |
- if (sysctlbyname("vm.vmmeter", &vmm, &vmm_size, NULL, 0)) { | |
- perror("sysctlbyname: vm.vmmeter"); | |
- exit(1); | |
- } | |
- if (sysctlbyname("vm.vmtotal", &total, &vmt_size, NULL, 0)) { | |
- perror("sysctlbyname: vm.vmtotal"); | |
- exit(1); | |
- } | |
printf("%2ld %1ld %1ld", | |
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment