Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 293088 Details for
Bug 430424
Redeem "vmstat.c" source.
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Unified diff for vmstat.c
vmstat.diff (text/plain), 24.76 KB, created by
David Tonhofer
on 2008-01-27 22:53:59 UTC
(
hide
)
Description:
Unified diff for vmstat.c
Filename:
MIME Type:
Creator:
David Tonhofer
Created:
2008-01-27 22:53:59 UTC
Size:
24.76 KB
patch
obsolete
>--- procps-3.2.3.orig/vmstat.c 2008-01-27 20:32:17.000000000 +0000 >+++ procps-3.2.3/vmstat.c 2008-01-27 22:37:19.000000000 +0000 >@@ -5,12 +5,16 @@ > // 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 >+// 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 >+// January 2007 (DaTo) : Usage output corrected >+// Additional comments >+// Denial of multiple simultaneous modes >+// Cleaned up some global variables > > #include <stdio.h> > #include <stdlib.h> >@@ -28,52 +32,64 @@ > #include "proc/sysinfo.h" > #include "proc/version.h" > >-static unsigned long dataUnit=1024; >-static char szDataUnit [16]; > #define UNIT_B 1 > #define UNIT_k 1000 > #define UNIT_K 1024 > #define UNIT_m 1000000 > #define UNIT_M 1048576 > >-#define VMSTAT 0 >+#define VMSTAT 0x00000000 > #define DISKSTAT 0x00000001 > #define VMSUMSTAT 0x00000002 > #define SLABSTAT 0x00000004 > #define PARTITIONSTAT 0x00000008 > #define DISKSUMSTAT 0x00000010 >- >-static int statMode=VMSTAT; >+#define FORKSTAT 0x00000020 > > #define FALSE 0 >-#define TRUE 1 >+#define TRUE 1 > >-static int a_option; /* "-a" means "show active/inactive" */ >+static int statMode=VMSTAT; > > static unsigned sleep_time = 1; >-static unsigned long num_updates; > > static unsigned int height; // window height > static unsigned int moreheaders=TRUE; > >+///////////////////////////////////////////////////////////////////////// >+// Count bits set in 32 bit number using the MIT HAKMEM count >+ >+static int count32Bits(unsigned int u) { >+ unsigned int uCount; >+ uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111); >+ return ((uCount + (uCount >> 3)) & 030707070707) % 63; >+} > > ///////////////////////////////////////////////////////////////////////// > > static void usage(void) NORETURN; > static void usage(void) { >- fprintf(stderr,"usage: vmstat [-V] [-n] [delay [count]]\n"); >- fprintf(stderr," -V prints version.\n"); >- fprintf(stderr," -n causes the headers not to be reprinted regularly.\n"); >- fprintf(stderr," -a print inactive/active page stats.\n"); >- fprintf(stderr," -d prints disk statistics\n"); >- fprintf(stderr," -D prints disk table\n"); >- fprintf(stderr," -p prints disk partition statistics\n"); >- fprintf(stderr," -s prints vm table\n"); >- fprintf(stderr," -m prints slabinfo\n"); >- fprintf(stderr," -S unit size\n"); >- fprintf(stderr," delay is the delay between updates in seconds. \n"); >- fprintf(stderr," unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)\n"); >- fprintf(stderr," count is the number of updates.\n"); >+ // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 >+ fprintf(stderr,"Usage: vmstat [options] [delay [count]]\n"); >+ fprintf(stderr," Mode selection:\n"); >+ fprintf(stderr," default : prints VM stats with 'buffer/page cache' sizes.\n"); >+ fprintf(stderr," -a : prints VM stats with 'inactive/active pages'.\n"); >+ fprintf(stderr," -d : prints disk stats.\n"); >+ fprintf(stderr," -D : prints disk table.\n"); >+ fprintf(stderr," -p part : prints disk partition stats. 'part' is chosen from\n"); >+ fprintf(stderr," the '/proc/diskstats' file.\n"); >+ fprintf(stderr," -s : prints VM table.\n"); >+ fprintf(stderr," -m : prints slabinfo.\n"); >+ fprintf(stderr," -f : prints the number of forks since boot.\n"); >+ fprintf(stderr," -V : prints version number only.\n"); >+ fprintf(stderr," Additional options:\n"); >+ fprintf(stderr," -S unit : sets the unit size. Allowed are k=10^3, K=2^10,\n"); >+ fprintf(stderr," m=10^6, M=2^20. Default is K.\n"); >+ fprintf(stderr," This is relevant only for default mode and -a and -s.\n"); >+ fprintf(stderr," Regularly updated display:\n"); >+ fprintf(stderr," -n : causes the header not to be reprinted regularly.\n"); >+ fprintf(stderr," 'delay' : is the delay between updates in seconds. Default is 1.\n"); >+ fprintf(stderr," 'count' : is the number of updates desired. Default is ULONG_MAX.\n"); > exit(EXIT_FAILURE); > } > >@@ -148,7 +164,7 @@ > > //////////////////////////////////////////////////////////////////////////// > >-static void new_header(void){ >+static void new_header(int a_option){ > printf("procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----\n"); > printf( > "%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %5s %2s %2s %2s %2s\n", >@@ -163,106 +179,137 @@ > > //////////////////////////////////////////////////////////////////////////// > >-static unsigned long unitConvert(unsigned int size){ >- float cvSize; >- cvSize=(float)size/dataUnit*((statMode==SLABSTAT)?1:1024); >+static unsigned long unitConvert(unsigned int size_KiB,unsigned long dataUnit) { >+ // Never called if SLABSTAT >+ // cvSize=(float)size/dataUnit*((statMode==SLABSTAT)?1:1024); >+ float cvSize=(((float)size_KiB)*1024)/((float)dataUnit); > return ((unsigned long) cvSize); > } > > //////////////////////////////////////////////////////////////////////////// > >-static void new_format(void) { >+static void new_format(const int a_option,const unsigned long num_updates,unsigned long dataUnit) { > const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %5u %2u %2u %2u %2u\n"; >- unsigned int tog=0; /* toggle switch for cleaner code */ >+ unsigned int tog=0; /* toggle switch for cleaner code; index of the 2-value jiffy arrays */ > 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]; >- jiff duse, dsys, didl, diow, Div, divo2; >- unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2]; >+ // values obtained: >+ jiff cpu_user[2], cpu_nice[2], cpu_system[2], cpu_idle[2], cpu_iowait[2], cpu_irq[2], cpu_softirq[2]; >+ // delta values for the above: >+ jiff duser, dsystem, didle, diowait; >+ jiff Div, divo2; >+ unsigned long long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2]; > unsigned int intr[2], ctxt[2]; >+ // delta values for the above: >+ unsigned long long dpswpin,dpswpout,dpgpgin,dpgpgout; >+ unsigned int dintr,dctxt; > unsigned int sleep_half; > unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul; > int debt = 0; // handle idle ticks running backwards > > sleep_half=(sleep_time/2); >- new_header(); >+ new_header(a_option); >+ >+ /* The Beef 1: Slurp data from "/proc/meminfo" into global variables (see proc/sysinfo.c)*/ > meminfo(); > >- getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,cpu_iow,cpu_xxx,cpu_yyy, >+ /* The Beef 2: Slurp data from "/proc/stat" into the passed variables (see proc/sysinfo.c). >+ * This will probably snowball into reading "/proc/stat" into global variables, >+ * some of which are copied into the passed variables, and may even lead to >+ * a scan of "/proc" for running processes on some kernels. */ >+ getstat(cpu_user,cpu_nice,cpu_system,cpu_idle,cpu_iowait,cpu_irq,cpu_softirq, > pgpgin,pgpgout,pswpin,pswpout, > intr,ctxt, > &running,&blocked, > &dummy_1, &dummy_2); > >- duse= *cpu_use + *cpu_nic; >- dsys= *cpu_sys + *cpu_xxx + *cpu_yyy; >- didl= *cpu_idl; >- diow= *cpu_iow; >- Div= duse+dsys+didl+diow; >- divo2= Div/2UL; >+ /* ----------------------------------------- */ >+ /* First line shows values since system boot */ >+ duser = *cpu_user + *cpu_nice; >+ dsystem = *cpu_system + *cpu_irq + *cpu_softirq; >+ didle = *cpu_idle; >+ diowait = *cpu_iowait; >+ dpswpin = *pswpin * unitConvert(kb_per_page,dataUnit) * hz; >+ dpswpout = *pswpout * unitConvert(kb_per_page,dataUnit) * hz; >+ dpgpgin = *pgpgin * hz; >+ dpgpgout = *pgpgout * hz; >+ dintr = *intr * hz; >+ dctxt = *ctxt * hz; >+ Div = duser + dsystem + didle + diowait; >+ divo2 = Div/2UL; > printf(format, > 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 * unitConvert(kb_per_page) * hz + divo2) / Div ), >- (unsigned)( (*pswpout * unitConvert(kb_per_page) * hz + divo2) / Div ), >- (unsigned)( (*pgpgin * hz + divo2) / Div ), >- (unsigned)( (*pgpgout * hz + divo2) / Div ), >- (unsigned)( (*intr * hz + divo2) / Div ), >- (unsigned)( (*ctxt * hz + divo2) / Div ), >- (unsigned)( (100*duse + divo2) / Div ), >- (unsigned)( (100*dsys + divo2) / Div ), >- (unsigned)( (100*didl + divo2) / Div ), >- (unsigned)( (100*diow + divo2) / Div ) >+ unitConvert(kb_swap_used,dataUnit), >+ unitConvert(kb_main_free,dataUnit), >+ unitConvert(a_option?kb_inactive:kb_main_buffers,dataUnit), >+ unitConvert(a_option?kb_active:kb_main_cached,dataUnit), >+ (unsigned)( (dpswpin + divo2) / Div ), >+ (unsigned)( (dpswpout + divo2) / Div ), >+ (unsigned)( (dpgpgin + divo2) / Div ), >+ (unsigned)( (dpgpgout + divo2) / Div ), >+ (unsigned)( (dintr + divo2) / Div ), >+ (unsigned)( (dctxt + divo2) / Div ), >+ (unsigned)( (100*duser + divo2) / Div ), >+ (unsigned)( (100*dsystem + divo2) / Div ), >+ (unsigned)( (100*didle + divo2) / Div ), >+ (unsigned)( (100*diowait + divo2) / Div ) > ); > >- for(i=1;i<num_updates;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */ >+ /* ------------------------------- */ >+ /* Additional lines show in a 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(a_option); > tog= !tog; > >+ /* Obtain additional pounds of Beef */ > meminfo(); >- >- getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog,cpu_iow+tog,cpu_xxx+tog,cpu_yyy+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]; >- didl= cpu_idl[tog]-cpu_idl[!tog]; >- diow= cpu_iow[tog]-cpu_iow[!tog]; >+ getstat(cpu_user+tog,cpu_nice+tog,cpu_system+tog,cpu_idle+tog,cpu_iowait+tog,cpu_irq+tog,cpu_softirq+tog, >+ pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog, >+ intr+tog,ctxt+tog, >+ &running,&blocked, >+ &dummy_1,&dummy_2); >+ >+ /* Compute deltas */ >+ duser = (cpu_user[tog] - cpu_user[!tog]) + (cpu_nice[tog] - cpu_nice[!tog]); >+ dsystem = (cpu_system[tog] - cpu_system[!tog]) + (cpu_irq[tog] - cpu_irq[!tog]) + (cpu_softirq[tog] - cpu_softirq[!tog]); >+ didle = (cpu_idle[tog] - cpu_idle[!tog]); >+ diowait = (cpu_iowait[tog] - cpu_iowait[!tog]); >+ dpswpin = (pswpin [tog] - pswpin [!tog]) * unitConvert(kb_per_page,dataUnit); >+ dpswpout = (pswpout[tog] - pswpout[!tog]) * unitConvert(kb_per_page,dataUnit); >+ dpgpgin = (pgpgin [tog] - pgpgin [!tog]); >+ dpgpgout = (pgpgout[tog] - pgpgout[!tog]); >+ dintr = (intr [tog] - intr [!tog]); >+ dctxt = (ctxt [tog] - ctxt [!tog]); > > /* idle can run backwards for a moment -- kernel "feature" */ > if(debt){ >- didl = (int)didl + debt; >+ didle = (int)didle + debt; > debt = 0; > } >- if( (int)didl < 0 ){ >- debt = (int)didl; >- didl = 0; >+ if( (int)didle < 0 ){ >+ debt = (int)didle; >+ didle = 0; > } >- >- Div= duse+dsys+didl+diow; >- divo2= Div/2UL; >+ Div = duser + dsystem + didle + diowait; >+ divo2 = Div/2UL; > printf(format, > 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*/ >+ unitConvert(kb_swap_used,dataUnit), >+ unitConvert(kb_main_free,dataUnit), >+ unitConvert(a_option?kb_inactive:kb_main_buffers,dataUnit), >+ unitConvert(a_option?kb_active:kb_main_cached,dataUnit), >+ (unsigned)( (dpswpin + sleep_half )/sleep_time ), /*si*/ >+ (unsigned)( (dpswpout + sleep_half )/sleep_time ), /*so*/ >+ (unsigned)( (dpgpgin + sleep_half )/sleep_time ), /*bi*/ >+ (unsigned)( (dpgpgout + sleep_half )/sleep_time ), /*bo*/ >+ (unsigned)( (dintr + sleep_half )/sleep_time ), /*in*/ >+ (unsigned)( (dctxt + sleep_half )/sleep_time ), /*cs*/ >+ (unsigned)( (100*duser + divo2)/Div ), /*us*/ >+ (unsigned)( (100*dsystem + divo2)/Div ), /*sy*/ >+ (unsigned)( (100*didle + divo2)/Div ), /*id*/ >+ (unsigned)( (100*diowait + divo2)/Div ) /*wa*/ > ); > } > } >@@ -275,7 +322,7 @@ > > //////////////////////////////////////////////////////////////////////////// > >-static int diskpartition_format(const char* partition_name){ >+static int diskpartition_format(const char* partition_name,const unsigned long num_updates){ > FILE *fDiskstat; > struct disk_stat *disks; > struct partition_stat *partitions, *current_partition=NULL; >@@ -340,7 +387,7 @@ > > //////////////////////////////////////////////////////////////////////////// > >-static void diskformat(void){ >+static void diskformat(const unsigned long num_updates){ > FILE *fDiskstat; > struct disk_stat *disks; > struct partition_stat *partitions; >@@ -407,7 +454,7 @@ > > //////////////////////////////////////////////////////////////////////////// > >-static void slabformat (void){ >+static void slabformat (const unsigned long num_updates){ > FILE *fSlab; > struct slab_cache *slabs; > unsigned long nSlab,i,j,k; >@@ -501,41 +548,42 @@ > > //////////////////////////////////////////////////////////////////////////// > >-static void sum_format(void) { >+static void sum_format(const unsigned long dataUnit,const char *szDataUnit) { > unsigned int running, blocked, btime, processes; >- jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy; >- unsigned long pgpgin, pgpgout, pswpin, pswpout; >+ jiff cpu_user, cpu_nice, cpu_system, cpu_idle, cpu_iowait, cpu_irq, cpu_softirq; >+ unsigned long long pgpgin, pgpgout, pswpin, pswpout; > unsigned int intr, ctxt; > >+ /* slurp /proc/meminfo into global variables */ > meminfo(); > >- getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl, &cpu_iow, &cpu_xxx, &cpu_yyy, >+ getstat(&cpu_user, &cpu_nice, &cpu_system, &cpu_idle, &cpu_iowait, &cpu_irq, &cpu_softirq, > &pgpgin, &pgpgout, &pswpin, &pswpout, > &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); >- printf("%13lu %s active memory\n", unitConvert(kb_active),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 buffer memory\n", unitConvert(kb_main_buffers),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 used swap\n", unitConvert(kb_swap_used),szDataUnit); >- printf("%13lu %s free swap\n", unitConvert(kb_swap_free),szDataUnit); >- printf("%13Lu non-nice user cpu ticks\n", cpu_use); >- printf("%13Lu nice user cpu ticks\n", cpu_nic); >- printf("%13Lu system cpu ticks\n", cpu_sys); >- printf("%13Lu idle cpu ticks\n", cpu_idl); >- printf("%13Lu IO-wait cpu ticks\n", cpu_iow); >- printf("%13Lu IRQ cpu ticks\n", cpu_xxx); >- printf("%13Lu softirq cpu ticks\n", cpu_yyy); >- printf("%13lu pages paged in\n", pgpgin); >- printf("%13lu pages paged out\n", pgpgout); >- printf("%13lu pages swapped in\n", pswpin); >- printf("%13lu pages swapped out\n", pswpout); >+ printf("%13lu %s total memory\n", unitConvert(kb_main_total,dataUnit),szDataUnit); >+ printf("%13lu %s used memory\n", unitConvert(kb_main_used,dataUnit),szDataUnit); >+ printf("%13lu %s active memory\n", unitConvert(kb_active,dataUnit),szDataUnit); >+ printf("%13lu %s inactive memory\n", unitConvert(kb_inactive,dataUnit),szDataUnit); >+ printf("%13lu %s free memory\n", unitConvert(kb_main_free,dataUnit),szDataUnit); >+ printf("%13lu %s buffer memory\n", unitConvert(kb_main_buffers,dataUnit),szDataUnit); >+ printf("%13lu %s swap cache\n", unitConvert(kb_main_cached,dataUnit),szDataUnit); >+ printf("%13lu %s total swap\n", unitConvert(kb_swap_total,dataUnit),szDataUnit); >+ printf("%13lu %s used swap\n", unitConvert(kb_swap_used,dataUnit),szDataUnit); >+ printf("%13lu %s free swap\n", unitConvert(kb_swap_free,dataUnit),szDataUnit); >+ printf("%13Lu non-nice user cpu ticks\n", cpu_user); >+ printf("%13Lu nice user cpu ticks\n", cpu_nice); >+ printf("%13Lu system cpu ticks\n", cpu_system); >+ printf("%13Lu idle cpu ticks\n", cpu_idle); >+ printf("%13Lu IO-wait cpu ticks\n", cpu_iowait); >+ printf("%13Lu IRQ cpu ticks\n", cpu_irq); >+ printf("%13Lu softirq cpu ticks\n", cpu_softirq); >+ printf("%13llu pages paged in\n", pgpgin); >+ printf("%13llu pages paged out\n", pgpgout); >+ printf("%13llu pages swapped in\n", pswpin); >+ printf("%13llu pages swapped out\n", pswpout); > printf("%13u interrupts\n", intr); > printf("%13u CPU context switches\n", ctxt); > printf("%13u boot time\n", btime); >@@ -546,11 +594,11 @@ > > 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; >- unsigned long pgpgin, pgpgout, pswpin, pswpout; >+ jiff cpu_user, cpu_nice, cpu_system, cpu_idle, cpu_iowait, cpu_irq, cpu_softirq; >+ unsigned long long pgpgin, pgpgout, pswpin, pswpout; > unsigned int intr, ctxt; > >- getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl, &cpu_iow, &cpu_xxx, &cpu_yyy, >+ getstat(&cpu_user, &cpu_nice, &cpu_system, &cpu_idle, &cpu_iowait, &cpu_irq, &cpu_softirq, > &pgpgin, &pgpgout, &pswpin, &pswpout, > &intr, &ctxt, > &running, &blocked, >@@ -574,30 +622,38 @@ > //////////////////////////////////////////////////////////////////////////// > > int main(int argc, char *argv[]) { >- char partition[16]; >- argc=0; /* redefined as number of integer arguments */ >+ char partition[16]; /* name of partition to read (if any) */ >+ unsigned long dataUnit=UNIT_K; /* KiB is default unit */ >+ const char *szDataUnit = "KiB"; >+ int a_option=FALSE; /* "-a" means "show active/inactive" in default display mode */ >+ unsigned long num_updates=0; /* No repeats by default */ >+ int intargc=0; /* number of integer arguments */ >+ argc=argc; /* argc is not used */ > for (argv++;*argv;argv++) { > if ('-' ==(**argv)) { >- switch (*(++(*argv))) { >- >+ switch (*(++(*argv))) { > case 'V': >+ /* version only and exit */ > display_version(); > exit(0); > case 'd': >+ /* prepare for diskstats */ > statMode |= DISKSTAT; > break; > case 'a': >- /* active/inactive mode */ >- a_option=1; >+ /* active/inactive submode of default mode */ >+ a_option=TRUE; > break; > case 'f': >- // FIXME: check for conflicting args >- fork_format(); >- exit(0); >+ /* prepare for fork display */ >+ statMode |= FORKSTAT; >+ break; > case 'm': >+ /* prepare for slab display */ > statMode |= SLABSTAT; > break; > case 'D': >+ /* prepare for disk sum display */ > statMode |= DISKSUMSTAT; > break; > case 'n': >@@ -605,70 +661,90 @@ > moreheaders=FALSE; > break; > case 'p': >+ /* print partition stats for some partition */ > statMode |= PARTITIONSTAT; >- if (argv[1]){ >- ++argv; >- sprintf(partition, "%s", *argv); >- }else{fprintf(stderr, "-p requires an argument\n"); >- exit(EXIT_FAILURE); >+ if (argv[1]) { >+ ++argv; >+ strncpy(partition, *argv, sizeof(partition)); >+ partition[sizeof(partition)-1] = '\0'; >+ } >+ else { >+ fprintf(stderr, "-p requires an argument\n"); >+ exit(EXIT_FAILURE); > } > break; > case 'S': >- if (argv[1]){ >- ++argv; >- if (!strcmp(*argv, "k")) dataUnit=UNIT_k; >- else if (!strcmp(*argv, "K")) dataUnit=UNIT_K; >- else if (!strcmp(*argv, "m")) dataUnit=UNIT_m; >- else if (!strcmp(*argv, "M")) dataUnit=UNIT_M; >- else {fprintf(stderr, "-S requires k, K, m or M (default is kb)\n"); >- exit(EXIT_FAILURE); >- } >- strcpy(szDataUnit, *argv); >- }else {fprintf(stderr, "-S requires an argument\n"); >- exit(EXIT_FAILURE); >- } >- break; >+ /* modify the unit size */ >+ if (argv[1]) { >+ ++argv; >+ if (!strcmp(*argv, "k")) { dataUnit=UNIT_k;szDataUnit="KB"; } >+ else if (!strcmp(*argv, "K")) { dataUnit=UNIT_K;szDataUnit="KiB"; } >+ else if (!strcmp(*argv, "m")) { dataUnit=UNIT_m;szDataUnit="MB"; } >+ else if (!strcmp(*argv, "M")) { dataUnit=UNIT_M;szDataUnit="MiB"; } >+ else { >+ fprintf(stderr, "-S requires k, K, m or M\n"); >+ exit(EXIT_FAILURE); >+ } >+ } >+ else { >+ fprintf(stderr, "-S requires an argument\n"); >+ exit(EXIT_FAILURE); >+ } >+ break; > case 's': >+ /* prepare for printing VM table */ > statMode |= VMSUMSTAT; > break; > default: > /* no other aguments defined yet. */ > usage(); >- } >- }else{ >- argc++; >- switch (argc) { >+ } /* switch */ >+ } /* case of argument starting with - */ >+ else { >+ /* argument with no '-'; assume it's an integer */ >+ intargc++; >+ switch (intargc) { > case 1: >- if ((sleep_time = atoi(*argv)) == 0) >- usage(); >- num_updates = ULONG_MAX; >- break; >+ // it's the "delay" (assume max count) >+ if ((sleep_time = atoi(*argv)) <= 0) usage(); >+ num_updates = ULONG_MAX; >+ break; > case 2: >+ // it's the "count" (0 is acceptable) > num_updates = atol(*argv); >- break; >+ break; > default: >- usage(); >+ // it's too many arguments >+ usage(); > } /* switch */ >- } >-} >+ } /* case of option not starting with - */ >+ } /* loop over options */ > if (moreheaders) { > int tmp=winhi()-3; > height=((tmp>0)?tmp:22); > } > setlinebuf(stdout); >+ /* check unique option */ >+ if (count32Bits(statMode)>1) { >+ fprintf(stderr,"More than one mode selected\n"); >+ exit(EXIT_FAILURE); >+ } >+ /* dispatch */ > switch(statMode){ >- case(VMSTAT): new_format(); >+ case(VMSTAT): new_format(a_option,num_updates,dataUnit); /* several prints possible */ > break; >- case(VMSUMSTAT): sum_format(); >+ case(FORKSTAT): fork_format(); /* one print only */ >+ break; >+ case(VMSUMSTAT): sum_format(dataUnit,szDataUnit); /* one print only */ > break; >- case(DISKSTAT): diskformat(); >+ case(DISKSTAT): diskformat(num_updates); /* several prints possible */ > break; >- case(PARTITIONSTAT): if(diskpartition_format(partition)==-1) >- printf("Partition was not found\n"); >+ case(PARTITIONSTAT): if(diskpartition_format(partition,num_updates)==-1) /* several prints possible */ >+ printf("Partition '%s' was not found\n",partition); > break; >- case(SLABSTAT): slabformat(); >+ case(SLABSTAT): slabformat(num_updates); /* several prints possible */ > break; >- case(DISKSUMSTAT): disksum_format(); >+ case(DISKSUMSTAT): disksum_format(); /*one print only */ > break; > default: usage(); > break;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 430424
: 293088