summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Levon <john.levon@sun.com>2009-03-20 07:49:30 -0700
committerJohn Levon <john.levon@sun.com>2009-03-20 07:49:30 -0700
commit4944376cd5de3dcd3b4feeaad9cbedbc024d1474 (patch)
tree6e2782b9453770efeb9cd5aa1025a7208979339f
parent45a9a7b1085ec7faee89aaf1367379a0bf23f50a (diff)
downloadillumos-gate-4944376cd5de3dcd3b4feeaad9cbedbc024d1474.tar.gz
PSARC/2009/105 Time stamp option for xxstat commands
4775687 would like a timestamp option like iostat has added to mpstat, vmstat and prstat Contributed by Chad Mynhier <cmynhier@gmail.com>
-rw-r--r--usr/src/cmd/kstat/kstat.pl9
-rw-r--r--usr/src/cmd/prstat/prstat.c68
-rw-r--r--usr/src/cmd/prstat/prstat.h6
-rw-r--r--usr/src/cmd/prstat/prutil.c6
-rw-r--r--usr/src/cmd/stat/common/common.c33
-rw-r--r--usr/src/cmd/stat/common/statcommon.h12
-rw-r--r--usr/src/cmd/stat/fsstat/fsstat.c57
-rw-r--r--usr/src/cmd/stat/iostat/iostat.c56
-rw-r--r--usr/src/cmd/stat/mpstat/mpstat.c115
-rw-r--r--usr/src/cmd/stat/vmstat/vmstat.c123
10 files changed, 282 insertions, 203 deletions
diff --git a/usr/src/cmd/kstat/kstat.pl b/usr/src/cmd/kstat/kstat.pl
index a10af503ed..44eaf85e1d 100644
--- a/usr/src/cmd/kstat/kstat.pl
+++ b/usr/src/cmd/kstat/kstat.pl
@@ -21,7 +21,7 @@
#
#
#
-# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -30,7 +30,8 @@ use strict;
use warnings;
use locale;
use Getopt::Std;
-use POSIX qw(locale_h ctime);
+use POSIX qw(locale_h strftime);
+use I18N::Langinfo qw(langinfo D_T_FMT);
use File::Basename;
use Sun::Solaris::Utils qw(textdomain gettext gmatch);
use Sun::Solaris::Kstat;
@@ -135,9 +136,11 @@ if (@ARGV >= 2 && $ARGV[-2] =~ /^\d+$/ && $ARGV[-1] =~ /^\d+$/) {
# Get timestamp flag
my $timestamp;
+my $timefmt;
if ($timestamp = $opt{T}) {
if ($timestamp eq "d") {
- $timestamp = sub { print(ctime(time())); };
+ $timefmt = langinfo(D_T_FMT) . "\n";
+ $timestamp = sub { print(strftime($timefmt, localtime())); };
} elsif ($timestamp eq "u") {
$timestamp = sub { print(time(), "\n"); };
} else {
diff --git a/usr/src/cmd/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c
index 5a4b9185ea..34f5feff05 100644
--- a/usr/src/cmd/prstat/prstat.c
+++ b/usr/src/cmd/prstat/prstat.c
@@ -20,12 +20,10 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/loadavg.h>
@@ -49,6 +47,7 @@
#include <time.h>
#include <project.h>
+#include <langinfo.h>
#include <libintl.h>
#include <locale.h>
@@ -174,6 +173,34 @@ static optdesc_t opts = {
-1 /* sort in decreasing order */
};
+/*
+ * Print timestamp as decimal reprentation of time_t value (-d u was specified)
+ * or the standard date format (-d d was specified).
+ */
+static void
+print_timestamp(void)
+{
+ time_t t = time(NULL);
+ static char *fmt = NULL;
+
+ /* We only need to retrieve this once per invocation */
+ if (fmt == NULL)
+ fmt = nl_langinfo(_DATE_FMT);
+
+ if (opts.o_outpmode & OPT_UDATE) {
+ (void) printf("%ld", t);
+ } else if (opts.o_outpmode & OPT_DDATE) {
+ char dstr[64];
+ int len;
+
+ len = strftime(dstr, sizeof (dstr), fmt, localtime(&t));
+ if (len > 0)
+ (void) printf("%s", dstr);
+ }
+ (void) putp(t_eol);
+ (void) putchar('\n');
+}
+
static void
psetloadavg(long psetid, void *ptr)
{
@@ -338,6 +365,9 @@ list_print(list_t *list)
(void) getloadavg(loadavg, 3);
}
+ if (((opts.o_outpmode & OPT_UDATE) || (opts.o_outpmode & OPT_DDATE)) &&
+ ((list->l_type == LT_LWPS) || !(opts.o_outpmode & OPT_SPLIT)))
+ print_timestamp();
if (opts.o_outpmode & OPT_TTY)
(void) putchar('\r');
(void) putp(t_ulon);
@@ -916,8 +946,7 @@ prstat_scandir(DIR *procdir)
lwpsinfo->pr_onpro) ||
!has_element(&set_tbl,
lwpsinfo->pr_bindpset) ||
- !has_element(&lgr_tbl,
- lwpsinfo->pr_lgrp))
+ !has_element(&lgr_tbl, lwpsinfo->pr_lgrp))
continue;
nlwps++;
if ((opts.o_outpmode & (OPT_PSETS | OPT_LWPS))
@@ -1116,6 +1145,9 @@ setmovecur()
else
n = opts.o_ntop + 1;
}
+ if (((opts.o_outpmode & OPT_UDATE) || (opts.o_outpmode & OPT_DDATE)))
+ n++;
+
if (movecur != NULL && movecur != empty_string && movecur != t_home)
free(movecur);
movecur = Zalloc(strlen(t_up) * (n + 5));
@@ -1140,6 +1172,9 @@ setsize()
return (1);
}
n = n - 3; /* minus header, total and cursor lines */
+ if ((opts.o_outpmode & OPT_UDATE) ||
+ (opts.o_outpmode & OPT_DDATE))
+ n--; /* minus timestamp */
if (n < 1)
Die(gettext("window is too small (try -n)\n"));
if (opts.o_outpmode & OPT_SPLIT) {
@@ -1322,8 +1357,8 @@ main(int argc, char **argv)
pagesize = sysconf(_SC_PAGESIZE);
- while ((opt = getopt(argc, argv, "vcHmaRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z"))
- != (int)EOF) {
+ while ((opt = getopt(argc, argv,
+ "vcd:HmaRLtu:U:n:p:C:P:h:s:S:j:k:TJz:Z")) != (int)EOF) {
switch (opt) {
case 'R':
opts.o_outpmode |= OPT_REALTIME;
@@ -1332,6 +1367,18 @@ main(int argc, char **argv)
opts.o_outpmode &= ~OPT_TERMCAP;
opts.o_outpmode &= ~OPT_FULLSCREEN;
break;
+ case 'd':
+ if (optarg) {
+ if (*optarg == 'u')
+ opts.o_outpmode |= OPT_UDATE;
+ else if (*optarg == 'd')
+ opts.o_outpmode |= OPT_DDATE;
+ else
+ Usage();
+ } else {
+ Usage();
+ }
+ break;
case 'h':
fill_table(&lgr_tbl, optarg, 'h');
break;
@@ -1436,15 +1483,14 @@ main(int argc, char **argv)
"-a, -J, -T or -Z\n"));
if ((opts.o_outpmode & OPT_USERS) &&
- (opts.o_outpmode &
- (OPT_TASKS | OPT_PROJECTS | OPT_ZONES)))
+ (opts.o_outpmode & (OPT_TASKS | OPT_PROJECTS | OPT_ZONES)))
Die(gettext("-a option cannot be used with "
"-t, -J, -T or -Z\n"));
if (((opts.o_outpmode & OPT_TASKS) &&
(opts.o_outpmode & (OPT_PROJECTS|OPT_ZONES))) ||
((opts.o_outpmode & OPT_PROJECTS) &&
- (opts.o_outpmode & (OPT_TASKS|OPT_ZONES)))) {
+ (opts.o_outpmode & (OPT_TASKS|OPT_ZONES)))) {
Die(gettext(
"-J, -T and -Z options are mutually exclusive\n"));
}
@@ -1495,6 +1541,8 @@ main(int argc, char **argv)
Die(gettext("cannot open /proc directory\n"));
if (opts.o_outpmode & OPT_TTY) {
(void) printf(gettext("Please wait...\r"));
+ if (!(opts.o_outpmode & OPT_TERMCAP))
+ (void) putchar('\n');
(void) fflush(stdout);
}
set_signals();
diff --git a/usr/src/cmd/prstat/prstat.h b/usr/src/cmd/prstat/prstat.h
index d130164e7d..2b60b0b0fc 100644
--- a/usr/src/cmd/prstat/prstat.h
+++ b/usr/src/cmd/prstat/prstat.h
@@ -20,15 +20,13 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _PRSTAT_H
#define _PRSTAT_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/sysmacros.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -70,6 +68,8 @@ extern "C" {
#define OPT_ZONES 0x2000 /* report about zones */
#define OPT_PSETS 0x4000 /* report for specified psets */
#define OPT_LGRP 0x8000 /* report home lgroups */
+#define OPT_UDATE 0x20000 /* print unix timestamp */
+#define OPT_DDATE 0x40000 /* print timestamp in date(1) format */
/*
* Flags to keep track of process or lwp status
diff --git a/usr/src/cmd/prstat/prutil.c b/usr/src/cmd/prstat/prutil.c
index 8c0f99f138..f8484e30db 100644
--- a/usr/src/cmd/prstat/prutil.c
+++ b/usr/src/cmd/prstat/prutil.c
@@ -19,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/types.h>
#include <sys/param.h>
#include <sys/resource.h>
@@ -109,7 +107,7 @@ Usage()
"Usage:\tprstat [-acHJLmRtTvZ] [-u euidlist] [-U uidlist]\n"
"\t[-p pidlist] [-P cpulist] [-C psrsetlist] [-h lgrouplist]\n"
"\t[-j projidlist] [-k taskidlist] [-z zoneidlist]\n"
- "\t[-s key | -S key] [-n nprocs[,nusers]]\n"
+ "\t[-s key | -S key] [-n nprocs[,nusers]] [-d d|u]\n"
"\t[interval [counter]]\n"));
exit(1);
}
diff --git a/usr/src/cmd/stat/common/common.c b/usr/src/cmd/stat/common/common.c
index 713700d88b..0bf50b9d3b 100644
--- a/usr/src/cmd/stat/common/common.c
+++ b/usr/src/cmd/stat/common/common.c
@@ -19,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include "statcommon.h"
#include <stdarg.h>
@@ -32,10 +30,13 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <langinfo.h>
extern char *cmdname;
extern int caught_cont;
+uint_t timestamp_fmt = NODATE;
+
/*PRINTFLIKE2*/
void
fail(int do_perror, char *message, ...)
@@ -127,3 +128,29 @@ cont_handler(int sig_number)
(void) signal(sig_number, cont_handler);
caught_cont = 1;
}
+
+/*
+ * Print timestamp as decimal reprentation of time_t value (-T u was specified)
+ * or in date(1) format (-T d was specified).
+ */
+void
+print_timestamp(void)
+{
+ time_t t = time(NULL);
+ static char *fmt = NULL;
+
+ /* We only need to retrieve this once per invocation */
+ if (fmt == NULL)
+ fmt = nl_langinfo(_DATE_FMT);
+
+ if (timestamp_fmt == UDATE) {
+ (void) printf("%ld\n", t);
+ } else if (timestamp_fmt == DDATE) {
+ char dstr[64];
+ int len;
+
+ len = strftime(dstr, sizeof (dstr), fmt, localtime(&t));
+ if (len > 0)
+ (void) printf("%s\n", dstr);
+ }
+}
diff --git a/usr/src/cmd/stat/common/statcommon.h b/usr/src/cmd/stat/common/statcommon.h
index dacd0d3121..1efaacae1d 100644
--- a/usr/src/cmd/stat/common/statcommon.h
+++ b/usr/src/cmd/stat/common/statcommon.h
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Common routines for acquiring snapshots of kstats for
@@ -29,8 +29,6 @@
#ifndef _STATCOMMON_H
#define _STATCOMMON_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -60,6 +58,11 @@ extern "C" {
/* no limit to iodevs to collect */
#define UNLIMITED_IODEVS ((size_t)-1)
+#define NODATE 0 /* Default: No time stamp */
+#define DDATE 1 /* Standard date format */
+#define UDATE 2 /* Internal representation of Unix time */
+
+
enum snapshot_types {
/* All CPUs separately */
SNAP_CPUS = 1 << 0,
@@ -320,6 +323,9 @@ void sleep_until(hrtime_t *wakeup, hrtime_t interval, int forever,
/* signal handler - so we can be aware of SIGCONT */
void cont_handler(int sig_number);
+/* Print a timestamp in either Unix or standard format. */
+void print_timestamp(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/usr/src/cmd/stat/fsstat/fsstat.c b/usr/src/cmd/stat/fsstat/fsstat.c
index d42d3c1442..5eb35f5e5b 100644
--- a/usr/src/cmd/stat/fsstat/fsstat.c
+++ b/usr/src/cmd/stat/fsstat/fsstat.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -32,7 +32,6 @@
#include <limits.h>
#include <sys/types.h>
#include <time.h>
-#include <langinfo.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/vnode.h>
@@ -118,6 +117,8 @@ static char units[] = "num KMGTPE";
char *cmdname; /* name of this command */
int caught_cont = 0; /* have caught a SIGCONT */
+extern uint_t timestamp_fmt; /* print timestamp with stats */
+
static int vs_i = 0; /* Index of current vs[] slot */
static void
@@ -824,32 +825,6 @@ set_ksnames(entity_t *entities, int nentities, char **fstypes, int nfstypes)
}
}
-void
-print_time(int type)
-{
- time_t t;
- static char *fmt = NULL; /* Time format */
-
- /* We only need to retrieve this once per invocation */
- if (fmt == NULL) {
- fmt = nl_langinfo(_DATE_FMT);
- }
-
- if (time(&t) != -1) {
- if (type == UDATE) {
- (void) printf("%ld\n", t);
- } else if (type == DDATE) {
- char dstr[64];
- int len;
-
- len = strftime(dstr, sizeof (dstr), fmt, localtime(&t));
- if (len > 0) {
- (void) printf("%s\n", dstr);
- }
- }
- }
-}
-
/*
* The idea is that 'dspfunc' should only be modified from the default
* once since the display options are mutually exclusive. If 'dspfunc'
@@ -876,11 +851,10 @@ main(int argc, char *argv[])
int c;
int i, j; /* Generic counters */
int nentities_found;
- int linesout; /* Keeps track of lines printed */
+ int linesout = 0; /* Keeps track of lines printed */
int printhdr = 0; /* Print a header? 0 = no, 1 = yes */
int nfstypes; /* Number of fstypes */
int dispflag = 0; /* Flags for display control */
- int timestamp = NODATE; /* Default: no time stamp */
long count = 0; /* Number of iterations for display */
int forever; /* Run forever */
long interval = 0;
@@ -925,14 +899,14 @@ main(int argc, char *argv[])
case 'T': /* Timestamp */
if (optarg) {
if (strcmp(optarg, "u") == 0) {
- timestamp = UDATE;
+ timestamp_fmt = UDATE;
} else if (strcmp(optarg, "d") == 0) {
- timestamp = DDATE;
+ timestamp_fmt = DDATE;
}
}
/* If it was never set properly... */
- if (timestamp == NODATE) {
+ if (timestamp_fmt == NODATE) {
(void) fprintf(stderr, gettext("%s: -T option "
"requires either 'u' or 'd'\n"), cmdname);
usage();
@@ -962,7 +936,7 @@ main(int argc, char *argv[])
}
#if PARSABLE_OUTPUT
- if ((dispflag & DISP_RAW) && (timestamp != NODATE)) {
+ if ((dispflag & DISP_RAW) && (timestamp_fmt != NODATE)) {
(void) fprintf(stderr, gettext(
"-P and -T options are mutually exclusive\n"));
usage();
@@ -1025,18 +999,24 @@ main(int argc, char *argv[])
/* Set start time */
start_n = gethrtime();
+ /* Initial timestamp */
+ if (timestamp_fmt != NODATE) {
+ print_timestamp();
+ linesout++;
+ }
+
/*
* The following loop walks through the entities[] list to "prime
* the pump"
*/
- for (j = 0, linesout = 0; j < nentities; j++) {
+ for (j = 0, printhdr = 1; j < nentities; j++) {
entity_t *ent = &entities[j];
vopstats_t *vsp = &ent->e_vs[CUR_INDEX];
kstat_t *ksp = NULL;
if (get_vopstats(kc, ent->e_ksname, vsp, &ksp) == 0) {
(*dfunc)(ent->e_name, NULL, vsp,
- dispflag_policy(linesout == 0, dispflag));
+ dispflag_policy(printhdr, dispflag));
linesout++;
} else {
/*
@@ -1057,6 +1037,7 @@ main(int argc, char *argv[])
entities[j].e_name);
}
}
+ printhdr = 0;
}
if (count > 1)
@@ -1080,8 +1061,8 @@ main(int argc, char *argv[])
/* Have a kip */
sleep_until(&start_n, period_n, forever, &caught_cont);
- if (timestamp) {
- print_time(timestamp);
+ if (timestamp_fmt != NODATE) {
+ print_timestamp();
linesout++;
}
diff --git a/usr/src/cmd/stat/iostat/iostat.c b/usr/src/cmd/stat/iostat/iostat.c
index 039834a90d..958c1b19d1 100644
--- a/usr/src/cmd/stat/iostat/iostat.c
+++ b/usr/src/cmd/stat/iostat/iostat.c
@@ -20,15 +20,13 @@
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* rewritten from UCB 4.13 83/09/25
* rewritten from SunOS 4.1 SID 1.18 89/10/06
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -46,6 +44,7 @@
#include <strings.h>
#include <sys/systeminfo.h>
#include <kstat.h>
+#include <locale.h>
#include "dsr.h"
#include "statcommon.h"
@@ -127,16 +126,10 @@ static uint_t do_conversions; /* display disks as cXtYdZ (-n) */
static uint_t do_megabytes; /* display data in MB/sec (-M) */
static uint_t do_controller; /* display controller info (-C) */
static uint_t do_raw; /* emit raw format (-r) */
-static uint_t do_timestamp; /* timestamp each display (-T) */
+extern uint_t timestamp_fmt; /* timestamp each display (-T) */
static uint_t do_devid; /* -E should show devid */
/*
- * Definition of allowable types of timestamps
- */
-#define CDATE 1
-#define UDATE 2
-
-/*
* Default number of disk drives to be displayed in basic format
*/
#define DEFAULT_LIMIT 4
@@ -173,7 +166,6 @@ static format_t *formatter_end;
static u_longlong_t ull_delta(u_longlong_t, u_longlong_t);
static uint_t u32_delta(uint_t, uint_t);
static void setup(void (*nfunc)(void));
-static void print_timestamp(void);
static void print_tty_hdr1(void);
static void print_tty_hdr2(void);
static void print_cpu_hdr1(void);
@@ -209,6 +201,12 @@ main(int argc, char **argv)
hrtime_t start_n;
hrtime_t period_n;
+ (void) setlocale(LC_ALL, "");
+#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
+#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
do_args(argc, argv);
/*
@@ -1132,13 +1130,14 @@ do_args(int argc, char **argv)
case 'T':
if (optarg) {
if (*optarg == 'u')
- do_timestamp = UDATE;
+ timestamp_fmt = UDATE;
else if (*optarg == 'd')
- do_timestamp = CDATE;
+ timestamp_fmt = DDATE;
else
errflg++;
- } else
+ } else {
errflg++;
+ }
break;
case 'r':
do_raw = 1;
@@ -1357,7 +1356,7 @@ do_format(void)
dh_len = strlen(disk_header) - 2;
}
- if (do_timestamp)
+ if (timestamp_fmt != NODATE)
setup(print_timestamp);
/*
@@ -1674,33 +1673,6 @@ print_disk_header(void)
}
/*
- * Write out a timestamp. Format is all that goes out on
- * the line so no use of push_out.
- *
- * Write out as decimal reprentation of time_t value
- * (-T u was specified) or the string returned from
- * ctime() (-T d was specified).
- */
-static void
-print_timestamp(void)
-{
- time_t t;
-
- if (time(&t) != -1) {
- if (do_timestamp == UDATE) {
- (void) printf("%ld\n", t);
- } else if (do_timestamp == CDATE) {
- char *cpt;
-
- cpt = ctime(&t);
- if (cpt) {
- (void) fputs(cpt, stdout);
- }
- }
- }
-}
-
-/*
* No, UINTMAX_MAX isn't the right thing here since
* it is #defined to be either INT32_MAX or INT64_MAX
* depending on the whether _LP64 is defined.
diff --git a/usr/src/cmd/stat/mpstat/mpstat.c b/usr/src/cmd/stat/mpstat/mpstat.c
index c6b11fcd7f..320bc8be80 100644
--- a/usr/src/cmd/stat/mpstat/mpstat.c
+++ b/usr/src/cmd/stat/mpstat/mpstat.c
@@ -19,12 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/pset.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -44,6 +42,7 @@
#include <kstat.h>
#include <poll.h>
#include <signal.h>
+#include <locale.h>
#include "statcommon.h"
@@ -54,6 +53,8 @@
char *cmdname = "mpstat";
int caught_cont = 0;
+extern uint_t timestamp_fmt;
+
static int hz;
static int display_pset = -1;
static int show_set = 0;
@@ -79,7 +80,13 @@ main(int argc, char **argv)
hrtime_t start_n;
hrtime_t period_n;
- while ((c = getopt(argc, argv, "apP:q")) != (int)EOF)
+ (void) setlocale(LC_ALL, "");
+#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
+#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ while ((c = getopt(argc, argv, "apP:qT:")) != (int)EOF)
switch (c) {
case 'a':
/*
@@ -115,6 +122,18 @@ main(int argc, char **argv)
case 'q':
suppress_state = 1;
break;
+ case 'T':
+ if (optarg) {
+ if (*optarg == 'u')
+ timestamp_fmt = UDATE;
+ else if (*optarg == 'd')
+ timestamp_fmt = DDATE;
+ else
+ usage();
+ } else {
+ usage();
+ }
+ break;
case '?':
usage();
break;
@@ -231,26 +250,26 @@ print_cpu(struct cpu_snapshot *c1, struct cpu_snapshot *c2)
percent = 100.0 / etime / hz;
(void) printf("%3d %4.0f %3.0f %4.0f %5.0f %4.0f "
- "%4.0f %4.0f %4.0f %4.0f %4.0f %5.0f %3.0f %3.0f "
- "%3.0f %3.0f",
- c2->cs_id,
- (kstat_delta(old_vm, &c2->cs_vm, "hat_fault") +
- kstat_delta(old_vm, &c2->cs_vm, "as_fault")) / etime,
- kstat_delta(old_vm, &c2->cs_vm, "maj_fault") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "xcalls") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "intr") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "intrthread") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "pswitch") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "inv_swtch") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "cpumigrate") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "mutex_adenters") / etime,
- (kstat_delta(old_sys, &c2->cs_sys, "rw_rdfails") +
- kstat_delta(old_sys, &c2->cs_sys, "rw_wrfails")) / etime,
- kstat_delta(old_sys, &c2->cs_sys, "syscall") / etime,
- kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_user") * percent,
- kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_kernel") * percent,
- kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_wait") * percent,
- kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_idle") * percent);
+ "%4.0f %4.0f %4.0f %4.0f %4.0f %5.0f %3.0f %3.0f "
+ "%3.0f %3.0f",
+ c2->cs_id,
+ (kstat_delta(old_vm, &c2->cs_vm, "hat_fault") +
+ kstat_delta(old_vm, &c2->cs_vm, "as_fault")) / etime,
+ kstat_delta(old_vm, &c2->cs_vm, "maj_fault") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "xcalls") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "intr") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "intrthread") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "pswitch") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "inv_swtch") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "cpumigrate") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "mutex_adenters") / etime,
+ (kstat_delta(old_sys, &c2->cs_sys, "rw_rdfails") +
+ kstat_delta(old_sys, &c2->cs_sys, "rw_wrfails")) / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "syscall") / etime,
+ kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_user") * percent,
+ kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_kernel") * percent,
+ kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_wait") * percent,
+ kstat_delta(old_sys, &c2->cs_sys, "cpu_ticks_idle") * percent);
if (show_set)
(void) printf(" %3d", c2->cs_pset_id);
@@ -417,27 +436,27 @@ print_pset(struct pset_snapshot *p1, struct pset_snapshot *p2)
percent = 100.0 / p2->ps_nr_cpus / etime / hz;
(void) printf("%3d %4.0f %3.0f %4.0f %5.0f %4.0f "
- "%4.0f %4.0f %4.0f %4.0f %4.0f %5.0f %3.0f %3.0f "
- "%3.0f %3.0f %3d\n",
- p2->ps_id,
- (kstat_delta(&old_vm, &new_vm, "hat_fault") +
- kstat_delta(&old_vm, &new_vm, "as_fault")) / etime,
- kstat_delta(&old_vm, &new_vm, "maj_fault") / etime,
- kstat_delta(&old_sys, &new_sys, "xcalls") / etime,
- kstat_delta(&old_sys, &new_sys, "intr") / etime,
- kstat_delta(&old_sys, &new_sys, "intrthread") / etime,
- kstat_delta(&old_sys, &new_sys, "pswitch") / etime,
- kstat_delta(&old_sys, &new_sys, "inv_swtch") / etime,
- kstat_delta(&old_sys, &new_sys, "cpumigrate") / etime,
- kstat_delta(&old_sys, &new_sys, "mutex_adenters") / etime,
- (kstat_delta(&old_sys, &new_sys, "rw_rdfails") +
- kstat_delta(&old_sys, &new_sys, "rw_wrfails")) / etime,
- kstat_delta(&old_sys, &new_sys, "syscall") / etime,
- kstat_delta(&old_sys, &new_sys, "cpu_ticks_user") * percent,
- kstat_delta(&old_sys, &new_sys, "cpu_ticks_kernel") * percent,
- kstat_delta(&old_sys, &new_sys, "cpu_ticks_wait") * percent,
- kstat_delta(&old_sys, &new_sys, "cpu_ticks_idle") * percent,
- p2->ps_nr_cpus);
+ "%4.0f %4.0f %4.0f %4.0f %4.0f %5.0f %3.0f %3.0f "
+ "%3.0f %3.0f %3d\n",
+ p2->ps_id,
+ (kstat_delta(&old_vm, &new_vm, "hat_fault") +
+ kstat_delta(&old_vm, &new_vm, "as_fault")) / etime,
+ kstat_delta(&old_vm, &new_vm, "maj_fault") / etime,
+ kstat_delta(&old_sys, &new_sys, "xcalls") / etime,
+ kstat_delta(&old_sys, &new_sys, "intr") / etime,
+ kstat_delta(&old_sys, &new_sys, "intrthread") / etime,
+ kstat_delta(&old_sys, &new_sys, "pswitch") / etime,
+ kstat_delta(&old_sys, &new_sys, "inv_swtch") / etime,
+ kstat_delta(&old_sys, &new_sys, "cpumigrate") / etime,
+ kstat_delta(&old_sys, &new_sys, "mutex_adenters") / etime,
+ (kstat_delta(&old_sys, &new_sys, "rw_rdfails") +
+ kstat_delta(&old_sys, &new_sys, "rw_wrfails")) / etime,
+ kstat_delta(&old_sys, &new_sys, "syscall") / etime,
+ kstat_delta(&old_sys, &new_sys, "cpu_ticks_user") * percent,
+ kstat_delta(&old_sys, &new_sys, "cpu_ticks_kernel") * percent,
+ kstat_delta(&old_sys, &new_sys, "cpu_ticks_wait") * percent,
+ kstat_delta(&old_sys, &new_sys, "cpu_ticks_idle") * percent,
+ p2->ps_nr_cpus);
out:
free(old_vm.ks_data);
@@ -470,6 +489,9 @@ show_cpu_usage(struct snapshot *old, struct snapshot *new, int display_agg)
enum snapshot_types type = SNAP_CPUS;
snapshot_cb cb = compare_cpu;
+ if (timestamp_fmt != NODATE)
+ print_timestamp();
+
if (lines_until_reprint == 0 || nr_active_cpus(new) > 1) {
print_header(display_agg, show_set);
lines_until_reprint = REPRINT;
@@ -494,6 +516,7 @@ static void
usage(void)
{
(void) fprintf(stderr,
- "Usage: mpstat [-aq] [-p | -P processor_set] [interval [count]]\n");
+ "Usage: mpstat [-aq] [-p | -P processor_set] [-T d|u] "
+ "[interval [count]]\n");
exit(1);
}
diff --git a/usr/src/cmd/stat/vmstat/vmstat.c b/usr/src/cmd/stat/vmstat/vmstat.c
index dfdaf0a656..0b576d1ece 100644
--- a/usr/src/cmd/stat/vmstat/vmstat.c
+++ b/usr/src/cmd/stat/vmstat/vmstat.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -9,8 +9,6 @@
* specifies the terms and conditions for redistribution.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/* from UCB 5.4 5/17/86 */
/* from SunOS 4.1, SID 1.31 */
@@ -26,12 +24,15 @@
#include <signal.h>
#include <values.h>
#include <poll.h>
+#include <locale.h>
#include "statcommon.h"
char *cmdname = "vmstat";
int caught_cont = 0;
+extern uint_t timestamp_fmt;
+
static int hz;
static int pagesize;
static double etime;
@@ -65,40 +66,55 @@ main(int argc, char **argv)
kstat_ctl_t *kc;
int forever = 0;
hrtime_t start_n;
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
+#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
+#endif
+ (void) textdomain(TEXT_DOMAIN);
pagesize = sysconf(_SC_PAGESIZE);
hz = sysconf(_SC_CLK_TCK);
- argc--, argv++;
- while (argc > 0 && argv[0][0] == '-') {
- char *cp = *argv++;
- argc--;
- while (*++cp) {
- switch (*cp) {
-
- case 'S':
- swflag = !swflag;
- 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;
- default:
+ while ((c = getopt(argc, argv, "cipqsST:")) != EOF)
+ switch (c) {
+ case 'S':
+ swflag = !swflag;
+ 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')
+ timestamp_fmt = UDATE;
+ else if (*optarg == 'd')
+ timestamp_fmt = DDATE;
+ else
+ usage();
+ } else {
usage();
}
+ break;
+ default:
+ usage();
}
- }
+
+ argc -= optind;
+ argv += optind;
/* consistency with iostat */
types |= SNAP_CPUS;
@@ -118,7 +134,7 @@ main(int argc, char **argv)
(void) memset(df.if_names, 0, df.if_max_iodevs * sizeof (char *));
while (argc > 0 && !isdigit(argv[0][0]) &&
- df.if_nr_names < df.if_max_iodevs) {
+ df.if_nr_names < df.if_max_iodevs) {
df.if_names[df.if_nr_names] = *argv;
df.if_nr_names++;
argc--, argv++;
@@ -176,7 +192,6 @@ main(int argc, char **argv)
(void) sigset(SIGCONT, printhdr);
- printhdr(0);
dovmstats(old, ss);
while (forever || --iter > 0) {
/* (void) poll(NULL, 0, poll_interval); */
@@ -263,7 +278,12 @@ dovmstats(struct snapshot *old, struct snapshot *new)
etime = etime >= 1.0 ? (etime / nr_active_cpus(new)) / hz : 1.0;
updates = denom(DELTA(s_sys.ss_sysinfo.updates));
- if (--lines == 0)
+ if (timestamp_fmt != NODATE) {
+ print_timestamp();
+ lines--;
+ }
+
+ if (--lines <= 0)
printhdr(0);
adj = 0;
@@ -310,7 +330,7 @@ dovmstats(struct snapshot *old, struct snapshot *new)
adjprintf(" %*u", 6, pgtok((int)(DELTA(s_sys.ss_vminfo.swap_avail)
/ updates)));
adjprintf(" %*u", 5, pgtok((int)(DELTA(s_sys.ss_vminfo.freemem)
- / updates)));
+ / updates)));
adjprintf(" %*.0f", 3, swflag?
kstat_delta(oldvm, newvm, "swapin") / etime :
kstat_delta(oldvm, newvm, "pgrec") / etime);
@@ -400,7 +420,7 @@ sum_out(char const *pretty, kstat_t *ks, char *name)
kstat_named_t *ksn = kstat_data_lookup(ks, name);
if (ksn == NULL) {
fail(0, "kstat_data_lookup('%s', '%s') failed",
- ks->ks_name, name);
+ ks->ks_name, name);
}
(void) printf("%9llu %s\n", ksn->value.ui64, pretty);
@@ -422,18 +442,18 @@ dosum(struct sys_snapshot *ss)
ksn = kstat_data_lookup(&ss->ss_agg_vm, "hat_fault");
if (ksn == NULL) {
fail(0, "kstat_data_lookup('%s', 'hat_fault') failed",
- ss->ss_agg_vm.ks_name);
+ ss->ss_agg_vm.ks_name);
}
total_faults = ksn->value.ui64;
ksn = kstat_data_lookup(&ss->ss_agg_vm, "as_fault");
if (ksn == NULL) {
fail(0, "kstat_data_lookup('%s', 'as_fault') failed",
- ss->ss_agg_vm.ks_name);
+ ss->ss_agg_vm.ks_name);
}
total_faults += ksn->value.ui64;
(void) printf("%9llu total address trans. faults taken\n",
- total_faults);
+ total_faults);
sum_out("page ins", &ss->ss_agg_vm, "pgin");
sum_out("page outs", &ss->ss_agg_vm, "pgout");
@@ -480,8 +500,8 @@ dointr(struct snapshot *ss)
for (i = 0; i < ss->s_nr_intrs; i++) {
(void) printf("%-12.8s %10lu %8.0f\n",
- ss->s_intrs[i].is_name, ss->s_intrs[i].is_total,
- ss->s_intrs[i].is_total / etime);
+ ss->s_intrs[i].is_name, ss->s_intrs[i].is_total,
+ ss->s_intrs[i].is_total / etime);
total += ss->s_intrs[i].is_total;
}
@@ -503,11 +523,11 @@ docachestats(kstat_ctl_t *kc, hrtime_t interval, int forever)
if (iter == 0) {
(void) printf("flush statistics: (totals)\n");
(void) printf("%8s%8s%8s%8s%8s%8s\n",
- "usr", "ctx", "rgn", "seg", "pag", "par");
+ "usr", "ctx", "rgn", "seg", "pag", "par");
(void) printf(" %7d %7d %7d %7d %7d %7d\n",
- old->s_flushes.f_usr, old->s_flushes.f_ctx,
- old->s_flushes.f_region, old->s_flushes.f_segment,
- old->s_flushes.f_page, old->s_flushes.f_partial);
+ old->s_flushes.f_usr, old->s_flushes.f_ctx,
+ old->s_flushes.f_region, old->s_flushes.f_segment,
+ old->s_flushes.f_page, old->s_flushes.f_partial);
return;
}
@@ -523,12 +543,12 @@ docachestats(kstat_ctl_t *kc, hrtime_t interval, int forever)
new = acquire_snapshot(kc, SNAP_FLUSHES, NULL);
(void) printf(" %7d %7d %7d %7d %7d %7d\n",
- new->s_flushes.f_usr - old->s_flushes.f_usr,
- new->s_flushes.f_ctx - old->s_flushes.f_ctx,
- new->s_flushes.f_region - old->s_flushes.f_region,
- new->s_flushes.f_segment - old->s_flushes.f_segment,
- new->s_flushes.f_page - old->s_flushes.f_page,
- new->s_flushes.f_partial- old->s_flushes.f_partial);
+ new->s_flushes.f_usr - old->s_flushes.f_usr,
+ new->s_flushes.f_ctx - old->s_flushes.f_ctx,
+ new->s_flushes.f_region - old->s_flushes.f_region,
+ new->s_flushes.f_segment - old->s_flushes.f_segment,
+ new->s_flushes.f_page - old->s_flushes.f_page,
+ new->s_flushes.f_partial- old->s_flushes.f_partial);
(void) fflush(stdout);
free_snapshot(old);
old = new;
@@ -539,6 +559,7 @@ static void
usage(void)
{
(void) fprintf(stderr,
- "Usage: vmstat [-cipqsS] [disk ...] [interval [count]]\n");
+ "Usage: vmstat [-cipqsS] [-T d|u] [disk ...] "
+ "[interval [count]]\n");
exit(1);
}