rcapstat.c revision 26fd77009b17f8c8fb32eb362584cfd635e87ad9
/*
* 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 <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <libintl.h>
#include <locale.h>
#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;
static int global;
static int unformatted;
typedef struct col {
char col_name[LC_NAME_LEN];
int col_fresh;
} col_t;
static int ncol;
static col_t *
{
return (col);
return (NULL);
}
static col_t *
{
}
ncol++;
return (new_col);
}
static void
{
ncol--;
}
static void
usage()
{
gettext("usage: rcapstat [-g] [-p | -z] [-T d|u] "
"[interval [count]]\n"));
}
static void
{
char tag = 'K';
if (size >= 10000) {
tag = 'M';
if (size >= 10000) {
tag = 'G';
}
}
}
static int
{
int fd;
int proc_fd;
char procfile[20];
return (E_ERROR);
}
gettext("rcapstat: can't read stat file header: %s\n"),
return (E_ERROR);
}
/*
* Check if rcapd is running
*/
return (E_ERROR);
}
col->col_paged_eff = 0;
col->col_paged_att = 0;
}
continue;
}
col->col_paged_eff =
col->col_paged_eff /
} else {
col->col_paged_eff_avg = 0;
}
col->col_paged_att =
col->col_paged_att /
} else {
col->col_paged_att_avg = 0;
}
}
/*
* Remove stale data
*/
}
return (E_SUCCESS);
}
/*
* Print each collection's interval statistics.
*/
/*ARGSUSED*/
static void
print_unformatted_stats(void)
{
sizeof (col->col_src_stat)) == 0) {
continue;
}
"%llu/%llu, ineffective/scans/unenforced/samplings: "
}
if (global)
}
static void
{
char size[6];
char limit[6];
char rss[6];
char nproc[6];
char paged_att[6];
char paged_eff[6];
char paged_att_avg[6];
char paged_eff_avg[6];
static int count = 0;
/*
* Print a header once every 20 times if we're only displaying reports
* for one collection (10 times if -g is used). Print a header every
* interval otherwise.
*/
(void) printf("%6s %-15s %5s %5s %5s %5s %5s %5s %5s %5s\n",
"nproc", "vm", "rss", "cap",
"at", "avgat", "pg", "avgpg");
count = 0;
continue;
if (col->col_paged_att == 0)
else
(void) printf("%6lld %-15s %5s %5s %5s %5s %5s %5s %5s %5s\n",
}
if (global)
}
int
{
int interval = 5;
int count;
int always = 1;
int opt;
int projects = 0;
int zones = 0;
/* project reporting is the default if no option is specified */
(void) textdomain(TEXT_DOMAIN);
(void) setprogname("rcapstat");
global = unformatted = 0;
switch (opt) {
case 'g':
global = 1;
break;
case 'p':
projects = 1;
break;
case 'u':
unformatted = 1;
break;
case 'z':
zones = 1;
break;
case 'T':
if (optarg) {
if (*optarg == 'u')
else if (*optarg == 'd')
else
usage();
} else {
usage();
}
break;
default:
usage();
}
}
always = 0;
}
usage();
return (E_ERROR);
if (timestamp_fmt != NODATE)
if (!unformatted) {
} else {
}
}
return (E_SUCCESS);
}