vmstats: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
7af3d4efce
commit
72e37c7d11
596
vmstat.c
596
vmstat.c
@ -1,32 +1,33 @@
|
|||||||
// old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
|
/* old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
|
||||||
// most code copyright 2002 Albert Cahalan
|
* most code copyright 2002 Albert Cahalan
|
||||||
//
|
*
|
||||||
// 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
|
* 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
|
||||||
// Export proc/stat access to libproc
|
* Export proc/stat access to libproc
|
||||||
// Adapt vmstat helpfile
|
* Adapt vmstat helpfile
|
||||||
// 31/05/2003 (Fabian) : Add diskstat support (/libproc)
|
* 31/05/2003 (Fabian) : Add diskstat support (/libproc)
|
||||||
// June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
|
* June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
|
||||||
// June 2003 (Fabian) : -Adding diskstat against 3.1.9, slabinfo
|
* June 2003 (Fabian) : Adding diskstat against 3.1.9, slabinfo
|
||||||
// -patching 'header' in disk & slab
|
* patching 'header' in disk & slab
|
||||||
// July 2003 (Fabian) : -Adding disk partition output
|
* July 2003 (Fabian) : Adding disk partition output
|
||||||
// -Adding disk table
|
* Adding disk table
|
||||||
// -Syncing help / usage
|
* Syncing help / usage
|
||||||
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <ctype.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/dir.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <getopt.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 "c.h"
|
||||||
#include "nls.h"
|
#include "nls.h"
|
||||||
@ -39,7 +40,7 @@
|
|||||||
#define UNIT_m 1000000
|
#define UNIT_m 1000000
|
||||||
#define UNIT_M 1048576
|
#define UNIT_M 1048576
|
||||||
|
|
||||||
static unsigned long dataUnit=UNIT_K;
|
static unsigned long dataUnit = UNIT_K;
|
||||||
static char szDataUnit[3] = "K";
|
static char szDataUnit[3] = "K";
|
||||||
|
|
||||||
#define VMSTAT 0
|
#define VMSTAT 0
|
||||||
@ -49,22 +50,24 @@ static char szDataUnit[3] = "K";
|
|||||||
#define PARTITIONSTAT 0x00000008
|
#define PARTITIONSTAT 0x00000008
|
||||||
#define DISKSUMSTAT 0x00000010
|
#define DISKSUMSTAT 0x00000010
|
||||||
|
|
||||||
static int statMode=VMSTAT;
|
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 sleep_time = 1;
|
||||||
static unsigned long num_updates;
|
static unsigned long num_updates;
|
||||||
|
/* window height */
|
||||||
static unsigned int height; // window height
|
static unsigned int height;
|
||||||
static unsigned int moreheaders=TRUE;
|
static unsigned int moreheaders = TRUE;
|
||||||
|
|
||||||
static void __attribute__ ((__noreturn__))
|
static void __attribute__ ((__noreturn__))
|
||||||
usage(FILE * out)
|
usage(FILE * out)
|
||||||
{
|
{
|
||||||
fputs(USAGE_HEADER, out);
|
fputs(USAGE_HEADER, out);
|
||||||
fprintf(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(USAGE_OPTIONS, out);
|
||||||
fputs(_(" -a, --active active/inactive memory\n"), out);
|
fputs(_(" -a, --active active/inactive memory\n"), out);
|
||||||
fputs(_(" -f, --forks number of forks since boot\n"), out);
|
fputs(_(" -f, --forks number of forks since boot\n"), out);
|
||||||
@ -84,65 +87,68 @@ static void __attribute__ ((__noreturn__))
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// produce: " 6 ", "123 ", "123k ", etc.
|
/* produce: " 6 ", "123 ", "123k ", etc. */
|
||||||
static int format_1024(unsigned long long val64, char *restrict dst){
|
static int format_1024(unsigned long long val64, char *restrict dst)
|
||||||
|
{
|
||||||
unsigned oldval;
|
unsigned oldval;
|
||||||
const char suffix[] = " kmgtpe";
|
const char suffix[] = " kmgtpe";
|
||||||
unsigned level = 0;
|
unsigned level = 0;
|
||||||
unsigned val32;
|
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;
|
val32 = val64;
|
||||||
return sprintf(dst,"%3u ",val32);
|
return sprintf(dst, "%3u ", val32);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(val64 > 0xffffffffull){
|
while (val64 > 0xffffffffull) {
|
||||||
level++;
|
level++;
|
||||||
val64 /= 1024;
|
val64 /= 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
val32 = val64;
|
val32 = val64;
|
||||||
|
|
||||||
while(val32 > 999){
|
while (val32 > 999) {
|
||||||
level++;
|
level++;
|
||||||
oldval = val32;
|
oldval = val32;
|
||||||
val32 /= 1024;
|
val32 /= 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(val32 < 10){
|
if (val32 < 10) {
|
||||||
unsigned fract = (oldval % 1024) * 10 / 1024;
|
unsigned fract = (oldval % 1024) * 10 / 1024;
|
||||||
return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
|
return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
|
||||||
}
|
}
|
||||||
return sprintf(dst, "%3u%c ", val32, suffix[level]);
|
return sprintf(dst, "%3u%c ", val32, suffix[level]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* produce: " 6 ", "123 ", "123k ", etc. */
|
||||||
// produce: " 6 ", "123 ", "123k ", etc.
|
static int format_1000(unsigned long long val64, char *restrict dst)
|
||||||
static int format_1000(unsigned long long val64, char *restrict dst){
|
{
|
||||||
unsigned oldval;
|
unsigned oldval;
|
||||||
const char suffix[] = " kmgtpe";
|
const char suffix[] = " kmgtpe";
|
||||||
unsigned level = 0;
|
unsigned level = 0;
|
||||||
unsigned val32;
|
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;
|
val32 = val64;
|
||||||
return sprintf(dst,"%3u ",val32);
|
return sprintf(dst, "%3u ", val32);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(val64 > 0xffffffffull){
|
while (val64 > 0xffffffffull) {
|
||||||
level++;
|
level++;
|
||||||
val64 /= 1000;
|
val64 /= 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
val32 = val64;
|
val32 = val64;
|
||||||
|
|
||||||
while(val32 > 999){
|
while (val32 > 999) {
|
||||||
level++;
|
level++;
|
||||||
oldval = val32;
|
oldval = val32;
|
||||||
val32 /= 1000;
|
val32 /= 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(val32 < 10){
|
if (val32 < 10) {
|
||||||
unsigned fract = (oldval % 1000) / 100;
|
unsigned fract = (oldval % 1000) / 100;
|
||||||
return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
|
return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
|
||||||
}
|
}
|
||||||
@ -150,62 +156,56 @@ static int format_1000(unsigned long long val64, char *restrict dst){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void new_header(void)
|
||||||
|
{
|
||||||
static void new_header(void){
|
printf
|
||||||
printf("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
|
("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
|
||||||
printf(
|
printf
|
||||||
"%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s\n",
|
("%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s\n",
|
||||||
"r","b",
|
"r", "b", "swpd", "free", a_option ? "inact" : "buff",
|
||||||
"swpd", "free", a_option?"inact":"buff", a_option?"active":"cache",
|
a_option ? "active" : "cache", "si", "so", "bi", "bo", "in", "cs",
|
||||||
"si","so",
|
"us", "sy", "id", "wa");
|
||||||
"bi","bo",
|
|
||||||
"in","cs",
|
|
||||||
"us","sy","id","wa"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static unsigned long unitConvert(unsigned int size)
|
||||||
|
{
|
||||||
static unsigned long unitConvert(unsigned int size){
|
|
||||||
float cvSize;
|
float cvSize;
|
||||||
cvSize=(float)size/dataUnit*((statMode==SLABSTAT)?1:1024);
|
cvSize = (float)size / dataUnit * ((statMode == SLABSTAT) ? 1 : 1024);
|
||||||
return ((unsigned long) cvSize);
|
return ((unsigned long)cvSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void new_format(void)
|
||||||
|
{
|
||||||
static void new_format(void) {
|
const char format[] =
|
||||||
const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u\n";
|
"%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 tog = 0; /* toggle switch for cleaner code */
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int hz = Hertz;
|
unsigned int hz = Hertz;
|
||||||
unsigned int running,blocked,dummy_1,dummy_2;
|
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;
|
jiff duse, dsys, didl, diow, dstl, Div, divo2;
|
||||||
unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
|
unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
|
||||||
unsigned int intr[2], ctxt[2];
|
unsigned int intr[2], ctxt[2];
|
||||||
unsigned int sleep_half;
|
unsigned int sleep_half;
|
||||||
unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
|
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);
|
sleep_half = (sleep_time / 2);
|
||||||
new_header();
|
new_header();
|
||||||
meminfo();
|
meminfo();
|
||||||
|
|
||||||
getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,cpu_iow,cpu_xxx,cpu_yyy,cpu_zzz,
|
getstat(cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy,
|
||||||
pgpgin,pgpgout,pswpin,pswpout,
|
cpu_zzz, pgpgin, pgpgout, pswpin, pswpout, intr, ctxt, &running,
|
||||||
intr,ctxt,
|
&blocked, &dummy_1, &dummy_2);
|
||||||
&running,&blocked,
|
|
||||||
&dummy_1, &dummy_2);
|
|
||||||
|
|
||||||
duse= *cpu_use + *cpu_nic;
|
duse = *cpu_use + *cpu_nic;
|
||||||
dsys= *cpu_sys + *cpu_xxx + *cpu_yyy;
|
dsys = *cpu_sys + *cpu_xxx + *cpu_yyy;
|
||||||
didl= *cpu_idl;
|
didl = *cpu_idl;
|
||||||
diow= *cpu_iow;
|
diow = *cpu_iow;
|
||||||
dstl= *cpu_zzz;
|
dstl = *cpu_zzz;
|
||||||
Div= duse+dsys+didl+diow+dstl;
|
Div = duse + dsys + didl + diow + dstl;
|
||||||
divo2= Div/2UL;
|
divo2 = Div / 2UL;
|
||||||
printf(format,
|
printf(format,
|
||||||
running, blocked,
|
running, blocked,
|
||||||
unitConvert(kb_swap_used), unitConvert(kb_main_free),
|
unitConvert(kb_swap_used), unitConvert(kb_main_free),
|
||||||
@ -220,117 +220,140 @@ static void new_format(void) {
|
|||||||
(unsigned)( (100*duse + divo2) / Div ),
|
(unsigned)( (100*duse + divo2) / Div ),
|
||||||
(unsigned)( (100*dsys + divo2) / Div ),
|
(unsigned)( (100*dsys + divo2) / Div ),
|
||||||
(unsigned)( (100*didl + divo2) / Div ),
|
(unsigned)( (100*didl + divo2) / Div ),
|
||||||
(unsigned)( (100*diow + divo2) / Div ) /* ,
|
(unsigned)( (100*diow + divo2) / Div )/*,
|
||||||
(unsigned)( (100*dstl + divo2) / Div ) */
|
(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);
|
sleep(sleep_time);
|
||||||
if (moreheaders && ((i%height)==0)) new_header();
|
if (moreheaders && ((i % height) == 0))
|
||||||
tog= !tog;
|
new_header();
|
||||||
|
tog = !tog;
|
||||||
|
|
||||||
meminfo();
|
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,
|
getstat(cpu_use + tog, cpu_nic + tog, cpu_sys + tog,
|
||||||
pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog,
|
cpu_idl + tog, cpu_iow + tog, cpu_xxx + tog,
|
||||||
intr+tog,ctxt+tog,
|
cpu_yyy + tog, cpu_zzz + tog, pgpgin + tog,
|
||||||
&running,&blocked,
|
pgpgout + tog, pswpin + tog, pswpout + tog, intr + tog,
|
||||||
&dummy_1,&dummy_2);
|
ctxt + tog, &running, &blocked, &dummy_1, &dummy_2);
|
||||||
|
|
||||||
duse= cpu_use[tog]-cpu_use[!tog] + cpu_nic[tog]-cpu_nic[!tog];
|
duse =
|
||||||
dsys= cpu_sys[tog]-cpu_sys[!tog] + cpu_xxx[tog]-cpu_xxx[!tog] + cpu_yyy[tog]-cpu_yyy[!tog];
|
cpu_use[tog] - cpu_use[!tog] + cpu_nic[tog] - cpu_nic[!tog];
|
||||||
didl= cpu_idl[tog]-cpu_idl[!tog];
|
dsys =
|
||||||
diow= cpu_iow[tog]-cpu_iow[!tog];
|
cpu_sys[tog] - cpu_sys[!tog] + cpu_xxx[tog] -
|
||||||
dstl= cpu_zzz[tog]-cpu_zzz[!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];
|
||||||
|
|
||||||
/* idle can run backwards for a moment -- kernel "feature" */
|
/* idle can run backwards for a moment -- kernel "feature" */
|
||||||
if(debt){
|
if (debt) {
|
||||||
didl = (int)didl + debt;
|
didl = (int)didl + debt;
|
||||||
debt = 0;
|
debt = 0;
|
||||||
}
|
}
|
||||||
if( (int)didl < 0 ){
|
if ((int)didl < 0) {
|
||||||
debt = (int)didl;
|
debt = (int)didl;
|
||||||
didl = 0;
|
didl = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Div= duse+dsys+didl+diow+dstl;
|
Div = duse + dsys + didl + diow + dstl;
|
||||||
divo2= Div/2UL;
|
divo2 = Div / 2UL;
|
||||||
printf(format,
|
printf(format,
|
||||||
running, blocked,
|
running,
|
||||||
|
blocked,
|
||||||
unitConvert(kb_swap_used),unitConvert(kb_main_free),
|
unitConvert(kb_swap_used),unitConvert(kb_main_free),
|
||||||
unitConvert(a_option?kb_inactive:kb_main_buffers),
|
unitConvert(a_option?kb_inactive:kb_main_buffers),
|
||||||
unitConvert(a_option?kb_active:kb_main_cached),
|
unitConvert(a_option?kb_active:kb_main_cached),
|
||||||
(unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ), /*si*/
|
/*si */
|
||||||
(unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ), /*so*/
|
(unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ),
|
||||||
(unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ), /*bi*/
|
/* so */
|
||||||
(unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ), /*bo*/
|
(unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ),
|
||||||
(unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time ), /*in*/
|
/* bi */
|
||||||
(unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time ), /*cs*/
|
(unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ),
|
||||||
(unsigned)( (100*duse+divo2)/Div ), /*us*/
|
/* bo */
|
||||||
(unsigned)( (100*dsys+divo2)/Div ), /*sy*/
|
(unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ),
|
||||||
(unsigned)( (100*didl+divo2)/Div ), /*id*/
|
/* in */
|
||||||
(unsigned)( (100*diow+divo2)/Div )/*, //wa
|
(unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time ),
|
||||||
(unsigned)( (100*dstl+divo2)/Div ) //st */
|
/* 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)
|
||||||
|
{
|
||||||
static void diskpartition_header(const char *partition_name){
|
printf("%-10s %10s %10s %10s %10s\n", partition_name, _("reads "),
|
||||||
printf("%-10s %10s %10s %10s %10s\n",partition_name, _("reads "), _("read sectors"), _("writes "), _("requested writes"));
|
_("read sectors"), _("writes "), _("requested writes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static int diskpartition_format(const char *partition_name)
|
||||||
|
{
|
||||||
static int diskpartition_format(const char* partition_name){
|
|
||||||
FILE *fDiskstat;
|
FILE *fDiskstat;
|
||||||
struct disk_stat *disks;
|
struct disk_stat *disks;
|
||||||
struct partition_stat *partitions, *current_partition=NULL;
|
struct partition_stat *partitions, *current_partition = NULL;
|
||||||
unsigned long ndisks, j, k, npartitions;
|
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");
|
fDiskstat = fopen("/proc/diskstats", "rb");
|
||||||
if(!fDiskstat)
|
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);
|
fclose(fDiskstat);
|
||||||
ndisks=getdiskstat(&disks,&partitions);
|
ndisks = getdiskstat(&disks, &partitions);
|
||||||
npartitions=getpartitions_num(disks, ndisks);
|
npartitions = getpartitions_num(disks, ndisks);
|
||||||
for(k=0; k<npartitions; k++){
|
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]);
|
current_partition = &(partitions[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!current_partition){
|
if (!current_partition) {
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
diskpartition_header(partition_name);
|
diskpartition_header(partition_name);
|
||||||
printf (format,
|
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);
|
fflush(stdout);
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
for(j=1; j<num_updates; j++){
|
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);
|
sleep(sleep_time);
|
||||||
ndisks=getdiskstat(&disks,&partitions);
|
ndisks = getdiskstat(&disks, &partitions);
|
||||||
npartitions=getpartitions_num(disks, ndisks);
|
npartitions = getpartitions_num(disks, ndisks);
|
||||||
current_partition=NULL;
|
current_partition = NULL;
|
||||||
for(k=0; k<npartitions; k++){
|
for (k = 0; k < npartitions; k++) {
|
||||||
if(!strcmp(partition_name, partitions[k].partition_name)){
|
if (!strcmp
|
||||||
current_partition=&(partitions[k]);
|
(partition_name, partitions[k].partition_name)) {
|
||||||
|
current_partition = &(partitions[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!current_partition){
|
if (!current_partition) {
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf (format,
|
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);
|
fflush(stdout);
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
@ -338,30 +361,31 @@ static int diskpartition_format(const char* partition_name){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void diskheader(void)
|
||||||
|
{
|
||||||
static void diskheader(void){
|
|
||||||
printf(_("disk- ------------reads------------ ------------writes----------- -----IO------\n"));
|
printf(_("disk- ------------reads------------ ------------writes----------- -----IO------\n"));
|
||||||
|
|
||||||
printf("%5s %6s %6s %7s %7s %6s %6s %7s %7s %6s %6s\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;
|
FILE *fDiskstat;
|
||||||
struct disk_stat *disks;
|
struct disk_stat *disks;
|
||||||
struct partition_stat *partitions;
|
struct partition_stat *partitions;
|
||||||
unsigned long ndisks,i,j,k;
|
unsigned long ndisks, i, j, k;
|
||||||
const char format[]="%-5s %6u %6u %7llu %7u %6u %6u %7llu %7u %6u %6u\n";
|
const char format[] = "%-5s %6u %6u %7llu %7u %6u %6u %7llu %7u %6u %6u\n";
|
||||||
if ((fDiskstat=fopen("/proc/diskstats", "rb"))){
|
|
||||||
|
if ((fDiskstat = fopen("/proc/diskstats", "rb"))) {
|
||||||
fclose(fDiskstat);
|
fclose(fDiskstat);
|
||||||
ndisks=getdiskstat(&disks,&partitions);
|
ndisks = getdiskstat(&disks, &partitions);
|
||||||
if (!moreheaders) diskheader();
|
if (!moreheaders)
|
||||||
for(k=0; k<ndisks; k++){
|
diskheader();
|
||||||
if (moreheaders && ((k%height)==0)) diskheader();
|
for (k = 0; k < ndisks; k++) {
|
||||||
|
if (moreheaders && ((k % height) == 0))
|
||||||
|
diskheader();
|
||||||
printf(format,
|
printf(format,
|
||||||
disks[k].disk_name,
|
disks[k].disk_name,
|
||||||
disks[k].reads,
|
disks[k].reads,
|
||||||
@ -372,19 +396,19 @@ static void diskformat(void){
|
|||||||
disks[k].merged_writes,
|
disks[k].merged_writes,
|
||||||
disks[k].written_sectors,
|
disks[k].written_sectors,
|
||||||
disks[k].milli_writing,
|
disks[k].milli_writing,
|
||||||
disks[k].inprogress_IO?disks[k].inprogress_IO/1000:0,
|
disks[k].inprogress_IO ? disks[k].inprogress_IO / 1000 : 0,
|
||||||
disks[k].milli_spent_IO?disks[k].milli_spent_IO/1000:0/*,
|
disks[k].milli_spent_IO ? disks[k].
|
||||||
disks[i].weighted_milli_spent_IO/1000*/
|
milli_spent_IO / 1000 : 0);
|
||||||
);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
for(j=1; j<num_updates; j++){
|
for (j = 1; j < num_updates; j++) {
|
||||||
sleep(sleep_time);
|
sleep(sleep_time);
|
||||||
ndisks=getdiskstat(&disks,&partitions);
|
ndisks = getdiskstat(&disks, &partitions);
|
||||||
for(i=0; i<ndisks; i++,k++){
|
for (i = 0; i < ndisks; i++, k++) {
|
||||||
if (moreheaders && ((k%height)==0)) diskheader();
|
if (moreheaders && ((k % height) == 0))
|
||||||
|
diskheader();
|
||||||
printf(format,
|
printf(format,
|
||||||
disks[i].disk_name,
|
disks[i].disk_name,
|
||||||
disks[i].reads,
|
disks[i].reads,
|
||||||
@ -395,73 +419,70 @@ static void diskformat(void){
|
|||||||
disks[i].merged_writes,
|
disks[i].merged_writes,
|
||||||
disks[i].written_sectors,
|
disks[i].written_sectors,
|
||||||
disks[i].milli_writing,
|
disks[i].milli_writing,
|
||||||
disks[i].inprogress_IO?disks[i].inprogress_IO/1000:0,
|
disks[i].inprogress_IO ? disks[i].inprogress_IO / 1000 : 0,
|
||||||
disks[i].milli_spent_IO?disks[i].milli_spent_IO/1000:0/*,
|
disks[i].milli_spent_IO ? disks[i].
|
||||||
disks[i].weighted_milli_spent_IO/1000*/
|
milli_spent_IO / 1000 : 0);
|
||||||
);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
}
|
}
|
||||||
}else
|
} 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)
|
||||||
|
{
|
||||||
static void slabheader(void){
|
printf("%-24s %6s %6s %6s %6s\n", _("Cache"), _("Num"), _("Total"),
|
||||||
printf("%-24s %6s %6s %6s %6s\n",_("Cache"),_("Num"), _("Total"), _("Size"), _("Pages"));
|
_("Size"), _("Pages"));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void slabformat(void)
|
||||||
|
{
|
||||||
static void slabformat (void){
|
|
||||||
FILE *fSlab;
|
FILE *fSlab;
|
||||||
struct slab_cache *slabs;
|
struct slab_cache *slabs;
|
||||||
unsigned long nSlab,i,j,k;
|
unsigned long nSlab, i, j, k;
|
||||||
const char format[]="%-24s %6u %6u %6u %6u\n";
|
const char format[] = "%-24s %6u %6u %6u %6u\n";
|
||||||
|
|
||||||
fSlab=fopen("/proc/slabinfo", "rb");
|
fSlab = fopen("/proc/slabinfo", "rb");
|
||||||
if(!fSlab){
|
if (!fSlab) {
|
||||||
warnx(_("Your kernel doesn't support slabinfo or your permissions are insufficient."));
|
warnx(_("Your kernel doesn't support slabinfo or your permissions are insufficient."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!moreheaders) slabheader();
|
if (!moreheaders)
|
||||||
|
slabheader();
|
||||||
nSlab = getslabinfo(&slabs);
|
nSlab = getslabinfo(&slabs);
|
||||||
for(k=0; k<nSlab; k++){
|
for (k = 0; k < nSlab; k++) {
|
||||||
if (moreheaders && ((k%height)==0)) slabheader();
|
if (moreheaders && ((k % height) == 0))
|
||||||
|
slabheader();
|
||||||
printf(format,
|
printf(format,
|
||||||
slabs[k].name,
|
slabs[k].name,
|
||||||
slabs[k].active_objs,
|
slabs[k].active_objs,
|
||||||
slabs[k].num_objs,
|
slabs[k].num_objs,
|
||||||
slabs[k].objsize,
|
slabs[k].objsize, slabs[k].objperslab);
|
||||||
slabs[k].objperslab
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
free(slabs);
|
free(slabs);
|
||||||
for(j=1,k=1; j<num_updates; j++) {
|
for (j = 1, k = 1; j < num_updates; j++) {
|
||||||
sleep(sleep_time);
|
sleep(sleep_time);
|
||||||
nSlab = getslabinfo(&slabs);
|
nSlab = getslabinfo(&slabs);
|
||||||
for(i=0; i<nSlab; i++,k++){
|
for (i = 0; i < nSlab; i++, k++) {
|
||||||
if (moreheaders && ((k%height)==0)) slabheader();
|
if (moreheaders && ((k % height) == 0))
|
||||||
|
slabheader();
|
||||||
printf(format,
|
printf(format,
|
||||||
slabs[i].name,
|
slabs[i].name,
|
||||||
slabs[i].active_objs,
|
slabs[i].active_objs,
|
||||||
slabs[i].num_objs,
|
slabs[i].num_objs,
|
||||||
slabs[i].objsize,
|
slabs[i].objsize, slabs[i].objperslab);
|
||||||
slabs[i].objperslab
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
free(slabs);
|
free(slabs);
|
||||||
}
|
}
|
||||||
free(fSlab);
|
free(fSlab);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void disksum_format(void)
|
||||||
|
{
|
||||||
static void disksum_format(void) {
|
|
||||||
|
|
||||||
FILE *fDiskstat;
|
FILE *fDiskstat;
|
||||||
struct disk_stat *disks;
|
struct disk_stat *disks;
|
||||||
@ -471,48 +492,48 @@ static void disksum_format(void) {
|
|||||||
merged_writes, written_sectors, milli_writing, inprogress_IO,
|
merged_writes, written_sectors, milli_writing, inprogress_IO,
|
||||||
milli_spent_IO, weighted_milli_spent_IO;
|
milli_spent_IO, weighted_milli_spent_IO;
|
||||||
|
|
||||||
reads=merged_reads=read_sectors=milli_reading=writes=merged_writes= \
|
reads = merged_reads = read_sectors = milli_reading = writes =
|
||||||
written_sectors=milli_writing=inprogress_IO=milli_spent_IO= \
|
merged_writes = written_sectors = milli_writing = inprogress_IO =
|
||||||
weighted_milli_spent_IO=0;
|
milli_spent_IO = weighted_milli_spent_IO = 0;
|
||||||
|
|
||||||
if ((fDiskstat=fopen("/proc/diskstats", "rb"))){
|
if ((fDiskstat = fopen("/proc/diskstats", "rb"))) {
|
||||||
fclose(fDiskstat);
|
fclose(fDiskstat);
|
||||||
ndisks=getdiskstat(&disks, &partitions);
|
ndisks = getdiskstat(&disks, &partitions);
|
||||||
printf(_("%13d disks \n"), ndisks);
|
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++){
|
for (i = 0; i < ndisks; i++) {
|
||||||
reads+=disks[i].reads;
|
reads += disks[i].reads;
|
||||||
merged_reads+=disks[i].merged_reads;
|
merged_reads += disks[i].merged_reads;
|
||||||
read_sectors+=disks[i].reads_sectors;
|
read_sectors += disks[i].reads_sectors;
|
||||||
milli_reading+=disks[i].milli_reading;
|
milli_reading += disks[i].milli_reading;
|
||||||
writes+=disks[i].writes;
|
writes += disks[i].writes;
|
||||||
merged_writes+=disks[i].merged_writes;
|
merged_writes += disks[i].merged_writes;
|
||||||
written_sectors+=disks[i].written_sectors;
|
written_sectors += disks[i].written_sectors;
|
||||||
milli_writing+=disks[i].milli_writing;
|
milli_writing += disks[i].milli_writing;
|
||||||
inprogress_IO+=disks[i].inprogress_IO?disks[i].inprogress_IO/1000:0;
|
inprogress_IO += disks[i].inprogress_IO ? disks[i].inprogress_IO / 1000 : 0;
|
||||||
milli_spent_IO+=disks[i].milli_spent_IO?disks[i].milli_spent_IO/1000:0;
|
milli_spent_IO += disks[i].milli_spent_IO ? disks[i].milli_spent_IO / 1000 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(_("%13lu total reads\n"),reads);
|
printf(_("%13lu total reads\n"), reads);
|
||||||
printf(_("%13lu merged reads\n"),merged_reads);
|
printf(_("%13lu merged reads\n"), merged_reads);
|
||||||
printf(_("%13lu read sectors\n"),read_sectors);
|
printf(_("%13lu read sectors\n"), read_sectors);
|
||||||
printf(_("%13lu milli reading\n"),milli_reading);
|
printf(_("%13lu milli reading\n"), milli_reading);
|
||||||
printf(_("%13lu writes\n"),writes);
|
printf(_("%13lu writes\n"), writes);
|
||||||
printf(_("%13lu merged writes\n"),merged_writes);
|
printf(_("%13lu merged writes\n"), merged_writes);
|
||||||
printf(_("%13lu written sectors\n"),written_sectors);
|
printf(_("%13lu written sectors\n"), written_sectors);
|
||||||
printf(_("%13lu milli writing\n"),milli_writing);
|
printf(_("%13lu milli writing\n"), milli_writing);
|
||||||
printf(_("%13lu inprogress IO\n"),inprogress_IO);
|
printf(_("%13lu inprogress IO\n"), inprogress_IO);
|
||||||
printf(_("%13lu milli spent IO\n"),milli_spent_IO);
|
printf(_("%13lu milli spent IO\n"), milli_spent_IO);
|
||||||
|
|
||||||
free(disks);
|
free(disks);
|
||||||
free(partitions);
|
free(partitions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void sum_format(void)
|
||||||
|
{
|
||||||
static void sum_format(void) {
|
|
||||||
unsigned int running, blocked, btime, processes;
|
unsigned int running, blocked, btime, processes;
|
||||||
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
|
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
|
||||||
unsigned long pgpgin, pgpgout, pswpin, pswpout;
|
unsigned long pgpgin, pgpgout, pswpin, pswpout;
|
||||||
@ -523,20 +544,18 @@ static void sum_format(void) {
|
|||||||
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
|
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
|
||||||
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
|
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
|
||||||
&pgpgin, &pgpgout, &pswpin, &pswpout,
|
&pgpgin, &pgpgout, &pswpin, &pswpout,
|
||||||
&intr, &ctxt,
|
&intr, &ctxt, &running, &blocked, &btime, &processes);
|
||||||
&running, &blocked,
|
|
||||||
&btime, &processes);
|
|
||||||
|
|
||||||
printf(_("%13lu %s total memory\n"), unitConvert(kb_main_total),szDataUnit);
|
printf(_("%13lu %s total memory\n"), unitConvert(kb_main_total), szDataUnit);
|
||||||
printf(_("%13lu %s used memory\n"), unitConvert(kb_main_used),szDataUnit);
|
printf(_("%13lu %s used memory\n"), unitConvert(kb_main_used), szDataUnit);
|
||||||
printf(_("%13lu %s active memory\n"), unitConvert(kb_active),szDataUnit);
|
printf(_("%13lu %s active memory\n"), unitConvert(kb_active), szDataUnit);
|
||||||
printf(_("%13lu %s inactive memory\n"), unitConvert(kb_inactive),szDataUnit);
|
printf(_("%13lu %s inactive memory\n"), unitConvert(kb_inactive), szDataUnit);
|
||||||
printf(_("%13lu %s free memory\n"), unitConvert(kb_main_free),szDataUnit);
|
printf(_("%13lu %s free memory\n"), unitConvert(kb_main_free), szDataUnit);
|
||||||
printf(_("%13lu %s buffer memory\n"), unitConvert(kb_main_buffers),szDataUnit);
|
printf(_("%13lu %s buffer memory\n"), unitConvert(kb_main_buffers), szDataUnit);
|
||||||
printf(_("%13lu %s swap cache\n"), unitConvert(kb_main_cached),szDataUnit);
|
printf(_("%13lu %s swap cache\n"), unitConvert(kb_main_cached), szDataUnit);
|
||||||
printf(_("%13lu %s total swap\n"), unitConvert(kb_swap_total),szDataUnit);
|
printf(_("%13lu %s total swap\n"), unitConvert(kb_swap_total), szDataUnit);
|
||||||
printf(_("%13lu %s used swap\n"), unitConvert(kb_swap_used),szDataUnit);
|
printf(_("%13lu %s used swap\n"), unitConvert(kb_swap_used), szDataUnit);
|
||||||
printf(_("%13lu %s free swap\n"), unitConvert(kb_swap_free),szDataUnit);
|
printf(_("%13lu %s free swap\n"), unitConvert(kb_swap_free), szDataUnit);
|
||||||
printf(_("%13Lu non-nice user cpu ticks\n"), cpu_use);
|
printf(_("%13Lu non-nice user cpu ticks\n"), cpu_use);
|
||||||
printf(_("%13Lu nice user cpu ticks\n"), cpu_nic);
|
printf(_("%13Lu nice user cpu ticks\n"), cpu_nic);
|
||||||
printf(_("%13Lu system cpu ticks\n"), cpu_sys);
|
printf(_("%13Lu system cpu ticks\n"), cpu_sys);
|
||||||
@ -555,9 +574,8 @@ static void sum_format(void) {
|
|||||||
printf(_("%13u forks\n"), processes);
|
printf(_("%13u forks\n"), processes);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static void fork_format(void)
|
||||||
|
{
|
||||||
static void fork_format(void) {
|
|
||||||
unsigned int running, blocked, btime, processes;
|
unsigned int running, blocked, btime, processes;
|
||||||
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
|
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
|
||||||
unsigned long pgpgin, pgpgout, pswpin, pswpout;
|
unsigned long pgpgin, pgpgout, pswpin, pswpout;
|
||||||
@ -566,16 +584,13 @@ static void fork_format(void) {
|
|||||||
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
|
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
|
||||||
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
|
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
|
||||||
&pgpgin, &pgpgout, &pswpin, &pswpout,
|
&pgpgin, &pgpgout, &pswpin, &pswpout,
|
||||||
&intr, &ctxt,
|
&intr, &ctxt, &running, &blocked, &btime, &processes);
|
||||||
&running, &blocked,
|
|
||||||
&btime, &processes);
|
|
||||||
|
|
||||||
printf(_("%13u forks\n"), processes);
|
printf(_("%13u forks\n"), processes);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
static int winhi(void)
|
||||||
|
{
|
||||||
static int winhi(void) {
|
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
int rows = 24;
|
int rows = 24;
|
||||||
|
|
||||||
@ -585,9 +600,8 @@ static int winhi(void) {
|
|||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
char *partition = NULL;
|
char *partition = NULL;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@ -606,7 +620,10 @@ int main(int argc, char *argv[]) {
|
|||||||
{NULL, 0, NULL, 0}
|
{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':
|
case 'V':
|
||||||
printf(PROCPS_NG_VERSION);
|
printf(PROCPS_NG_VERSION);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@ -617,10 +634,10 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
/* active/inactive mode */
|
/* active/inactive mode */
|
||||||
a_option=1;
|
a_option = 1;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
// FIXME: check for conflicting args
|
/* FIXME: check for conflicting args */
|
||||||
fork_format();
|
fork_format();
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'm':
|
case 'm':
|
||||||
@ -631,22 +648,36 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
/* print only one header */
|
/* print only one header */
|
||||||
moreheaders=FALSE;
|
moreheaders = FALSE;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
statMode |= PARTITIONSTAT;
|
statMode |= PARTITIONSTAT;
|
||||||
partition = optarg;
|
partition = optarg;
|
||||||
if (memcmp(partition, "/dev/", 5) == 0) partition += 5;
|
if (memcmp(partition, "/dev/", 5) == 0)
|
||||||
|
partition += 5;
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
switch(optarg[0]) {
|
switch (optarg[0]) {
|
||||||
case 'b': case 'B': dataUnit = UNIT_B; break;
|
case 'b':
|
||||||
case 'k': dataUnit = UNIT_k; break;
|
case 'B':
|
||||||
case 'K': dataUnit = UNIT_K; break;
|
dataUnit = UNIT_B;
|
||||||
case 'm': dataUnit = UNIT_m; break;
|
break;
|
||||||
case 'M': dataUnit = UNIT_M; 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:
|
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];
|
szDataUnit[0] = optarg[0];
|
||||||
break;
|
break;
|
||||||
@ -669,28 +700,33 @@ int main(int argc, char *argv[]) {
|
|||||||
usage(stderr);
|
usage(stderr);
|
||||||
|
|
||||||
if (moreheaders) {
|
if (moreheaders) {
|
||||||
int tmp=winhi()-3;
|
int tmp = winhi() - 3;
|
||||||
height=((tmp>0)?tmp:22);
|
height = ((tmp > 0) ? tmp : 22);
|
||||||
}
|
}
|
||||||
setlinebuf(stdout);
|
setlinebuf(stdout);
|
||||||
switch(statMode){
|
switch (statMode) {
|
||||||
case(VMSTAT): new_format();
|
case (VMSTAT):
|
||||||
|
new_format();
|
||||||
break;
|
break;
|
||||||
case(VMSUMSTAT): sum_format();
|
case (VMSUMSTAT):
|
||||||
|
sum_format();
|
||||||
break;
|
break;
|
||||||
case(DISKSTAT): diskformat();
|
case (DISKSTAT):
|
||||||
|
diskformat();
|
||||||
break;
|
break;
|
||||||
case(PARTITIONSTAT): if(diskpartition_format(partition)==-1)
|
case (PARTITIONSTAT):
|
||||||
|
if (diskpartition_format(partition) == -1)
|
||||||
printf(_("Partition was not found\n"));
|
printf(_("Partition was not found\n"));
|
||||||
break;
|
break;
|
||||||
case(SLABSTAT): slabformat();
|
case (SLABSTAT):
|
||||||
|
slabformat();
|
||||||
break;
|
break;
|
||||||
case(DISKSUMSTAT): disksum_format();
|
case (DISKSUMSTAT):
|
||||||
|
disksum_format();
|
||||||
break;
|
break;
|
||||||
default: usage(stderr);
|
default:
|
||||||
|
usage(stderr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user