1 /*
2 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
3 */
4
5 /*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
11 /* from UCB 5.4 5/17/86 */
12 /* from SunOS 4.1, SID 1.31 */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stdarg.h>
17 #include <ctype.h>
18 #include <unistd.h>
19 #include <memory.h>
20 #include <string.h>
21 #include <fcntl.h>
22 #include <errno.h>
23 #include <signal.h>
24 #include <values.h>
25 #include <poll.h>
26 #include <locale.h>
27
28 #include "statcommon.h"
29
30 char *cmdname = "vmstat";
31 int caught_cont = 0;
32
33 static uint_t timestamp_fmt = NODATE;
208 (void) kstat_close(kc);
209 return (0);
210 }
211
212 #define DELTA(v) (new->v - (old ? old->v : 0))
213 #define ADJ(n) ((adj <= 0) ? n : (adj >= n) ? 1 : n - adj)
214 #define adjprintf(fmt, n, val) adj -= (n + 1) - printf(fmt, ADJ(n), val)
215
216 static int adj; /* number of excess columns */
217
218 /*ARGSUSED*/
219 static void
220 show_disk(void *v1, void *v2, void *d)
221 {
222 struct iodev_snapshot *old = (struct iodev_snapshot *)v1;
223 struct iodev_snapshot *new = (struct iodev_snapshot *)v2;
224 hrtime_t oldtime = new->is_crtime;
225 double hr_etime;
226 double reads, writes;
227
228 if (new == NULL)
229 return;
230
231 if (old)
232 oldtime = old->is_stats.wlastupdate;
233 hr_etime = new->is_stats.wlastupdate - oldtime;
234 if (hr_etime == 0.0)
235 hr_etime = NANOSEC;
236 reads = new->is_stats.reads - (old ? old->is_stats.reads : 0);
237 writes = new->is_stats.writes - (old ? old->is_stats.writes : 0);
238 adjprintf(" %*.0f", 2, (reads + writes) / hr_etime * NANOSEC);
239 }
240
241 static void
242 dovmstats(struct snapshot *old, struct snapshot *new)
243 {
244 kstat_t *oldsys = NULL;
245 kstat_t *newsys = &new->s_sys.ss_agg_sys;
246 kstat_t *oldvm = NULL;
247 kstat_t *newvm = &new->s_sys.ss_agg_vm;
248 double percent_factor;
249 ulong_t sys_updates, vm_updates;
250 int count;
|
1 /*
2 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
3 */
4
5 /*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
11 /* from UCB 5.4 5/17/86 */
12 /* from SunOS 4.1, SID 1.31 */
13
14 /*
15 * Copyright (c) 2018, Joyent, Inc.
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <stdarg.h>
21 #include <ctype.h>
22 #include <unistd.h>
23 #include <memory.h>
24 #include <string.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <signal.h>
28 #include <values.h>
29 #include <poll.h>
30 #include <locale.h>
31
32 #include "statcommon.h"
33
34 char *cmdname = "vmstat";
35 int caught_cont = 0;
36
37 static uint_t timestamp_fmt = NODATE;
212 (void) kstat_close(kc);
213 return (0);
214 }
215
216 #define DELTA(v) (new->v - (old ? old->v : 0))
217 #define ADJ(n) ((adj <= 0) ? n : (adj >= n) ? 1 : n - adj)
218 #define adjprintf(fmt, n, val) adj -= (n + 1) - printf(fmt, ADJ(n), val)
219
220 static int adj; /* number of excess columns */
221
222 /*ARGSUSED*/
223 static void
224 show_disk(void *v1, void *v2, void *d)
225 {
226 struct iodev_snapshot *old = (struct iodev_snapshot *)v1;
227 struct iodev_snapshot *new = (struct iodev_snapshot *)v2;
228 hrtime_t oldtime = new->is_crtime;
229 double hr_etime;
230 double reads, writes;
231
232 if (old)
233 oldtime = old->is_stats.wlastupdate;
234 hr_etime = new->is_stats.wlastupdate - oldtime;
235 if (hr_etime == 0.0)
236 hr_etime = NANOSEC;
237 reads = new->is_stats.reads - (old ? old->is_stats.reads : 0);
238 writes = new->is_stats.writes - (old ? old->is_stats.writes : 0);
239 adjprintf(" %*.0f", 2, (reads + writes) / hr_etime * NANOSEC);
240 }
241
242 static void
243 dovmstats(struct snapshot *old, struct snapshot *new)
244 {
245 kstat_t *oldsys = NULL;
246 kstat_t *newsys = &new->s_sys.ss_agg_sys;
247 kstat_t *oldvm = NULL;
248 kstat_t *newvm = &new->s_sys.ss_agg_vm;
249 double percent_factor;
250 ulong_t sys_updates, vm_updates;
251 int count;
|