vmstats: fix coding style

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-10-23 00:14:01 +02:00
parent 7af3d4efce
commit 72e37c7d11

382
vmstat.c
View File

@ -1,32 +1,33 @@
// old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
// most code copyright 2002 Albert Cahalan
//
// 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
// Export proc/stat access to libproc
// Adapt vmstat helpfile
// 31/05/2003 (Fabian) : Add diskstat support (/libproc)
// June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
// June 2003 (Fabian) : -Adding diskstat against 3.1.9, slabinfo
// -patching 'header' in disk & slab
// July 2003 (Fabian) : -Adding disk partition output
// -Adding disk table
// -Syncing help / usage
/* old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
* most code copyright 2002 Albert Cahalan
*
* 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
* Export proc/stat access to libproc
* Adapt vmstat helpfile
* 31/05/2003 (Fabian) : Add diskstat support (/libproc)
* June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
* June 2003 (Fabian) : Adding diskstat against 3.1.9, slabinfo
* patching 'header' in disk & slab
* July 2003 (Fabian) : Adding disk partition output
* Adding disk table
* Syncing help / usage
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/dir.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dir.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include "c.h"
#include "nls.h"
@ -51,12 +52,13 @@ static char szDataUnit[3] = "K";
static int statMode = VMSTAT;
static int a_option; /* "-a" means "show active/inactive" */
/* "-a" means "show active/inactive" */
static int a_option;
static unsigned sleep_time = 1;
static unsigned long num_updates;
static unsigned int height; // window height
/* window height */
static unsigned int height;
static unsigned int moreheaders = TRUE;
static void __attribute__ ((__noreturn__))
@ -64,7 +66,8 @@ static void __attribute__ ((__noreturn__))
{
fputs(USAGE_HEADER, out);
fprintf(out,
" %s [options] [delay [count]]\n", program_invocation_short_name);
" %s [options] [delay [count]]\n",
program_invocation_short_name);
fputs(USAGE_OPTIONS, out);
fputs(_(" -a, --active active/inactive memory\n"), out);
fputs(_(" -f, --forks number of forks since boot\n"), out);
@ -84,14 +87,16 @@ static void __attribute__ ((__noreturn__))
}
#if 0
// produce: " 6 ", "123 ", "123k ", etc.
static int format_1024(unsigned long long val64, char *restrict dst){
/* produce: " 6 ", "123 ", "123k ", etc. */
static int format_1024(unsigned long long val64, char *restrict dst)
{
unsigned oldval;
const char suffix[] = " kmgtpe";
unsigned level = 0;
unsigned val32;
if(val64 < 1000){ // special case to avoid "6.0 " when plain " 6 " would do
if (val64 < 1000) {
/* special case to avoid "6.0 " when plain " 6 " would do */
val32 = val64;
return sprintf(dst, "%3u ", val32);
}
@ -116,15 +121,16 @@ static int format_1024(unsigned long long val64, char *restrict dst){
return sprintf(dst, "%3u%c ", val32, suffix[level]);
}
// produce: " 6 ", "123 ", "123k ", etc.
static int format_1000(unsigned long long val64, char *restrict dst){
/* produce: " 6 ", "123 ", "123k ", etc. */
static int format_1000(unsigned long long val64, char *restrict dst)
{
unsigned oldval;
const char suffix[] = " kmgtpe";
unsigned level = 0;
unsigned val32;
if(val64 < 1000){ // special case to avoid "6.0 " when plain " 6 " would do
if (val64 < 1000) {
/* special case to avoid "6.0 " when plain " 6 " would do */
val32 = val64;
return sprintf(dst, "%3u ", val32);
}
@ -150,54 +156,48 @@ static int format_1000(unsigned long long val64, char *restrict dst){
}
#endif
////////////////////////////////////////////////////////////////////////////
static void new_header(void){
printf("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
printf(
"%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s\n",
"r","b",
"swpd", "free", a_option?"inact":"buff", a_option?"active":"cache",
"si","so",
"bi","bo",
"in","cs",
"us","sy","id","wa"
);
static void new_header(void)
{
printf
("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
printf
("%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s\n",
"r", "b", "swpd", "free", a_option ? "inact" : "buff",
a_option ? "active" : "cache", "si", "so", "bi", "bo", "in", "cs",
"us", "sy", "id", "wa");
}
////////////////////////////////////////////////////////////////////////////
static unsigned long unitConvert(unsigned int size){
static unsigned long unitConvert(unsigned int size)
{
float cvSize;
cvSize = (float)size / dataUnit * ((statMode == SLABSTAT) ? 1 : 1024);
return ((unsigned long)cvSize);
}
////////////////////////////////////////////////////////////////////////////
static void new_format(void) {
const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u\n";
static void new_format(void)
{
const char format[] =
"%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u\n";
unsigned int tog = 0; /* toggle switch for cleaner code */
unsigned int i;
unsigned int hz = Hertz;
unsigned int running, blocked, dummy_1, dummy_2;
jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2], cpu_xxx[2], cpu_yyy[2], cpu_zzz[2];
jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2],
cpu_xxx[2], cpu_yyy[2], cpu_zzz[2];
jiff duse, dsys, didl, diow, dstl, Div, divo2;
unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
unsigned int intr[2], ctxt[2];
unsigned int sleep_half;
unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
int debt = 0; // handle idle ticks running backwards
int debt = 0; /* handle idle ticks running backwards */
sleep_half = (sleep_time / 2);
new_header();
meminfo();
getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,cpu_iow,cpu_xxx,cpu_yyy,cpu_zzz,
pgpgin,pgpgout,pswpin,pswpout,
intr,ctxt,
&running,&blocked,
&dummy_1, &dummy_2);
getstat(cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy,
cpu_zzz, pgpgin, pgpgout, pswpin, pswpout, intr, ctxt, &running,
&blocked, &dummy_1, &dummy_2);
duse = *cpu_use + *cpu_nic;
dsys = *cpu_sys + *cpu_xxx + *cpu_yyy;
@ -224,21 +224,26 @@ static void new_format(void) {
(unsigned)( (100*dstl + divo2) / Div ) */
);
for(i=1;i<num_updates;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
/* main loop */
for (i = 1; i < num_updates; i++) {
sleep(sleep_time);
if (moreheaders && ((i%height)==0)) new_header();
if (moreheaders && ((i % height) == 0))
new_header();
tog = !tog;
meminfo();
getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog,cpu_iow+tog,cpu_xxx+tog,cpu_yyy+tog,cpu_zzz+tog,
pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog,
intr+tog,ctxt+tog,
&running,&blocked,
&dummy_1,&dummy_2);
getstat(cpu_use + tog, cpu_nic + tog, cpu_sys + tog,
cpu_idl + tog, cpu_iow + tog, cpu_xxx + tog,
cpu_yyy + tog, cpu_zzz + tog, pgpgin + tog,
pgpgout + tog, pswpin + tog, pswpout + tog, intr + tog,
ctxt + tog, &running, &blocked, &dummy_1, &dummy_2);
duse= cpu_use[tog]-cpu_use[!tog] + cpu_nic[tog]-cpu_nic[!tog];
dsys= cpu_sys[tog]-cpu_sys[!tog] + cpu_xxx[tog]-cpu_xxx[!tog] + cpu_yyy[tog]-cpu_yyy[!tog];
duse =
cpu_use[tog] - cpu_use[!tog] + cpu_nic[tog] - cpu_nic[!tog];
dsys =
cpu_sys[tog] - cpu_sys[!tog] + cpu_xxx[tog] -
cpu_xxx[!tog] + cpu_yyy[tog] - cpu_yyy[!tog];
didl = cpu_idl[tog] - cpu_idl[!tog];
diow = cpu_iow[tog] - cpu_iow[!tog];
dstl = cpu_zzz[tog] - cpu_zzz[!tog];
@ -256,43 +261,55 @@ static void new_format(void) {
Div = duse + dsys + didl + diow + dstl;
divo2 = Div / 2UL;
printf(format,
running, blocked,
running,
blocked,
unitConvert(kb_swap_used),unitConvert(kb_main_free),
unitConvert(a_option?kb_inactive:kb_main_buffers),
unitConvert(a_option?kb_active:kb_main_cached),
(unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ), /*si*/
(unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ), /*so*/
(unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ), /*bi*/
(unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ), /*bo*/
(unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time ), /*in*/
(unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time ), /*cs*/
(unsigned)( (100*duse+divo2)/Div ), /*us*/
(unsigned)( (100*dsys+divo2)/Div ), /*sy*/
(unsigned)( (100*didl+divo2)/Div ), /*id*/
(unsigned)( (100*diow+divo2)/Div )/*, //wa
(unsigned)( (100*dstl+divo2)/Div ) //st */
/*si */
(unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ),
/* so */
(unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ),
/* bi */
(unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ),
/* bo */
(unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ),
/* in */
(unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time ),
/* cs */
(unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time ),
/* us */
(unsigned)( (100*duse+divo2)/Div ),
/* sy */
(unsigned)( (100*dsys+divo2)/Div ),
/* id */
(unsigned)( (100*didl+divo2)/Div ),
/* wa */
(unsigned)( (100*diow+divo2)/Div )/*,
/ * st * /
(unsigned)( (100*dstl+divo2)/Div ) */
);
}
}
////////////////////////////////////////////////////////////////////////////
static void diskpartition_header(const char *partition_name){
printf("%-10s %10s %10s %10s %10s\n",partition_name, _("reads "), _("read sectors"), _("writes "), _("requested writes"));
static void diskpartition_header(const char *partition_name)
{
printf("%-10s %10s %10s %10s %10s\n", partition_name, _("reads "),
_("read sectors"), _("writes "), _("requested writes"));
}
////////////////////////////////////////////////////////////////////////////
static int diskpartition_format(const char* partition_name){
static int diskpartition_format(const char *partition_name)
{
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions, *current_partition = NULL;
unsigned long ndisks, j, k, npartitions;
const char format[] = "%20u %10llu %10u %10llu\n";
const char format[] = "%20u %10llu %10u %10u\n";
fDiskstat = fopen("/proc/diskstats", "rb");
if (!fDiskstat)
errx(EXIT_FAILURE, _("Your kernel doesn't support diskstat. (2.5.70 or above required)"));
errx(EXIT_FAILURE,
_("Your kernel doesn't support diskstat. (2.5.70 or above required)"));
fclose(fDiskstat);
ndisks = getdiskstat(&disks, &partitions);
@ -309,18 +326,21 @@ static int diskpartition_format(const char* partition_name){
}
diskpartition_header(partition_name);
printf(format,
current_partition->reads,current_partition->reads_sectors,current_partition->writes,current_partition->requested_writes);
current_partition->reads, current_partition->reads_sectors,
current_partition->writes, current_partition->requested_writes);
fflush(stdout);
free(disks);
free(partitions);
for (j = 1; j < num_updates; j++) {
if (moreheaders && ((j%height)==0)) diskpartition_header(partition_name);
if (moreheaders && ((j % height) == 0))
diskpartition_header(partition_name);
sleep(sleep_time);
ndisks = getdiskstat(&disks, &partitions);
npartitions = getpartitions_num(disks, ndisks);
current_partition = NULL;
for (k = 0; k < npartitions; k++) {
if(!strcmp(partition_name, partitions[k].partition_name)){
if (!strcmp
(partition_name, partitions[k].partition_name)) {
current_partition = &(partitions[k]);
}
}
@ -330,7 +350,10 @@ static int diskpartition_format(const char* partition_name){
return -1;
}
printf(format,
current_partition->reads,current_partition->reads_sectors,current_partition->writes,current_partition->requested_writes);
current_partition->reads,
current_partition->reads_sectors,
current_partition->writes,
current_partition->requested_writes);
fflush(stdout);
free(disks);
free(partitions);
@ -338,30 +361,31 @@ static int diskpartition_format(const char* partition_name){
return 0;
}
////////////////////////////////////////////////////////////////////////////
static void diskheader(void){
static void diskheader(void)
{
printf(_("disk- ------------reads------------ ------------writes----------- -----IO------\n"));
printf("%5s %6s %6s %7s %7s %6s %6s %7s %7s %6s %6s\n",
" ", _("total"), _("merged"),_("sectors"),_("ms"),_("total"),_("merged"),_("sectors"),_("ms"),_("cur"),_("sec"));
" ", _("total"), _("merged"), _("sectors"), _("ms"), _("total"),
_("merged"), _("sectors"), _("ms"), _("cur"), _("sec"));
}
////////////////////////////////////////////////////////////////////////////
static void diskformat(void){
static void diskformat(void)
{
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions;
unsigned long ndisks, i, j, k;
const char format[] = "%-5s %6u %6u %7llu %7u %6u %6u %7llu %7u %6u %6u\n";
if ((fDiskstat = fopen("/proc/diskstats", "rb"))) {
fclose(fDiskstat);
ndisks = getdiskstat(&disks, &partitions);
if (!moreheaders) diskheader();
if (!moreheaders)
diskheader();
for (k = 0; k < ndisks; k++) {
if (moreheaders && ((k%height)==0)) diskheader();
if (moreheaders && ((k % height) == 0))
diskheader();
printf(format,
disks[k].disk_name,
disks[k].reads,
@ -373,9 +397,8 @@ static void diskformat(void){
disks[k].written_sectors,
disks[k].milli_writing,
disks[k].inprogress_IO ? disks[k].inprogress_IO / 1000 : 0,
disks[k].milli_spent_IO?disks[k].milli_spent_IO/1000:0/*,
disks[i].weighted_milli_spent_IO/1000*/
);
disks[k].milli_spent_IO ? disks[k].
milli_spent_IO / 1000 : 0);
fflush(stdout);
}
free(disks);
@ -384,7 +407,8 @@ static void diskformat(void){
sleep(sleep_time);
ndisks = getdiskstat(&disks, &partitions);
for (i = 0; i < ndisks; i++, k++) {
if (moreheaders && ((k%height)==0)) diskheader();
if (moreheaders && ((k % height) == 0))
diskheader();
printf(format,
disks[i].disk_name,
disks[i].reads,
@ -396,27 +420,26 @@ static void diskformat(void){
disks[i].written_sectors,
disks[i].milli_writing,
disks[i].inprogress_IO ? disks[i].inprogress_IO / 1000 : 0,
disks[i].milli_spent_IO?disks[i].milli_spent_IO/1000:0/*,
disks[i].weighted_milli_spent_IO/1000*/
);
disks[i].milli_spent_IO ? disks[i].
milli_spent_IO / 1000 : 0);
fflush(stdout);
}
free(disks);
free(partitions);
}
} else
errx(EXIT_FAILURE, _("Your kernel doesn't support diskstat (2.5.70 or above required)"));
errx(EXIT_FAILURE,
_("Your kernel doesn't support diskstat (2.5.70 or above required)"));
}
////////////////////////////////////////////////////////////////////////////
static void slabheader(void){
printf("%-24s %6s %6s %6s %6s\n",_("Cache"),_("Num"), _("Total"), _("Size"), _("Pages"));
static void slabheader(void)
{
printf("%-24s %6s %6s %6s %6s\n", _("Cache"), _("Num"), _("Total"),
_("Size"), _("Pages"));
}
////////////////////////////////////////////////////////////////////////////
static void slabformat (void){
static void slabformat(void)
{
FILE *fSlab;
struct slab_cache *slabs;
unsigned long nSlab, i, j, k;
@ -428,40 +451,38 @@ static void slabformat (void){
return;
}
if (!moreheaders) slabheader();
if (!moreheaders)
slabheader();
nSlab = getslabinfo(&slabs);
for (k = 0; k < nSlab; k++) {
if (moreheaders && ((k%height)==0)) slabheader();
if (moreheaders && ((k % height) == 0))
slabheader();
printf(format,
slabs[k].name,
slabs[k].active_objs,
slabs[k].num_objs,
slabs[k].objsize,
slabs[k].objperslab
);
slabs[k].objsize, slabs[k].objperslab);
}
free(slabs);
for (j = 1, k = 1; j < num_updates; j++) {
sleep(sleep_time);
nSlab = getslabinfo(&slabs);
for (i = 0; i < nSlab; i++, k++) {
if (moreheaders && ((k%height)==0)) slabheader();
if (moreheaders && ((k % height) == 0))
slabheader();
printf(format,
slabs[i].name,
slabs[i].active_objs,
slabs[i].num_objs,
slabs[i].objsize,
slabs[i].objperslab
);
slabs[i].objsize, slabs[i].objperslab);
}
free(slabs);
}
free(fSlab);
}
////////////////////////////////////////////////////////////////////////////
static void disksum_format(void) {
static void disksum_format(void)
{
FILE *fDiskstat;
struct disk_stat *disks;
@ -471,15 +492,16 @@ static void disksum_format(void) {
merged_writes, written_sectors, milli_writing, inprogress_IO,
milli_spent_IO, weighted_milli_spent_IO;
reads=merged_reads=read_sectors=milli_reading=writes=merged_writes= \
written_sectors=milli_writing=inprogress_IO=milli_spent_IO= \
weighted_milli_spent_IO=0;
reads = merged_reads = read_sectors = milli_reading = writes =
merged_writes = written_sectors = milli_writing = inprogress_IO =
milli_spent_IO = weighted_milli_spent_IO = 0;
if ((fDiskstat = fopen("/proc/diskstats", "rb"))) {
fclose(fDiskstat);
ndisks = getdiskstat(&disks, &partitions);
printf(_("%13d disks \n"), ndisks);
printf(_("%13d partitions \n"), getpartitions_num(disks, ndisks));
printf(_("%13d partitions \n"),
getpartitions_num(disks, ndisks));
for (i = 0; i < ndisks; i++) {
reads += disks[i].reads;
@ -510,9 +532,8 @@ static void disksum_format(void) {
}
}
////////////////////////////////////////////////////////////////////////////
static void sum_format(void) {
static void sum_format(void)
{
unsigned int running, blocked, btime, processes;
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
unsigned long pgpgin, pgpgout, pswpin, pswpout;
@ -523,9 +544,7 @@ static void sum_format(void) {
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
&pgpgin, &pgpgout, &pswpin, &pswpout,
&intr, &ctxt,
&running, &blocked,
&btime, &processes);
&intr, &ctxt, &running, &blocked, &btime, &processes);
printf(_("%13lu %s total memory\n"), unitConvert(kb_main_total), szDataUnit);
printf(_("%13lu %s used memory\n"), unitConvert(kb_main_used), szDataUnit);
@ -555,9 +574,8 @@ static void sum_format(void) {
printf(_("%13u forks\n"), processes);
}
////////////////////////////////////////////////////////////////////////////
static void fork_format(void) {
static void fork_format(void)
{
unsigned int running, blocked, btime, processes;
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
unsigned long pgpgin, pgpgout, pswpin, pswpout;
@ -566,16 +584,13 @@ static void fork_format(void) {
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
&pgpgin, &pgpgout, &pswpin, &pswpout,
&intr, &ctxt,
&running, &blocked,
&btime, &processes);
&intr, &ctxt, &running, &blocked, &btime, &processes);
printf(_("%13u forks\n"), processes);
}
////////////////////////////////////////////////////////////////////////////
static int winhi(void) {
static int winhi(void)
{
struct winsize win;
int rows = 24;
@ -585,9 +600,8 @@ static int winhi(void) {
return rows;
}
////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
char *partition = NULL;
int c;
@ -606,7 +620,10 @@ int main(int argc, char *argv[]) {
{NULL, 0, NULL, 0}
};
while((c = getopt_long(argc, argv, "afmnsdDp:S:hV", longopts, NULL)) != EOF) switch(c) {
while ((c =
getopt_long(argc, argv, "afmnsdDp:S:hV", longopts,
NULL)) != EOF)
switch (c) {
case 'V':
printf(PROCPS_NG_VERSION);
return EXIT_SUCCESS;
@ -620,7 +637,7 @@ int main(int argc, char *argv[]) {
a_option = 1;
break;
case 'f':
// FIXME: check for conflicting args
/* FIXME: check for conflicting args */
fork_format();
exit(0);
case 'm':
@ -636,17 +653,31 @@ int main(int argc, char *argv[]) {
case 'p':
statMode |= PARTITIONSTAT;
partition = optarg;
if (memcmp(partition, "/dev/", 5) == 0) partition += 5;
if (memcmp(partition, "/dev/", 5) == 0)
partition += 5;
break;
case 'S':
switch (optarg[0]) {
case 'b': case 'B': dataUnit = UNIT_B; break;
case 'k': dataUnit = UNIT_k; break;
case 'K': dataUnit = UNIT_K; break;
case 'm': dataUnit = UNIT_m; break;
case 'M': dataUnit = UNIT_M; break;
case 'b':
case 'B':
dataUnit = UNIT_B;
break;
case 'k':
dataUnit = UNIT_k;
break;
case 'K':
dataUnit = UNIT_K;
break;
case 'm':
dataUnit = UNIT_m;
break;
case 'M':
dataUnit = UNIT_M;
break;
default:
errx(EXIT_FAILURE, _("-S requires k, K, m or M (default is kb)"));
errx(EXIT_FAILURE,
_
("-S requires k, K, m or M (default is kb)"));
}
szDataUnit[0] = optarg[0];
break;
@ -674,23 +705,28 @@ int main(int argc, char *argv[]) {
}
setlinebuf(stdout);
switch (statMode) {
case(VMSTAT): new_format();
case (VMSTAT):
new_format();
break;
case(VMSUMSTAT): sum_format();
case (VMSUMSTAT):
sum_format();
break;
case(DISKSTAT): diskformat();
case (DISKSTAT):
diskformat();
break;
case(PARTITIONSTAT): if(diskpartition_format(partition)==-1)
case (PARTITIONSTAT):
if (diskpartition_format(partition) == -1)
printf(_("Partition was not found\n"));
break;
case(SLABSTAT): slabformat();
case (SLABSTAT):
slabformat();
break;
case(DISKSUMSTAT): disksum_format();
case (DISKSUMSTAT):
disksum_format();
break;
default: usage(stderr);
default:
usage(stderr);
break;
}
return 0;
}