diff options
31 files changed, 543 insertions, 192 deletions
diff --git a/usr/src/cmd/auditstat/Makefile b/usr/src/cmd/auditstat/Makefile index a1b8cf39ac..232a01693e 100644 --- a/usr/src/cmd/auditstat/Makefile +++ b/usr/src/cmd/auditstat/Makefile @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,25 +19,41 @@ # CDDL HEADER END # # -# Copyright 1992, 2002 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# PROG= auditstat +OBJS = auditstat.o +SRCS = $(OBJS:%.o=%.c) include ../Makefile.cmd include ../Makefile.cmd.bsm -LDLIBS += -lbsm +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +SRCS += $(STAT_COMMON_SRCS) + +LDLIBS += -lbsm +CPPFLAGS += -I$(STATCOMMONDIR) .KEEP_STATE: all: $(PROG) +$(PROG): $(OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) -o $(PROG) $(OBJS) $(STAT_COMMON_OBJS) $(LDLIBS) + $(POST_PROCESS) + +%.o: $(STATCOMMONDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + clean: + -$(RM) $(OBJS) $(STAT_COMMON_OBJS) -lint: lint_PROG +lint: lint_SRCS include ../Makefile.targ diff --git a/usr/src/cmd/auditstat/auditstat.c b/usr/src/cmd/auditstat/auditstat.c index 26cbd74d6f..594ba8e16a 100644 --- a/usr/src/cmd/auditstat/auditstat.c +++ b/usr/src/cmd/auditstat/auditstat.c @@ -19,11 +19,11 @@ * 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 <sys/types.h> #include <stdlib.h> @@ -32,6 +32,12 @@ #include <bsm/audit.h> #include <bsm/libbsm.h> #include <unistd.h> +#include <locale.h> + +#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ +#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */ +#endif + /* * Display header every HEADER_MOD lines printed @@ -51,6 +57,7 @@ static int count; static int flags; static int header_mod = DFLT_HEADER_MOD; static int interval; +static uint_t timestamp_fmt = NODATE; static void display_stats(); static void eauditon(); @@ -66,6 +73,9 @@ char **argv; register int i; au_stat_t s; + (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); + (void) setbuf(stdout, (char *)0); (void) setbuf(stderr, (char *)0); @@ -73,6 +83,8 @@ char **argv; if (!flags) { eauditon(A_GETSTAT, (caddr_t)&s, NULL); + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); display_stats(&s, 0); exit(0); } @@ -92,6 +104,8 @@ char **argv; /* CSTYLED */ for (i = 0;; i++) { eauditon(A_GETSTAT, (caddr_t)&s, NULL); + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); display_stats(&s, i); if ((flags & CFLG) && count) if (i == count - 1) @@ -126,7 +140,8 @@ au_stat_t *s; s->as_memused / ONEK, &(offset[11])); /* print a properly aligned header every HEADER_MOD lines */ - if (header_mod && (!cnt || !(cnt % header_mod))) { + if (header_mod && (!cnt || ((timestamp_fmt != NODATE) ? + !(cnt % (header_mod / 2)) : !(cnt % header_mod)))) { (void) printf( "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n", offset[0] - 1, "gen", @@ -167,7 +182,7 @@ char **argv; { int c; - while ((c = getopt(argc, argv, "c:h:i:vn")) != -1) { + while ((c = getopt(argc, argv, "c:h:i:vnT:")) != -1) { switch (c) { case 'c': if (flags & CFLG) @@ -212,6 +227,18 @@ char **argv; usage_exit(); flags |= VFLG; break; + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage_exit(); + } else { + usage_exit(); + } + break; case '?': default: usage_exit(); @@ -226,7 +253,7 @@ usage_exit() { (void) fprintf(stderr, "auditstat: usage: auditstat [-c count] [-h lines] " - "[-i interval] [-n] [-v]\n"); + "[-T d|u] [-i interval] [-n] [-v]\n"); exit(1); } diff --git a/usr/src/cmd/cmd-inet/usr.bin/netstat/Makefile b/usr/src/cmd/cmd-inet/usr.bin/netstat/Makefile index f8a34d2f01..47d36f1c36 100644 --- a/usr/src/cmd/cmd-inet/usr.bin/netstat/Makefile +++ b/usr/src/cmd/cmd-inet/usr.bin/netstat/Makefile @@ -19,11 +19,9 @@ # 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. # -# ident "%Z%%M% %I% %E% SMI" -# # Copyright (c) 1990 Mentat Inc. # # cmd/cmd-inet/usr.bin/netstat/Makefile @@ -32,16 +30,22 @@ PROG= netstat LOCALOBJS= netstat.o unix.o COMMONOBJS= compat.o -OBJS= $(LOCALOBJS) $(COMMONOBJS) include ../../../Makefile.cmd include ../../Makefile.cmd-inet LOCALSRCS= $(LOCALOBJS:%.o=%.c) COMMONSRCS= $(CMDINETCOMMONDIR)/$(COMMONOBJS:%.o=%.c) -SRCS= $(LOCALSRCS) $(COMMONSRCS) -CPPFLAGS += -DNDEBUG -I$(CMDINETCOMMONDIR) +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) + +OBJS= $(LOCALOBJS) $(COMMONOBJS) $(STAT_COMMON_OBJS) +SRCS= $(LOCALSRCS) $(COMMONSRCS) $(STAT_COMMON_SRCS) + +CPPFLAGS += -DNDEBUG -I$(CMDINETCOMMONDIR) -I$(STATCOMMONDIR) LDLIBS += -ldhcpagent -lsocket -lnsl -lkstat -ltsnet -ltsol .KEEP_STATE: @@ -54,6 +58,10 @@ $(PROG): $(OBJS) $(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) +%.o : $(STATCOMMONDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + install: all $(ROOTPROG) clean: diff --git a/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c b/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c index 98fd04ba3d..a347255b81 100644 --- a/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c +++ b/usr/src/cmd/cmd-inet/usr.bin/netstat/netstat.c @@ -58,6 +58,7 @@ #include <ctype.h> #include <kstat.h> #include <assert.h> +#include <locale.h> #include <sys/types.h> #include <sys/stream.h> @@ -92,6 +93,8 @@ #include <libtsnet.h> #include <tsol/label.h> +#include "statcommon.h" + extern void unixpr(kstat_ctl_t *kc); #define STR_EXPAND 4 @@ -211,7 +214,6 @@ static void sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, static void m_report(void); static void dhcp_report(char *); - void fail(int, char *, ...); static uint64_t kstat_named_value(kstat_t *, char *); static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *); static int isnum(char *); @@ -335,6 +337,12 @@ struct filter_rule { */ static filter_t *filters[NFILTERKEYS]; +static uint_t timestamp_fmt = NODATE; + +#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ +#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */ +#endif + int main(int argc, char **argv) { @@ -368,7 +376,10 @@ main(int argc, char **argv) default_ip_str, DEFAULT_IP, INET_DEFAULT_FILE); free(default_ip_str); - while ((c = getopt(argc, argv, "adimnrspMgvf:P:I:DR")) != -1) { + (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); + + while ((c = getopt(argc, argv, "adimnrspMgvf:P:I:DRT:")) != -1) { switch ((char)c) { case 'a': /* all connections */ Aflag = B_TRUE; @@ -471,6 +482,19 @@ main(int argc, char **argv) Iflag_only = 0; break; + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage(name); + } else { + usage(name); + } + break; + case '?': default: usage(name); @@ -566,6 +590,9 @@ main(int argc, char **argv) for (;;) { mib_item_t *curritem = NULL; /* only for -[M]s */ + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); + /* netstat: AF_INET[6] behaviour */ if (family_selected(AF_INET) || family_selected(AF_INET6)) { if (Sflag) { @@ -3348,6 +3375,9 @@ dhcp_do_ipc(dhcp_ipc_type_t type, const char *ifname, boolean_t printed_one) fail(0, "dhcp_do_ipc: %s", dhcp_ipc_strerror(error)); } + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); + if (!printed_one) (void) printf("%s", dhcp_status_hdr_string()); @@ -6225,20 +6255,21 @@ ifindex2str(uint_t ifindex, char *ifname) static void usage(char *cmdname) { - (void) fprintf(stderr, "usage: %s [-anv] [-f address_family]\n", - cmdname); + (void) fprintf(stderr, "usage: %s [-anv] [-f address_family] " + "[-T d|u]\n", cmdname); (void) fprintf(stderr, " %s [-n] [-f address_family] " - "[-P protocol] [-g | -p | -s [interval [count]]]\n", cmdname); - (void) fprintf(stderr, " %s -m [-v] " + "[-P protocol] [-T d|u] [-g | -p | -s [interval [count]]]\n", + cmdname); + (void) fprintf(stderr, " %s -m [-v] [-T d|u] " "[interval [count]]\n", cmdname); (void) fprintf(stderr, " %s -i [-I interface] [-an] " - "[-f address_family] [interval [count]]\n", cmdname); + "[-f address_family] [-T d|u] [interval [count]]\n", cmdname); (void) fprintf(stderr, " %s -r [-anv] " - "[-f address_family|filter]\n", cmdname); - (void) fprintf(stderr, " %s -M [-ns] [-f address_family]\n", - cmdname); + "[-f address_family|filter] [-T d|u]\n", cmdname); + (void) fprintf(stderr, " %s -M [-ns] [-f address_family] " + "[-T d|u]\n", cmdname); (void) fprintf(stderr, " %s -D [-I interface] " - "[-f address_family]\n", cmdname); + "[-f address_family] [-T d|u]\n", cmdname); exit(EXIT_FAILURE); } diff --git a/usr/src/cmd/cpc/common/cpustat.c b/usr/src/cmd/cpc/common/cpustat.c index 0fe4549b1d..8d405bb625 100644 --- a/usr/src/cmd/cpc/common/cpustat.c +++ b/usr/src/cmd/cpc/common/cpustat.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/processor.h> #include <sys/pset.h> @@ -49,6 +47,7 @@ #include <sys/resource.h> #include "cpucmds.h" +#include "statcommon.h" static struct options { int debug; @@ -93,6 +92,8 @@ static int *chip_designees; /* cpuid of CPU which counts for phs chip */ static int smt = 0; /* If set, cpustat needs to be SMT-aware. */ static pcinfo_t fxinfo = { 0, "FX", NULL }; /* FX scheduler class info */ +static uint_t timestamp_fmt = NODATE; + /*ARGSUSED*/ static void cpustat_errfn(const char *fn, int subcode, const char *fmt, va_list ap) @@ -136,8 +137,8 @@ main(int argc, char *argv[]) if (setrlimit(RLIMIT_NOFILE, &rl) != 0) { errstr = strerror(errno); (void) fprintf(stderr, - gettext("%s: setrlimit failed - %s\n"), - opts->pgmname, errstr); + gettext("%s: setrlimit failed - %s\n"), + opts->pgmname, errstr); } if ((cpc = cpc_open(CPC_VER_CURRENT)) == NULL) { @@ -167,7 +168,7 @@ main(int argc, char *argv[]) return (1); } - while ((c = getopt(argc, argv, "Dc:hntsp:")) != EOF && errcnt == 0) + while ((c = getopt(argc, argv, "Dc:hntT:sp:")) != EOF && errcnt == 0) switch (c) { case 'D': /* enable debugging */ opts->debug++; @@ -196,6 +197,18 @@ main(int argc, char *argv[]) case 't': /* print %tick */ opts->dotick = 1; break; + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + errcnt++; + } else { + errcnt++; + } + break; case 'h': /* help */ opts->dohelp = 1; break; @@ -239,12 +252,14 @@ main(int argc, char *argv[]) (opts->nsets = cpc_setgrp_numsets(opts->master)) == 0) { (void) fprintf(opts->dohelp ? stdout : stderr, gettext( "Usage:\n\t%s [-c events] [-p period] [-nstD] " - "[interval [count]]\n\n" + "[-T d|u] [interval [count]]\n\n" "\t-c events specify processor events to be monitored\n" "\t-n\t suppress titles\n" "\t-p period cycle through event list periodically\n" "\t-s\t run user soaker thread for system-only events\n" "\t-t\t include %s register\n" + "\t-T d|u\t Display a timestamp in date (d) or unix " + "time_t (u)\n" "\t-D\t enable debug mode\n" "\t-h\t print extended usage information\n\n" "\tUse cputrack(1) to monitor per-process statistics.\n"), @@ -347,6 +362,8 @@ print_sample(processorid_t cpuid, cpc_buf_t *buf, int nreq, const char *setname, } } + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); if (ccnt > sizeof (line)) ccnt = sizeof (line); if (ccnt > 0) @@ -513,7 +530,7 @@ gtick(void *arg) * If periodic behavior was requested, rest here. */ if (opts->doperiod && opts->mseconds_rest > 0 && - (sample_cnt % opts->nsets) == 0) { + (sample_cnt % opts->nsets) == 0) { /* * Stop the soaker while the tool rests. */ @@ -609,7 +626,7 @@ cpustat(void) max_chip_id = sysconf(_SC_CPUID_MAX); if ((chip_designees = malloc(max_chip_id * sizeof (int))) == NULL) { (void) fprintf(stderr, gettext( - "%s: out of heap\n"), opts->pgmname); + "%s: out of heap\n"), opts->pgmname); return (1); } for (i = 0; i < max_chip_id; i++) @@ -618,16 +635,16 @@ cpustat(void) if (smt) { if ((kc = kstat_open()) == NULL) { (void) fprintf(stderr, gettext( - "%s: kstat_open() failed: %s\n"), opts->pgmname, + "%s: kstat_open() failed: %s\n"), opts->pgmname, strerror(errno)); - return (1); + return (1); } } if (opts->dosoaker) if (priocntl(0, 0, PC_GETCID, &fxinfo) == -1) { (void) fprintf(stderr, gettext( - "%s: couldn't get FX scheduler class: %s\n"), + "%s: couldn't get FX scheduler class: %s\n"), opts->pgmname, strerror(errno)); return (1); } diff --git a/usr/src/cmd/cpc/cpustat/Makefile b/usr/src/cmd/cpc/cpustat/Makefile index 1c0b06524b..bddb25db49 100644 --- a/usr/src/cmd/cpc/cpustat/Makefile +++ b/usr/src/cmd/cpc/cpustat/Makefile @@ -19,11 +19,9 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" -# PROG = cpustat OBJS = $(PROG).o caps.o time.o setgrp.o strtoset.o @@ -31,23 +29,29 @@ SRCS = $(OBJS:%.o=../common/%.c) include ../../Makefile.cmd +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +SRCS += $(STAT_COMMON_SRCS) + CFLAGS += $(CCVERBOSE) $(CTF_FLAGS) -CPPFLAGS += -D_REENTRANT -I$(SRC)/lib/libcpc/common +CPPFLAGS += -D_REENTRANT -I$(SRC)/lib/libcpc/common -I$(STATCOMMONDIR) LDLIBS += -lcpc -lkstat .KEEP_STATE: all: $(PROG) -$(PROG): $(OBJS) - $(LINK.c) $(OBJS) -o $@ $(LDLIBS) +$(PROG): $(OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) $(OBJS) $(STAT_COMMON_OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) - $(CTFMERGE) -L VERSION -o $@ $(OBJS) + $(CTFMERGE) -L VERSION -o $@ $(OBJS) $(STAT_COMMON_OBJS) install: all $(ROOTUSRSBINPROG) clean: - $(RM) $(OBJS) + $(RM) $(OBJS) $(STAT_COMMON_OBJS) lint: lint_SRCS @@ -58,6 +62,10 @@ strip: all $(COMPILE.c) $< $(CTFCONVERT_O) +%.o: $(STATCOMMONDIR)/%.c + $(COMPILE.c) $< + $(CTFCONVERT_O) + POFILES = ../common/$(PROG).po ../common/caps.po POFILE = $(PROG)_cmd.po diff --git a/usr/src/cmd/ctstat/Makefile b/usr/src/cmd/ctstat/Makefile index 300f5dd395..8f84632dc6 100644 --- a/usr/src/cmd/ctstat/Makefile +++ b/usr/src/cmd/ctstat/Makefile @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,16 +19,23 @@ # CDDL HEADER END # # -# Copyright 2004 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" - PROG= ctstat +OBJS = ctstat.o +SRCS = $(OBJS:%.o=%.c) include ../Makefile.cmd +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +SRCS += $(STAT_COMMON_SRCS) + +CPPFLAGS += -I$(STATCOMMONDIR) CFLAGS += -v LDLIBS += -lcontract -luutil @@ -37,10 +43,19 @@ LDLIBS += -lcontract -luutil all: $(PROG) +$(PROG): $(OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) -o $(PROG) $(OBJS) $(STAT_COMMON_OBJS) $(LDLIBS) + $(POST_PROCESS) + +%.o : $(STATCOMMONDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + install: all $(ROOTPROG) clean: + $(RM) $(OBJS) $(STAT_COMMON_OBJS) -lint: lint_PROG +lint: lint_SRCS include ../Makefile.targ diff --git a/usr/src/cmd/ctstat/ctstat.c b/usr/src/cmd/ctstat/ctstat.c index 5f174195c4..5893a65118 100644 --- a/usr/src/cmd/ctstat/ctstat.c +++ b/usr/src/cmd/ctstat/ctstat.c @@ -19,12 +19,10 @@ * 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. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/types.h> #include <sys/ctfs.h> #include <stdio.h> @@ -43,6 +41,10 @@ #include <locale.h> #include <langinfo.h> +#include "statcommon.h" + +static uint_t timestamp_fmt = NODATE; + static int opt_verbose = 0; static int opt_showall = 0; @@ -55,7 +57,7 @@ static void usage(void) { (void) fprintf(stderr, gettext("Usage: %s [-a] [-i ctidlist] " - "[-t typelist] [-v] [interval [count]]\n"), uu_getpname()); + "[-t typelist] [-T d|u] [-v] [interval [count]]\n"), uu_getpname()); exit(UU_EXIT_USAGE); } @@ -770,7 +772,7 @@ main(int argc, char **argv) (void) uu_setpname(argv[0]); - while ((s = getopt(argc, argv, "ai:t:v")) != EOF) { + while ((s = getopt(argc, argv, "ai:T:t:v")) != EOF) { switch (s) { case 'a': opt_showall = 1; @@ -778,6 +780,18 @@ main(int argc, char **argv) case 'i': nids = parse_ids(optarg, (int **)&ids, nids); break; + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage(); + } else { + usage(); + } + break; case 't': ntypes = parse_types(optarg, &types, ntypes); break; @@ -814,6 +828,8 @@ main(int argc, char **argv) for (i = 0; count == 0 || i < count; i++) { if (i) (void) sleep(interval); + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); print_header(); if (nids && ntypes) scan_all(types, ntypes, ids, nids); diff --git a/usr/src/cmd/fm/fmstat/Makefile.com b/usr/src/cmd/fm/fmstat/Makefile.com index 5413b919f1..0c743f8108 100644 --- a/usr/src/cmd/fm/fmstat/Makefile.com +++ b/usr/src/cmd/fm/fmstat/Makefile.com @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,10 +19,9 @@ # CDDL HEADER END # # -# Copyright 2005 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -#ident "%Z%%M% %I% %E% SMI" .KEEP_STATE: .SUFFIXES: @@ -36,8 +34,14 @@ LINTFILES = $(SRCS:%.c=%.ln) PROG = fmstat ROOTPROG = $(ROOTUSRSBIN)/$(PROG) +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_LINTFILES = $(STAT_COMMON_OBJS:%.o=%.ln) +LINTFILES += $(STAT_LINTFILES) + $(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG -CPPFLAGS += -I. -I../common +CPPFLAGS += -I. -I../common -I$(STATCOMMONDIR) CFLAGS += $(CTF_FLAGS) $(CCVERBOSE) $(XSTRCONST) LDLIBS += -L$(ROOT)/usr/lib/fm -lfmd_adm LDFLAGS += -R/usr/lib/fm @@ -48,9 +52,9 @@ LINTFLAGS += -mnu all: $(PROG) -$(PROG): $(OBJS) - $(LINK.c) $(OBJS) -o $@ $(LDLIBS) - $(CTFMERGE) -L VERSION -o $@ $(OBJS) +$(PROG): $(OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) $(OBJS) $(STAT_COMMON_OBJS) -o $@ $(LDLIBS) + $(CTFMERGE) -L VERSION -o $@ $(OBJS) $(STAT_COMMON_OBJS) $(POST_PROCESS) %.o: ../common/%.c @@ -61,12 +65,19 @@ $(PROG): $(OBJS) $(COMPILE.c) $< $(CTFCONVERT_O) +%.o : $(STATCOMMONDIR)/%.c + $(COMPILE.c) $< + $(CTFCONVERT_O) + clean: - $(RM) $(OBJS) $(LINTFILES) + $(RM) $(OBJS) $(STAT_COMMON_OBJS) $(LINTFILES) clobber: clean $(RM) $(PROG) +%.ln: $(STATCOMMONDIR)/%.c + $(LINT.c) -c $< + %.ln: ../common/%.c $(LINT.c) -c $< diff --git a/usr/src/cmd/fm/fmstat/common/fmstat.c b/usr/src/cmd/fm/fmstat/common/fmstat.c index 07decee16f..adc14fe40b 100644 --- a/usr/src/cmd/fm/fmstat/common/fmstat.c +++ b/usr/src/cmd/fm/fmstat/common/fmstat.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -21,12 +20,10 @@ */ /* - * Copyright 2005 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 <fm/fmd_adm.h> #include <strings.h> @@ -36,6 +33,9 @@ #include <stdio.h> #include <errno.h> #include <poll.h> +#include <locale.h> + +#include "statcommon.h" #define FMSTAT_EXIT_SUCCESS 0 #define FMSTAT_EXIT_ERROR 1 @@ -110,6 +110,12 @@ static struct modstats { double m_pct_w; } *g_mods; +static uint_t timestamp_fmt = NODATE; + +#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ +#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */ +#endif + static void vwarn(const char *format, va_list ap) { @@ -672,10 +678,11 @@ static int usage(FILE *fp) { (void) fprintf(fp, "Usage: %s [-astTz] [-m module] " - "[-P prog] [interval [count]]\n\n", g_pname); + "[-P prog] [-d d|u] [interval [count]]\n\n", g_pname); (void) fprintf(fp, "\t-a show all statistics, including those kept by fmd\n" + "\t-d display a timestamp in date (d) or unix time_t (u)\n" "\t-m show module-specific statistics\n" "\t-P connect to alternate fmd program\n" "\t-s show module-specific serd engines\n" @@ -707,11 +714,26 @@ main(int argc, char *argv[]) else program = FMD_ADM_PROGRAM; - while ((c = getopt(argc, argv, "am:P:stTz")) != EOF) { + (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); + + while ((c = getopt(argc, argv, "ad:m:P:stTz")) != EOF) { switch (c) { case 'a': opt_a++; break; + case 'd': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + return (usage(stderr)); + } else { + return (usage(stderr)); + } + break; case 'm': opt_m = optarg; break; @@ -768,6 +790,8 @@ main(int argc, char *argv[]) die(NULL); /* fmd_adm_errmsg() has enough info */ while (iter < 0 || iter-- > 0) { + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); if (opt_s) stat_mod_serd(opt_m); else if (opt_T) diff --git a/usr/src/cmd/fs.d/nfs/nfsstat/Makefile b/usr/src/cmd/fs.d/nfs/nfsstat/Makefile index 8e3103e3c8..a5000c80c8 100644 --- a/usr/src/cmd/fs.d/nfs/nfsstat/Makefile +++ b/usr/src/cmd/fs.d/nfs/nfsstat/Makefile @@ -33,6 +33,14 @@ COMMON= nfs_sec.o OBJS= nfsstat.o $(COMMON) SRCS= nfsstat.c ../lib/nfs_sec.c +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +SRCS += $(STAT_COMMON_SRCS) +OBJS += $(STAT_COMMON_OBJS) + +CPPFLAGS += -I$(STATCOMMONDIR) LDLIBS += -lkstat -lnsl $(PROG): $(OBJS) @@ -48,6 +56,9 @@ all: $(PROG) nfs_sec.o: ../lib/nfs_sec.c $(COMPILE.c) ../lib/nfs_sec.c +%.o: $(STATCOMMONDIR)/%.c + $(COMPILE.c) $< + install: all $(ROOTPROG) lint: diff --git a/usr/src/cmd/fs.d/nfs/nfsstat/nfsstat.c b/usr/src/cmd/fs.d/nfs/nfsstat/nfsstat.c index 7015830673..195a2bb5d5 100644 --- a/usr/src/cmd/fs.d/nfs/nfsstat/nfsstat.c +++ b/usr/src/cmd/fs.d/nfs/nfsstat/nfsstat.c @@ -23,12 +23,10 @@ /* PROTOLIB1 */ /* - * Copyright 2008 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" - /* * nfsstat: Network File System statistics * @@ -65,7 +63,9 @@ #include <sys/time.h> #include <strings.h> #include <ctype.h> +#include <locale.h> +#include "statcommon.h" static kstat_ctl_t *kc = NULL; /* libkstat cookie */ static kstat_t *rpc_clts_client_kstat, *rpc_clts_server_kstat; @@ -97,14 +97,13 @@ static void sa_print(int, int); static void req_print(kstat_t *, kstat_t *, int, int, int); static void req_print_v4(kstat_t *, kstat_t *, int, int); static void stat_print(const char *, kstat_t *, kstat_t *, int, int); -static void kstat_sum(kstat_t *, kstat_t *, kstat_t *); +static void nfsstat_kstat_sum(kstat_t *, kstat_t *, kstat_t *); static void stats_timer(int); static void safe_zalloc(void **, uint_t, int); static int safe_strtoi(char const *, char *); -static void kstat_copy(kstat_t *, kstat_t *, int); -static void fail(int, char *, ...); +static void nfsstat_kstat_copy(kstat_t *, kstat_t *, int); static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *); static kid_t safe_kstat_write(kstat_ctl_t *, kstat_t *, void *); @@ -149,7 +148,11 @@ static old_kstat_t old_rfsreqcnt_v3_kstat, old_rfsreqcnt_v4_kstat; static old_kstat_t old_aclproccnt_v2_kstat, old_aclproccnt_v3_kstat; static old_kstat_t old_aclreqcnt_v2_kstat, old_aclreqcnt_v3_kstat; +static uint_t timestamp_fmt = NODATE; +#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ +#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */ +#endif int main(int argc, char *argv[]) @@ -170,7 +173,10 @@ main(int argc, char *argv[]) count = 0; go_forever = 0; - while ((c = getopt(argc, argv, "cnrsmzav:")) != EOF) { + (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); + + while ((c = getopt(argc, argv, "cnrsmzav:T:")) != EOF) { switch (c) { case 'c': cflag++; @@ -200,6 +206,18 @@ main(int argc, char *argv[]) if ((vflag < 2) || (vflag > 4)) fail(0, "Invalid version number\n"); break; + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage(); + } else { + usage(); + } + break; case '?': default: usage(); @@ -255,6 +273,8 @@ main(int argc, char *argv[]) if (mflag) { mi_print(); } else { + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); if (sflag && (rpc_clts_server_kstat == NULL || @@ -619,7 +639,8 @@ cn_print(int zflag, int vflag) return; if (vflag == 0) { - kstat_sum(nfs_client_kstat, nfs4_client_kstat, ksum_kstat); + nfsstat_kstat_sum(nfs_client_kstat, nfs4_client_kstat, + ksum_kstat); stat_print("\nClient nfs:", ksum_kstat, &old_ksum_kstat.kst, field_width, zflag); } @@ -810,9 +831,9 @@ req_print(kstat_t *req, kstat_t *req_old, int ver, int field_width, knp[i].value.ui64 = 0; } if (knp_old != NULL) - kstat_copy(req, req_old, 1); + nfsstat_kstat_copy(req, req_old, 1); else - kstat_copy(req, req_old, 0); + nfsstat_kstat_copy(req, req_old, 0); } /* @@ -918,9 +939,9 @@ req_print_v4(kstat_t *req, kstat_t *req_old, int field_width, int zflag) kptr[i].value.ui64 = 0; } if (kptr_old != NULL) - kstat_copy(req, req_old, 1); + nfsstat_kstat_copy(req, req_old, 1); else - kstat_copy(req, req_old, 0); + nfsstat_kstat_copy(req, req_old, 0); } static void @@ -969,13 +990,13 @@ stat_print(const char *title_string, kstat_t *req, kstat_t *req_old, } if (knp_old != NULL) - kstat_copy(req, req_old, 1); + nfsstat_kstat_copy(req, req_old, 1); else - kstat_copy(req, req_old, 0); + nfsstat_kstat_copy(req, req_old, 0); } static void -kstat_sum(kstat_t *kstat1, kstat_t *kstat2, kstat_t *sum) +nfsstat_kstat_sum(kstat_t *kstat1, kstat_t *kstat2, kstat_t *sum) { int i; kstat_named_t *knp1, *knp2, *knpsum; @@ -985,7 +1006,7 @@ kstat_sum(kstat_t *kstat1, kstat_t *kstat2, kstat_t *sum) knp1 = KSTAT_NAMED_PTR(kstat1); knp2 = KSTAT_NAMED_PTR(kstat2); if (sum->ks_data == NULL) - kstat_copy(kstat1, sum, 0); + nfsstat_kstat_copy(kstat1, sum, 0); knpsum = KSTAT_NAMED_PTR(sum); for (i = 0; i < (kstat1->ks_ndata); i++) @@ -1297,12 +1318,12 @@ void usage(void) { fprintf(stderr, "Usage: nfsstat [-cnrsza [-v version] " - "[interval [count]]\n"); + "[-T d|u] [interval [count]]\n"); fprintf(stderr, "Usage: nfsstat -m [pathname..]\n"); exit(1); } -static void +void fail(int do_perror, char *message, ...) { va_list args; @@ -1385,7 +1406,7 @@ handle_sig(int x) } static void -kstat_copy(kstat_t *src, kstat_t *dst, int fr) +nfsstat_kstat_copy(kstat_t *src, kstat_t *dst, int fr) { if (fr) diff --git a/usr/src/cmd/intrstat/Makefile.com b/usr/src/cmd/intrstat/Makefile.com index 199da08a00..e766172423 100644 --- a/usr/src/cmd/intrstat/Makefile.com +++ b/usr/src/cmd/intrstat/Makefile.com @@ -29,22 +29,33 @@ SRCS = $(OBJS:%.o=../%.c) include ../../Makefile.cmd +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +SRCS += $(STAT_COMMON_SRCS) + +CPPFLAGS += -I$(STATCOMMONDIR) CFLAGS += $(CCVERBOSE) CFLAGS64 += $(CCVERBOSE) LDLIBS += -ldtrace FILEMODE = 0555 -CLEANFILES += $(OBJS) +CLEANFILES += $(OBJS) $(STAT_COMMON_OBJS) .KEEP_STATE: all: $(PROG) -$(PROG): $(OBJS) - $(LINK.c) -o $@ $(OBJS) $(LDLIBS) +$(PROG): $(OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) -o $@ $(OBJS) $(STAT_COMMON_OBJS) $(LDLIBS) $(POST_PROCESS) ; $(STRIP_STABS) +%.o : $(STATCOMMONDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + clean: -$(RM) $(CLEANFILES) diff --git a/usr/src/cmd/intrstat/intrstat.c b/usr/src/cmd/intrstat/intrstat.c index 0b17211f67..55dab8f4a8 100644 --- a/usr/src/cmd/intrstat/intrstat.c +++ b/usr/src/cmd/intrstat/intrstat.c @@ -34,12 +34,21 @@ #include <strings.h> #include <termio.h> #include <signal.h> +#include <locale.h> + +#include "statcommon.h" #define INTRSTAT_COLUMN_OFFS 14 #define INTRSTAT_COLUMNS_PER_CPU 15 #define INTRSTAT_CPUS_PER_LINE(w) \ (((w) - INTRSTAT_COLUMN_OFFS) / INTRSTAT_COLUMNS_PER_CPU) -#define INTRSTAT_OPTSTR "x:c:C:" +#define INTRSTAT_OPTSTR "x:c:C:T:" + +static uint_t timestamp_fmt = NODATE; + +#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ +#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */ +#endif static dtrace_hdl_t *g_dtp; static int *g_present; @@ -78,7 +87,7 @@ usage(void) { (void) fprintf(stderr, "usage: intrstat [ -C psrset | -c cpulist ] [-x opt[=val]] " - "[interval [ count]]\n"); + "[-T d|u] [interval [ count]]\n"); exit(EXIT_FAILURE); } @@ -358,6 +367,9 @@ main(int argc, char **argv) hrtime_t last, now; dtrace_optval_t statustime; + (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); + (void) sigemptyset(&act.sa_mask); act.sa_flags = 0; act.sa_handler = set_width; @@ -452,6 +464,19 @@ main(int argc, char **argv) break; } + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage(); + } else { + usage(); + } + break; + default: if (strchr(INTRSTAT_OPTSTR, c) == NULL) usage(); @@ -580,6 +605,9 @@ main(int argc, char **argv) g_start = g_end = 0; + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); + do { g_header = 1; diff --git a/usr/src/cmd/pools/poolstat/Makefile b/usr/src/cmd/pools/poolstat/Makefile index f45f974697..bcb4f27f9d 100644 --- a/usr/src/cmd/pools/poolstat/Makefile +++ b/usr/src/cmd/pools/poolstat/Makefile @@ -2,9 +2,8 @@ # CDDL HEADER START # # The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (the "License"). You may not use this file except in compliance -# with the License. +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. @@ -20,11 +19,9 @@ # CDDL HEADER END # # -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -#ident "%Z%%M% %I% %E% SMI" -# # cmd/pools/poolstat/Makefile PROG = poolstat @@ -35,30 +32,40 @@ POFILES = $(OBJS:.o=.po) include ../../Makefile.cmd include ../Makefile.pools -CFLAGS += -I$(POOLSCOMMONDIR) $(EXTRA_CFLAGS) +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +SRCS += $(STAT_COMMON_SRCS) + +CFLAGS += -I$(POOLSCOMMONDIR) -I$(STATCOMMONDIR) $(EXTRA_CFLAGS) sparc_COPTFLAG= LDLIBS += -lpool -lkstat XGETFLAGS = -a CLOBBERFILES += $(POFILES) -lint := LINTFLAGS += -I$(POOLSCOMMONDIR) +lint := LINTFLAGS += -I$(POOLSCOMMONDIR) -I$(STATCOMMONDIR) .KEEP_STATE: all: $(PROG) -$(PROG): $(OBJS) $(COMMON_OBJS) - $(LINK.c) -o $@ $(OBJS) $(COMMON_OBJS) $(LDLIBS) +$(PROG): $(OBJS) $(COMMON_OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) -o $@ $(OBJS) $(COMMON_OBJS) $(STAT_COMMON_OBJS) $(LDLIBS) $(POST_PROCESS) %.o : $(POOLSCOMMONDIR)/%.c $(COMPILE.c) -o $@ $< $(POST_PROCESS_O) +%.o : $(STATCOMMONDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + install: all $(ROOTPROG) clean: - $(RM) $(OBJS) $(COMMON_OBJS) $(POFILES) + $(RM) $(OBJS) $(COMMON_OBJS) $(STAT_COMMON_OBJS) $(POFILES) lint: lint_SRCS diff --git a/usr/src/cmd/pools/poolstat/poolstat.c b/usr/src/cmd/pools/poolstat/poolstat.c index 3b557c271d..ce6ba51d4a 100644 --- a/usr/src/cmd/pools/poolstat/poolstat.c +++ b/usr/src/cmd/pools/poolstat/poolstat.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. */ @@ -40,6 +40,7 @@ #include "utils.h" #include "poolstat.h" #include "poolstat_utils.h" +#include "statcommon.h" #ifndef TEXT_DOMAIN #define TEXT_DOMAIN "SYS_TEST" @@ -55,6 +56,8 @@ typedef int (* formatter) (char *, int, int, poolstat_field_format_t *, char *); +static uint_t timestamp_fmt = NODATE; + /* available field formatters */ static int default_f(char *, int, int, poolstat_field_format_t *, char *); static int bigno_f(char *, int, int, poolstat_field_format_t *, char *); @@ -163,8 +166,8 @@ usage(void) { (void) fprintf(stderr, gettext( "Usage:\n" -"poolstat [-p pool-list] [-r rset-list] [interval [count]]\n" -"poolstat [-p pool-list] [-o format -r rset-list] [interval [count]]\n" +"poolstat [-p pool-list] [-r rset-list] [-T d|u] [interval [count]]\n" +"poolstat [-p pool-list] [-o format -r rset-list] [-T d|u] [interval [count]]\n" " \'pool-list\' is a space-separated list of pool IDs or names\n" " \'rset-list\' is \'all\' or \'pset\'\n" " \'format\' for all resource types is one or more of:\n" @@ -211,7 +214,7 @@ main(int argc, char *argv[]) /* Don't let buffering interfere with piped output. */ (void) setvbuf(stdout, NULL, _IOLBF, 0); - while ((c = getopt(argc, argv, ":p:r:o:")) != EOF) { + while ((c = getopt(argc, argv, ":p:r:o:T:")) != EOF) { switch (c) { case 'p': /* pool name specification */ pflag++; @@ -230,6 +233,18 @@ main(int argc, char *argv[]) usage(); break; } + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage(); + } else { + usage(); + } + break; case ':': { (void) fprintf(stderr, gettext(ERR_OPTION_ARGS), optopt); @@ -287,6 +302,8 @@ main(int argc, char *argv[]) /* collect and print out statistics */ while (count-- != 0) { sa_update(pool_sbag, SA_REFRESH); + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); if (pool_sbag->sb_changed & POU_POOL) (void) printf( "<<State change>>\n"); diff --git a/usr/src/cmd/rcap/rcapstat/Makefile b/usr/src/cmd/rcap/rcapstat/Makefile index afea8d5c91..87e58eb043 100644 --- a/usr/src/cmd/rcap/rcapstat/Makefile +++ b/usr/src/cmd/rcap/rcapstat/Makefile @@ -19,10 +19,9 @@ # 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. # -# ident "%Z%%M% %I% %E% SMI" .KEEP_STATE: .SUFFIXES: @@ -34,19 +33,25 @@ SRCS = rcapstat.c \ utils.c LINTSRCS = $(COMMON_DIR)/utils.c \ - rcapstat.c + rcapstat.c \ + $(STAT_COMMON_SRCS) + +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) $(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG -CPPFLAGS += -I$(COMMON_DIR) +CPPFLAGS += -I$(COMMON_DIR) -I$(STATCOMMONDIR) LDLIBS += -lumem -lzonecfg -lscf LDFLAGS += $(MAPFILE.NGB:%=-M%) LINTFLAGS += $(LDLIBS) -mnu PROG = rcapstat -OBJS = $(SRCS:%.c=%.o) rcapd_conf.o +OBJS = $(SRCS:%.c=%.o) rcapd_conf.o $(STAT_COMMON_OBJS) -POFILES = $(OBJS:%.o=%.po) +POFILES = $(OBJS:%.o=%.po) $(STAT_COMMON_OBJS:%.o=%.po) POFILE = p$(PROG).po CLOBBERFILES += rcapd_conf.c $(POFILES) $(POFILE) @@ -62,10 +67,17 @@ $(PROG): $(OBJS) $(LINK.c) $(OBJS) -o $@ $(LDLIBS) $(POST_PROCESS) +%.o : $(STATCOMMONDIR)/%.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + $(POFILE): $(POFILES) $(RM) $@ $(CAT) $(POFILES) > $@ +%.po: $(STATCOMMONDIR)/%.c + $(COMPILE.cpp) $< > $<.i + $(BUILD.po) clean: $(RM) $(OBJS) diff --git a/usr/src/cmd/rcap/rcapstat/rcapstat.c b/usr/src/cmd/rcap/rcapstat/rcapstat.c index a22a40f50d..edac6dd56d 100644 --- a/usr/src/cmd/rcap/rcapstat/rcapstat.c +++ b/usr/src/cmd/rcap/rcapstat/rcapstat.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/stat.h> #include <stdlib.h> @@ -40,6 +38,7 @@ #include "rcapd.h" #include "utils.h" #include "rcapd_stat.h" +#include "statcommon.h" static char mode[RC_MODE_LEN]; static rcapd_stat_hdr_t hdr; @@ -47,6 +46,8 @@ static int global; static int unformatted; static time_t stat_mod = 0; +static uint_t timestamp_fmt = NODATE; + typedef struct col { rcid_t col_id; char col_name[LC_NAME_LEN]; @@ -119,7 +120,8 @@ static void usage() { (void) fprintf(stderr, - gettext("usage: rcapstat [-g] [-p | -z] [interval [count]]\n")); + gettext("usage: rcapstat [-g] [-p | -z] [-T d|u] " + "[interval [count]]\n")); exit(E_USAGE); } @@ -366,7 +368,7 @@ main(int argc, char *argv[]) (void) setprogname("rcapstat"); global = unformatted = 0; - while ((opt = getopt(argc, argv, "gpuz")) != (int)EOF) { + while ((opt = getopt(argc, argv, "gpuzT:")) != (int)EOF) { switch (opt) { case 'g': global = 1; @@ -382,6 +384,18 @@ main(int argc, char *argv[]) stat_type = RCIDT_ZONE; zones = 1; 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(); } @@ -401,6 +415,8 @@ main(int argc, char *argv[]) while (always || count-- > 0) { if (read_stats(stat_type) != E_SUCCESS) return (E_ERROR); + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); if (!unformatted) { print_stats(stat_type); (void) fflush(stdout); diff --git a/usr/src/cmd/stat/Makefile.stat b/usr/src/cmd/stat/Makefile.stat index 148963aa38..6ae7145ccc 100644 --- a/usr/src/cmd/stat/Makefile.stat +++ b/usr/src/cmd/stat/Makefile.stat @@ -19,15 +19,14 @@ # 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. # -#ident "%Z%%M% %I% %E% SMI" -# # cmd/stat/Makefile.stat STATSRC = $(SRC)/cmd/stat STATCOMMONDIR = $(STATSRC)/common -COMMON_OBJS = acquire.o walkers.o acquire_iodevs.o dsr.o mnt.o common.o +COMMON_OBJS = acquire.o walkers.o acquire_iodevs.o dsr.o mnt.o common.o \ + timestamp.o COMMON_SRCS = $(COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) diff --git a/usr/src/cmd/stat/common/common.c b/usr/src/cmd/stat/common/common.c index 0bf50b9d3b..9fc3b99715 100644 --- a/usr/src/cmd/stat/common/common.c +++ b/usr/src/cmd/stat/common/common.c @@ -30,13 +30,10 @@ #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, ...) @@ -128,29 +125,3 @@ 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 1efaacae1d..7ae60ced27 100644 --- a/usr/src/cmd/stat/common/statcommon.h +++ b/usr/src/cmd/stat/common/statcommon.h @@ -324,7 +324,7 @@ void sleep_until(hrtime_t *wakeup, hrtime_t interval, int forever, void cont_handler(int sig_number); /* Print a timestamp in either Unix or standard format. */ -void print_timestamp(void); +void print_timestamp(uint_t); #ifdef __cplusplus } diff --git a/usr/src/cmd/stat/common/timestamp.c b/usr/src/cmd/stat/common/timestamp.c new file mode 100644 index 0000000000..e0592f3806 --- /dev/null +++ b/usr/src/cmd/stat/common/timestamp.c @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include "statcommon.h" + +#include <langinfo.h> + +/* + * 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(uint_t timestamp_fmt) +{ + 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/fsstat/Makefile b/usr/src/cmd/stat/fsstat/Makefile index 2c12416481..17a0e34f1b 100644 --- a/usr/src/cmd/stat/fsstat/Makefile +++ b/usr/src/cmd/stat/fsstat/Makefile @@ -30,8 +30,7 @@ SRCS =$(OBJS:%.o=%.c) $(COMMON_SRCS) include $(SRC)/cmd/Makefile.cmd include $(SRC)/cmd/stat/Makefile.stat -# Only want one object -COMMON_OBJS = common.o +COMMON_OBJS = common.o timestamp.o COMMON_SRCS = $(COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) LDLIBS += -lkstat diff --git a/usr/src/cmd/stat/fsstat/fsstat.c b/usr/src/cmd/stat/fsstat/fsstat.c index 5eb35f5e5b..1869ff4fe6 100644 --- a/usr/src/cmd/stat/fsstat/fsstat.c +++ b/usr/src/cmd/stat/fsstat/fsstat.c @@ -117,7 +117,7 @@ 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 uint_t timestamp_fmt = NODATE; /* print timestamp with stats */ static int vs_i = 0; /* Index of current vs[] slot */ @@ -1001,7 +1001,7 @@ main(int argc, char *argv[]) /* Initial timestamp */ if (timestamp_fmt != NODATE) { - print_timestamp(); + print_timestamp(timestamp_fmt); linesout++; } @@ -1062,7 +1062,7 @@ main(int argc, char *argv[]) sleep_until(&start_n, period_n, forever, &caught_cont); if (timestamp_fmt != NODATE) { - print_timestamp(); + print_timestamp(timestamp_fmt); linesout++; } diff --git a/usr/src/cmd/stat/iostat/iostat.c b/usr/src/cmd/stat/iostat/iostat.c index 958c1b19d1..2720e51f34 100644 --- a/usr/src/cmd/stat/iostat/iostat.c +++ b/usr/src/cmd/stat/iostat/iostat.c @@ -126,7 +126,7 @@ 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) */ -extern uint_t timestamp_fmt; /* timestamp each display (-T) */ +static uint_t timestamp_fmt = NODATE; /* timestamp each display (-T) */ static uint_t do_devid; /* -E should show devid */ /* @@ -293,6 +293,10 @@ main(int argc, char **argv) if (formatter_list) { format_t *tmp; tmp = formatter_list; + + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); + while (tmp) { (tmp->nfunc)(); tmp = tmp->next; @@ -1356,9 +1360,6 @@ do_format(void) dh_len = strlen(disk_header) - 2; } - if (timestamp_fmt != NODATE) - setup(print_timestamp); - /* * -n *and* (-E *or* -e *or* -x) */ diff --git a/usr/src/cmd/stat/mpstat/mpstat.c b/usr/src/cmd/stat/mpstat/mpstat.c index 320bc8be80..64324224fd 100644 --- a/usr/src/cmd/stat/mpstat/mpstat.c +++ b/usr/src/cmd/stat/mpstat/mpstat.c @@ -53,7 +53,7 @@ char *cmdname = "mpstat"; int caught_cont = 0; -extern uint_t timestamp_fmt; +static uint_t timestamp_fmt = NODATE; static int hz; static int display_pset = -1; @@ -490,7 +490,7 @@ show_cpu_usage(struct snapshot *old, struct snapshot *new, int display_agg) snapshot_cb cb = compare_cpu; if (timestamp_fmt != NODATE) - print_timestamp(); + print_timestamp(timestamp_fmt); if (lines_until_reprint == 0 || nr_active_cpus(new) > 1) { print_header(display_agg, show_set); diff --git a/usr/src/cmd/stat/vmstat/vmstat.c b/usr/src/cmd/stat/vmstat/vmstat.c index 0b576d1ece..613284c82e 100644 --- a/usr/src/cmd/stat/vmstat/vmstat.c +++ b/usr/src/cmd/stat/vmstat/vmstat.c @@ -31,7 +31,7 @@ char *cmdname = "vmstat"; int caught_cont = 0; -extern uint_t timestamp_fmt; +static uint_t timestamp_fmt = NODATE; static int hz; static int pagesize; @@ -279,7 +279,7 @@ dovmstats(struct snapshot *old, struct snapshot *new) updates = denom(DELTA(s_sys.ss_sysinfo.updates)); if (timestamp_fmt != NODATE) { - print_timestamp(); + print_timestamp(timestamp_fmt); lines--; } diff --git a/usr/src/cmd/zpool/Makefile b/usr/src/cmd/zpool/Makefile index ecdbaf2339..1e1afa942e 100644 --- a/usr/src/cmd/zpool/Makefile +++ b/usr/src/cmd/zpool/Makefile @@ -19,11 +19,9 @@ # 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. # -# ident "%Z%%M% %I% %E% SMI" -# PROG= zpool OBJS= zpool_main.o zpool_vdev.o zpool_iter.o zpool_util.o @@ -33,9 +31,17 @@ POFILE= zpool.po include ../Makefile.cmd +STATCOMMONDIR = $(SRC)/cmd/stat/common + +STAT_COMMON_OBJS = timestamp.o +STAT_COMMON_SRCS = $(STAT_COMMON_OBJS:%.o=$(STATCOMMONDIR)/%.c) +STAT_COMMON_POFILES = $(STAT_COMMON_OBJS:%.o=%.po) +SRCS += $(STAT_COMMON_SRCS) +POFILES += $(STAT_COMMON_POFILES) + LDLIBS += -lzfs -lnvpair -ldevid -lefi -ldiskmgt -luutil -lumem -INCS += -I../../common/zfs +INCS += -I../../common/zfs -I$(STATCOMMONDIR) CPPFLAGS += -D_LARGEFILE64_SOURCE=1 -D_REENTRANT $(INCS) $(NOT_RELEASE_BUILD)CPPFLAGS += -DDEBUG @@ -50,16 +56,24 @@ ROOTUSRSBINLINKS = $(PROG:%=$(ROOTUSRSBIN)/%) all: $(PROG) -$(PROG): $(OBJS) - $(LINK.c) -o $@ $(OBJS) $(LDLIBS) +$(PROG): $(OBJS) $(STAT_COMMON_OBJS) + $(LINK.c) -o $@ $(OBJS) $(STAT_COMMON_OBJS) $(LDLIBS) $(POST_PROCESS) +%.o: $(STATCOMMONDIR)/%.c + $(COMPILE.c) $< + $(POST_PROCESS_O) + install: all $(ROOTSBINPROG) $(ROOTUSRSBINLINKS) $(POFILE): $(POFILES) $(RM) $@ $(CAT) $(POFILES) > $@ +%.po: $(STATCOMMONDIR)/%.c + $(COMPILE.cpp) $< > $<.i + $(BUILD.po) + clean: $(RM) $(OBJS) diff --git a/usr/src/cmd/zpool/zpool_main.c b/usr/src/cmd/zpool/zpool_main.c index c9b092e449..c78dc6f646 100644 --- a/usr/src/cmd/zpool/zpool_main.c +++ b/usr/src/cmd/zpool/zpool_main.c @@ -50,6 +50,8 @@ #include "zpool_util.h" #include "zfs_comutil.h" +#include "statcommon.h" + static int zpool_do_create(int, char **); static int zpool_do_destroy(int, char **); @@ -173,6 +175,8 @@ static zpool_command_t command_table[] = { zpool_command_t *current_command; static char history_str[HIS_MAX_RECORD_LEN]; +static uint_t timestamp_fmt = NODATE; + static const char * get_usage(zpool_help_t idx) { switch (idx) { @@ -203,7 +207,7 @@ get_usage(zpool_help_t idx) { "\t [-d dir | -c cachefile] [-D] [-f] [-R root] " "<pool | id> [newpool]\n")); case HELP_IOSTAT: - return (gettext("\tiostat [-v] [pool] ... [interval " + return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval " "[count]]\n")); case HELP_LIST: return (gettext("\tlist [-H] [-o property[,...]] " @@ -2070,8 +2074,9 @@ get_namewidth(zpool_handle_t *zhp, void *data) } /* - * zpool iostat [-v] [pool] ... [interval [count]] + * zpool iostat [-T d|u] [-v] [pool] ... [interval [count]] * + * -T Display a timestamp in date(1) or Unix format * -v Display statistics for individual vdevs * * This command can be tricky because we want to be able to deal with pool @@ -2092,8 +2097,20 @@ zpool_do_iostat(int argc, char **argv) iostat_cbdata_t cb; /* check options */ - while ((c = getopt(argc, argv, "v")) != -1) { + while ((c = getopt(argc, argv, "T:v")) != -1) { switch (c) { + case 'T': + if (optarg) { + if (*optarg == 'u') + timestamp_fmt = UDATE; + else if (*optarg == 'd') + timestamp_fmt = DDATE; + else + usage(B_FALSE); + } else { + usage(B_FALSE); + } + break; case 'v': verbose = B_TRUE; break; @@ -2210,6 +2227,9 @@ zpool_do_iostat(int argc, char **argv) cb.cb_namewidth = 0; (void) pool_list_iter(list, B_FALSE, get_namewidth, &cb); + if (timestamp_fmt != NODATE) + print_timestamp(timestamp_fmt); + /* * If it's the first time, or verbose mode, print the header. */ diff --git a/usr/src/cmd/zpool/zpool_util.c b/usr/src/cmd/zpool/zpool_util.c index f44da4ff60..bc34e41a4c 100644 --- a/usr/src/cmd/zpool/zpool_util.c +++ b/usr/src/cmd/zpool/zpool_util.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 <errno.h> #include <libgen.h> #include <libintl.h> @@ -54,7 +52,7 @@ safe_malloc(size_t size) * Same as above, but for strdup() */ char * -safe_strdup(const char *str) +zpool_safe_strdup(const char *str) { char *ret; diff --git a/usr/src/cmd/zpool/zpool_util.h b/usr/src/cmd/zpool/zpool_util.h index e82f3202af..2bcefee62b 100644 --- a/usr/src/cmd/zpool/zpool_util.h +++ b/usr/src/cmd/zpool/zpool_util.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. */ @@ -37,7 +37,7 @@ extern "C" { * Basic utility functions */ void *safe_malloc(size_t); -char *safe_strdup(const char *); +char *zpool_safe_strdup(const char *); void zpool_no_memory(void); uint_t num_logs(nvlist_t *nv); |