comparison toys/other/vmstat.c @ 1596:6eee35009294 draft

Fix bug pointed out by Elliott Hughes ("vmstat 1" should repeat endlessly), and remove final delay (after all output) for "vmstat 2 3" case.
author Rob Landley <rob@landley.net>
date Tue, 02 Dec 2014 16:02:50 -0600
parents a7df29f72bc6
children
comparison
equal deleted inserted replaced
1595:9db327a6920d 1596:6eee35009294
82 82
83 memset(top, 0, sizeof(top)); 83 memset(top, 0, sizeof(top));
84 if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX); 84 if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX);
85 if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX) - 1; 85 if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX) - 1;
86 86
87 for (loop = 0; loop <= loop_max; loop++) { 87 for (loop = 0; !loop_max || loop <= loop_max; loop++) {
88 unsigned idx = loop&1, offset = 0, expected = 0; 88 unsigned idx = loop&1, offset = 0, expected = 0;
89 uint64_t units, total_hz, *ptr = (uint64_t *)(top+idx), 89 uint64_t units, total_hz, *ptr = (uint64_t *)(top+idx),
90 *oldptr = (uint64_t *)(top+!idx); 90 *oldptr = (uint64_t *)(top+!idx);
91
92 if (loop && loop_delay) sleep(loop_delay);
91 93
92 // Print headers 94 // Print headers
93 if (rows>3 && !(loop % (rows-3))) { 95 if (rows>3 && !(loop % (rows-3))) {
94 if (isatty(1)) terminal_size(0, &rows); 96 if (isatty(1)) terminal_size(0, &rows);
95 else rows = 0; 97 else rows = 0;
145 if (len < 0) len = 0; 147 if (len < 0) len = 0;
146 offset += printf(" %*"PRIu64+!i, len, out); 148 offset += printf(" %*"PRIu64+!i, len, out);
147 } 149 }
148 xputc('\n'); 150 xputc('\n');
149 151
150 if (loop_delay) sleep(loop_delay); 152 if (!loop_delay) break;
151 else break;
152 } 153 }
153 } 154 }