Index: Makefile =================================================================== RCS file: /home/ncvs/src/usr.sbin/pstat/Makefile,v retrieving revision 1.5.6.1 diff -r1.5.6.1 Makefile 9c9 < LDADD= -lkvm --- > LDADD= -lkvm -lm Index: pstat.8 =================================================================== RCS file: /home/ncvs/src/usr.sbin/pstat/pstat.8,v retrieving revision 1.19.2.10 diff -r1.19.2.10 pstat.8 44c44 < .Op Fl Tfknst --- > .Op Fl HTfhknst 49c49 < .Op Fl k --- > .Op Fl Hhk 61a62,64 > .Fl H, > .Fl h, > and 63c66 < option is legal. --- > options are legal. 72a76,83 > .It Fl H > "Human-readable" output of device sizes. Use unit suffixes: Byte, > Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce > the number of digits to three or less using base 10 for sizes. > .It Fl h > "Human-readable" output of device sizes. Use unit suffixes: Byte, > Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce > the number of digits to three or less using base 2 for sizes. Index: pstat.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pstat/pstat.c,v retrieving revision 1.49.2.5 diff -r1.49.2.5 pstat.c 78a79 > #include 132a134 > int hflag; 194a197,225 > #define UNITS_SI 1 > #define UNITS_2 2 > > #define KILO_SZ(n) (n) > #define MEGA_SZ(n) ((n) * (n)) > #define GIGA_SZ(n) ((n) * (n) * (n)) > #define TERA_SZ(n) ((n) * (n) * (n) * (n)) > #define PETA_SZ(n) ((n) * (n) * (n) * (n) * (n)) > > #define KILO_2_SZ (KILO_SZ(1024ULL)) > #define MEGA_2_SZ (MEGA_SZ(1024ULL)) > #define GIGA_2_SZ (GIGA_SZ(1024ULL)) > #define TERA_2_SZ (TERA_SZ(1024ULL)) > #define PETA_2_SZ (PETA_SZ(1024ULL)) > > #define KILO_SI_SZ (KILO_SZ(1000ULL)) > #define MEGA_SI_SZ (MEGA_SZ(1000ULL)) > #define GIGA_SI_SZ (GIGA_SZ(1000ULL)) > #define TERA_SI_SZ (TERA_SZ(1000ULL)) > #define PETA_SI_SZ (PETA_SZ(1000ULL)) > > unsigned long long vals_si [] = {1, KILO_SI_SZ, MEGA_SI_SZ, GIGA_SI_SZ, TERA_SI_SZ, PETA_SI_SZ}; > unsigned long long vals_base2[] = {1, KILO_2_SZ, MEGA_2_SZ, GIGA_2_SZ, TERA_2_SZ, PETA_2_SZ}; > unsigned long long *valp; > > typedef enum { NONE, KILO, MEGA, GIGA, TERA, PETA, UNIT_MAX } unit_t; > > unit_t unitp [] = { NONE, KILO, MEGA, GIGA, TERA, PETA }; > 217a249,250 > unit_t unit_adjust(double *); > void prthumanval(int width,double bytes); 238,239c271,272 < opts = "kM:N:"; < usagestr = "swapinfo [-k] [-M core] [-N system]"; --- > opts = "hHkM:N:"; > usagestr = "swapinfo [-hHk] [-M core] [-N system]"; 241,242c274,275 < opts = "TM:N:fiknstv"; < usagestr = "pstat [-Tfknst] [-M core] [-N system]"; --- > opts = "TM:N:fhHiknstv"; > usagestr = "pstat [-TfhHknst] [-M core] [-N system]"; 249a283,290 > case 'H': > hflag = UNITS_SI; > valp = vals_si; > break; > case 'h': > hflag = UNITS_2; > valp = vals_base2; > break; 251a293 > hflag=0; 1018a1061 > if (hflag) header = " Size"; 1024a1068,1086 > (void)printf( > "%-15s ", > kswap[i].ksw_devname); > if (hflag) { > prthumanval(hlen,pagesize * kswap[i].ksw_total); > prthumanval(8,pagesize * kswap[i].ksw_used); > prthumanval(8,pagesize * (kswap[i].ksw_total - kswap[i].ksw_used)); > } else { > (void)printf( > "%*d ", > hlen, > CONVERT(kswap[i].ksw_total) > ); > (void)printf( > "%8d %8d ", > CONVERT(kswap[i].ksw_used), > CONVERT(kswap[i].ksw_total - kswap[i].ksw_used) > ); > } 1026,1039c1088,1093 < "%-15s %*d ", < kswap[i].ksw_devname, < hlen, < CONVERT(kswap[i].ksw_total) < ); < (void)printf( < "%8d %8d %5.0f%% %s\n", < CONVERT(kswap[i].ksw_used), < CONVERT(kswap[i].ksw_total - kswap[i].ksw_used), < (double)kswap[i].ksw_used * 100.0 / < (double)kswap[i].ksw_total, < (kswap[i].ksw_flags & SW_SEQUENTIAL) ? < "Sequential" : "Interleaved" < ); --- > "%5.0f%% %s\n", > (double)kswap[i].ksw_used * 100.0 / > (double)kswap[i].ksw_total, > (kswap[i].ksw_flags & SW_SEQUENTIAL) ? > "Sequential" : "Interleaved" > ); 1053,1061c1107,1153 < "%-15s %*d %8d %8d %5.0f%%\n", < "Total", < hlen, < CONVERT(kswap[n].ksw_total), < CONVERT(kswap[n].ksw_used), < CONVERT(kswap[n].ksw_total - kswap[n].ksw_used), < (double)kswap[n].ksw_used * 100.0 / < (double)kswap[n].ksw_total < ); --- > "%-15s ","Total"); > if (hflag) { > prthumanval(hlen,pagesize * kswap[n].ksw_total); > prthumanval(8,pagesize * kswap[n].ksw_used); > prthumanval(8,pagesize * (kswap[n].ksw_total - kswap[n].ksw_used)); > } else { > (void)printf( > "%*d ", > hlen, > CONVERT(kswap[n].ksw_total) > ); > (void)printf( > "%8d %8d ", > CONVERT(kswap[n].ksw_used), > CONVERT(kswap[n].ksw_total - kswap[n].ksw_used) > ); > } > (void)printf( > "%5.0f%%\n", > (double)kswap[n].ksw_used * 100.0 / > (double)kswap[n].ksw_total); > } > } > > /* > * Output in "human-readable" format. Uses 3 digits max and puts > * unit suffixes at the end. Makes output compact and easy to read, > * especially on huge disks. > * Shamelessly copied from df(1) > * > */ > unit_t > unit_adjust(double *val) > { > double abval; > unit_t unit; > unsigned int unit_sz; > > abval = fabs(*val); > > unit_sz = abval ? ilogb(abval) / 10 : 0; > > if (unit_sz >= UNIT_MAX) { > unit = NONE; > } else { > unit = unitp[unit_sz]; > *val /= (double)valp[unit_sz]; 1062a1155,1171 > > return (unit); > } > > void > prthumanval(int width,double bytes) > { > > unit_t unit; > unit = unit_adjust(&bytes); > > if (bytes == 0) > (void)printf("%*sB ", width-1, "0"); > else if (bytes > 10) > (void)printf("%*.0f%c ", width-1, bytes, "BKMGTPE"[unit]); > else > (void)printf("%*.1f%c ", width-1, bytes, "BKMGTPE"[unit]);