vmstat.c revision c65c9cdc54c4ba51aeb34ab36b73286653013c8a
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/* from UCB 5.4 5/17/86 */
/* from SunOS 4.1, SID 1.31 */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <memory.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <values.h>
#include <poll.h>
#include <locale.h>
#include "statcommon.h"
char *cmdname = "vmstat";
int caught_cont = 0;
static int hz;
static int pagesize;
static double etime;
static int lines = 1;
static int suppress_state;
static long iter = 0;
struct iodev_filter df;
#define denom(x) ((x) ? (x) : 1)
#define REPRINT 19
static void printhdr(int);
static void usage(void);
int
{
int summary = 0;
int intr = 0;
int forever = 0;
int c;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'S':
break;
case 's':
summary = 1;
break;
case 'i':
intr = 1;
break;
case 'c':
cflag++;
break;
case 'q':
suppress_state = 1;
break;
case 'p':
pflag++; /* detailed paging info */
break;
case 'T':
if (optarg) {
if (*optarg == 'u')
else if (*optarg == 'd')
else
usage();
} else {
usage();
}
break;
default:
usage();
}
/* consistency with iostat */
if (intr)
types |= SNAP_INTERRUPTS;
if (cflag)
types |= SNAP_FLUSHES;
if (!intr)
types |= SNAP_IODEVS;
/* max to fit in less than 80 characters */
df.if_nr_names = 0;
df.if_nr_names++;
}
kc = open_kstat();
/* time, in seconds, since boot */
if (intr) {
exit(0);
}
if (summary) {
exit(0);
}
if (argc > 0) {
long interval;
char *endptr;
errno = 0;
usage();
if (period_n <= 0)
usage();
if (argc > 1) {
usage();
} else
forever = 1;
if (argc > 2)
usage();
}
if (cflag) {
exit(0);
}
/* (void) poll(NULL, 0, poll_interval); */
/* Have a kip */
if (!suppress_state)
/* if config changed, show stats from boot */
}
}
(void) kstat_close(kc);
return (0);
}
static int adj; /* number of excess columns */
/*ARGSUSED*/
static void
{
double hr_etime;
return;
if (old)
if (hr_etime == 0.0)
}
static void
{
double percent_factor;
int count;
adj = 0;
if (old) {
}
/*
* If any time has passed, convert etime to seconds per CPU
*/
if (timestamp_fmt != NODATE) {
lines--;
}
if (--lines <= 0)
printhdr(0);
adj = 0;
if (pflag) {
/ vm_updates)));
/ etime);
/ etime);
/ etime);
return;
}
/ vm_updates)));
/ vm_updates)));
/ etime);
/ etime);
/ etime);
/ etime);
while (count-- > 0)
* percent_factor);
* percent_factor);
}
/*ARGSUSED*/
static void
print_disk(void *v, void *v2, void *d)
{
return;
}
/* ARGSUSED */
static void
{
caught_cont = 1;
if (pflag) {
(void) printf(" memory page ");
(void) printf("executable anonymous filesystem \n");
(void) printf(" swap free re mf fr de sr ");
(void) printf("epi epo epf api apo apf fpi fpo fpf\n");
return;
}
(void) printf(" kthr memory page ");
(void) printf("disk faults cpu\n");
if (swflag)
(void) printf(" r b w swap free si so pi po fr de sr ");
else
(void) printf(" r b w swap free re mf pi po fr de sr ");
while (i-- > 0)
(void) printf("-- ");
(void) printf(" in sy cs us sy id\n");
}
static void
{
fail(0, "kstat_data_lookup('%s', '%s') failed",
}
}
static void
{
long double nchtotal;
fail(0, "kstat_data_lookup('%s', 'hat_fault') failed",
}
fail(0, "kstat_data_lookup('%s', 'as_fault') failed",
}
(void) printf("%9llu total address trans. faults taken\n",
(void) printf("%9.0Lf total name lookups (cache hits %.0Lf%%)\n",
}
static void
{
size_t i;
(void) printf("interrupt total rate\n");
(void) printf("--------------------------------\n");
for (i = 0; i < ss->s_nr_intrs; i++) {
(void) printf("%-12.8s %10lu %8.0f\n",
}
(void) printf("--------------------------------\n");
}
static void
{
int i;
if (iter == 0) {
(void) printf("flush statistics: (totals)\n");
(void) printf("%8s%8s%8s%8s%8s%8s\n",
"usr", "ctx", "rgn", "seg", "pag", "par");
(void) printf(" %7d %7d %7d %7d %7d %7d\n",
return;
}
(void) printf("flush statistics: (interval based)\n");
for (i = 0; i < iter; i++) {
if (i % REPRINT == 0)
(void) printf("%8s%8s%8s%8s%8s%8s\n",
"usr", "ctx", "rgn", "seg", "pag", "par");
/* Have a kip */
(void) printf(" %7d %7d %7d %7d %7d %7d\n",
}
}
static void
usage(void)
{
"Usage: vmstat [-cipqsS] [-T d|u] [disk ...] "
"[interval [count]]\n");
exit(1);
}