mpstat.c revision 4944376cd5de3dcd3b4feeaad9cbedbc024d1474
/*
* 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
* 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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>
#include <memory.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <errno.h>
#include <kstat.h>
#include <poll.h>
#include <signal.h>
#include <locale.h>
#include "statcommon.h"
#define SNAP(s, i, l, n) ((s) ? agg_proc_snap(s, i, l, n) : 0)
#define REPRINT 20
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;
static int suppress_state;
static void print_header(int, int);
static void usage(void);
int
{
int c;
int display_agg = 0;
int iter = 1;
int interval = 0;
char *endptr;
int infinite_cycles = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'a':
/*
* Display aggregate data for processor sets.
*/
display_agg = 1;
break;
case 'p':
/*
* Display all processor sets.
*/
if (display_pset != -1)
usage();
show_set = 1;
break;
case 'P':
/*
* Display specific processor set.
*/
if (show_set == 1)
usage();
display_pset = (int)strtol
usage();
/*
* Not valid to specify a negative processor
* set value.
*/
if (display_pset < 0)
usage();
break;
case 'q':
suppress_state = 1;
break;
case 'T':
if (optarg) {
if (*optarg == 'u')
else if (*optarg == 'd')
else
usage();
} else {
usage();
}
break;
case '?':
usage();
break;
}
usage();
usage();
if (iter == 0)
return (0);
} else {
infinite_cycles = 1;
}
}
types |= SNAP_PSETS;
kc = open_kstat();
/* Set up handler for SIGCONT */
while (infinite_cycles || iter > 0) {
if (!suppress_state)
/* if config changed, show stats from boot */
}
break;
/* Have a kip */
}
(void) kstat_close(kc);
return (0);
}
/*
* Print an mpstat output header.
*/
static void
{
if (display_agg == 1)
(void) printf("SET minf mjf xcal intr ithr csw icsw migr "
"smtx srw syscl usr sys wt idl sze");
else {
(void) printf("CPU minf mjf xcal intr ithr csw icsw migr "
"smtx srw syscl usr sys wt idl");
if (show_set == 1)
(void) printf(" set");
}
(void) printf("\n");
}
static void
{
return;
/*
* the first mpstat output will have c1 = NULL, to give
* results since boot
*/
if (c1) {
/* check there are stats to report */
if (!CPU_ACTIVE(c1))
return;
}
/* check there are stats to report */
if (!CPU_ACTIVE(c2))
return;
etime = 1.0;
(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",
if (show_set)
(void) printf("\n");
}
/*ARGSUSED*/
static void
{
return;
}
static int
pset_has_stats(struct pset_snapshot *p)
{
int count = 0;
size_t i;
for (i = 0; i < p->ps_nr_cpus; i++) {
if (CPU_ACTIVE(p->ps_cpus[i]))
count++;
}
return (count);
}
static void
{
}
static kstat_t *
{
size_t i;
if (p->ps_nr_cpus == NULL)
return (NULL);
return (NULL);
for (i = 1; i < p->ps_nr_cpus; i++) {
}
return (ks);
}
static kstat_t *
{
size_t i;
if (p->ps_nr_cpus == NULL)
return (NULL);
return (NULL);
for (i = 1; i < p->ps_nr_cpus; i++) {
}
return (ks);
}
static uint64_t
{
size_t i = 0;
break;
}
}
break;
}
}
return (0);
}
}
static void
{
return;
return;
/*
* FIXME: these aggs will count "new" or disappeared cpus
* in a set, leaving an apparent huge change.
*/
/*
* the first mpstat output will have p1 = NULL, to give
* results since boot
*/
if (p1) {
goto out;
}
goto out;
etime = 1.0;
(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_nr_cpus);
out:
}
/*ARGSUSED*/
static void
{
return;
}
/*
* Report statistics for a sample interval.
*/
static void
{
static int lines_until_reprint = 0;
if (timestamp_fmt != NODATE)
}
if (display_agg) {
type = SNAP_PSETS;
cb = compare_pset;
}
/* print stats since boot the first time round */
}
/*
* Usage message on error.
*/
static void
usage(void)
{
"Usage: mpstat [-aq] [-p | -P processor_set] [-T d|u] "
"[interval [count]]\n");
exit(1);
}