Headers for disk and slab info and getopt replacement
Author: Liu Xing <liuxing@cn.fujitsu.com> Author: Michael Tokarev <mjt@corpit.ru> Bug-Debian: http://bugs.debian.org/436805 Bug-Debian: http://bugs.debian.org/408088
This commit is contained in:
parent
63b6a8fcbf
commit
8f466aa21d
66
vmstat.c
66
vmstat.c
@ -29,14 +29,15 @@
|
|||||||
#include "proc/sysinfo.h"
|
#include "proc/sysinfo.h"
|
||||||
#include "proc/version.h"
|
#include "proc/version.h"
|
||||||
|
|
||||||
static unsigned long dataUnit=1024;
|
|
||||||
static char szDataUnit [16];
|
|
||||||
#define UNIT_B 1
|
#define UNIT_B 1
|
||||||
#define UNIT_k 1000
|
#define UNIT_k 1000
|
||||||
#define UNIT_K 1024
|
#define UNIT_K 1024
|
||||||
#define UNIT_m 1000000
|
#define UNIT_m 1000000
|
||||||
#define UNIT_M 1048576
|
#define UNIT_M 1048576
|
||||||
|
|
||||||
|
static unsigned long dataUnit=UNIT_K;
|
||||||
|
static char szDataUnit[3] = "K";
|
||||||
|
|
||||||
#define VMSTAT 0
|
#define VMSTAT 0
|
||||||
#define DISKSTAT 0x00000001
|
#define DISKSTAT 0x00000001
|
||||||
#define VMSUMSTAT 0x00000002
|
#define VMSUMSTAT 0x00000002
|
||||||
@ -354,6 +355,7 @@ static void diskformat(void){
|
|||||||
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();
|
||||||
for(k=0; k<ndisks; k++){
|
for(k=0; k<ndisks; k++){
|
||||||
if (moreheaders && ((k%height)==0)) diskheader();
|
if (moreheaders && ((k%height)==0)) diskheader();
|
||||||
printf(format,
|
printf(format,
|
||||||
@ -424,6 +426,7 @@ static void slabformat (void){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
@ -582,12 +585,10 @@ static int winhi(void) {
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char partition[16];
|
char *partition = NULL;
|
||||||
argc=0; /* redefined as number of integer arguments */
|
int c;
|
||||||
for (argv++;*argv;argv++) {
|
|
||||||
if ('-' ==(**argv)) {
|
|
||||||
switch (*(++(*argv))) {
|
|
||||||
|
|
||||||
|
while((c = getopt(argc, argv, "VdafmDnp:S:s")) != EOF) switch(c) {
|
||||||
case 'V':
|
case 'V':
|
||||||
display_version();
|
display_version();
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -614,29 +615,21 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
statMode |= PARTITIONSTAT;
|
statMode |= PARTITIONSTAT;
|
||||||
if (argv[1]){
|
partition = optarg;
|
||||||
char *cp = *++argv;
|
if (memcmp(partition, "/dev/", 5) == 0) partition += 5;
|
||||||
if(!memcmp(cp,"/dev/",5)) cp += 5;
|
|
||||||
snprintf(partition, sizeof partition, "%s", cp);
|
|
||||||
}else{
|
|
||||||
fprintf(stderr, "-p requires an argument\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
if (argv[1]){
|
switch(optarg[0]) {
|
||||||
++argv;
|
case 'b': case 'B': dataUnit = UNIT_B; break;
|
||||||
if (!strcmp(*argv, "k")) dataUnit=UNIT_k;
|
case 'k': dataUnit = UNIT_k; break;
|
||||||
else if (!strcmp(*argv, "K")) dataUnit=UNIT_K;
|
case 'K': dataUnit = UNIT_K; break;
|
||||||
else if (!strcmp(*argv, "m")) dataUnit=UNIT_m;
|
case 'm': dataUnit = UNIT_m; break;
|
||||||
else if (!strcmp(*argv, "M")) dataUnit=UNIT_M;
|
case 'M': dataUnit = UNIT_M; break;
|
||||||
else {fprintf(stderr, "-S requires k, K, m or M (default is kb)\n");
|
default:
|
||||||
exit(EXIT_FAILURE);
|
fprintf(stderr, "-S requires k, K, m or M (default is kb)\n");
|
||||||
}
|
|
||||||
strcpy(szDataUnit, *argv);
|
|
||||||
}else {fprintf(stderr, "-S requires an argument\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
szDataUnit[0] = optarg[0];
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
statMode |= VMSUMSTAT;
|
statMode |= VMSUMSTAT;
|
||||||
@ -645,22 +638,17 @@ int main(int argc, char *argv[]) {
|
|||||||
/* no other aguments defined yet. */
|
/* no other aguments defined yet. */
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
argc++;
|
if (optind < argc) {
|
||||||
switch (argc) {
|
if ((sleep_time = atoi(argv[optind++])) == 0)
|
||||||
case 1:
|
|
||||||
if ((sleep_time = atoi(*argv)) == 0)
|
|
||||||
usage();
|
usage();
|
||||||
num_updates = ULONG_MAX;
|
num_updates = ULONG_MAX;
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
num_updates = atol(*argv);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
usage();
|
|
||||||
} /* switch */
|
|
||||||
}
|
}
|
||||||
}
|
if (optind < argc)
|
||||||
|
num_updates = atol(argv[optind++]);
|
||||||
|
if (optind < argc)
|
||||||
|
usage();
|
||||||
|
|
||||||
if (moreheaders) {
|
if (moreheaders) {
|
||||||
int tmp=winhi()-3;
|
int tmp=winhi()-3;
|
||||||
height=((tmp>0)?tmp:22);
|
height=((tmp>0)?tmp:22);
|
||||||
|
Loading…
Reference in New Issue
Block a user