fix vmstat -d

This commit is contained in:
albert 2004-05-04 23:29:40 +00:00
parent 6a48d37343
commit c8a8290ef2
6 changed files with 81 additions and 70 deletions

1
NEWS
View File

@ -3,6 +3,7 @@ procps-3.2.1 --> procps-3.2.2
avoid warning about -lncurses when not linking -- thanks FLWM
ps: personality-specific -x support (HP-UX and SVR4-MP)
ps: k option, same as --sort
vmstat: fixed -d
procps-3.2.0 --> procps-3.2.1

View File

@ -674,20 +674,6 @@ nextline:
///////////////////////////////////////////////////////////////////////
// based on Fabian Frederick's /proc/diskstats parser
static unsigned int getFileLines(const char* szFile){
char szBuffer[1024];
FILE *fdiskStat;
int lines=0;
if ((fdiskStat=fopen (szFile,"rb"))){
while (fgets(szBuffer, 1024, fdiskStat)){
lines++;
}
fclose(fdiskStat);
}
return lines;
}
/////////////////////////////////////////////////////////////////////////////
unsigned int getpartitions_num(struct disk_stat *disks, int ndisks){
int i=0;
@ -704,31 +690,28 @@ unsigned int getpartitions_num(struct disk_stat *disks, int ndisks){
unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **partitions){
FILE* fd;
int units,
i,
disk_type,
disk_num,
cDisk=0,
cPartition=0;
int cDisk = 0;
int cPartition = 0;
int fields;
unsigned dummy;
*disks = NULL;
*partitions = NULL;
buff[BUFFSIZE-1] = 0;
units = getFileLines("/proc/diskstats");
fd = fopen("/proc/diskstats", "rb");
if(!fd) crash("/proc/diskstats");
for (i=0; i<units; i++){
for (;;) {
if (!fgets(buff,BUFFSIZE-1,fd)){
fclose(fd);
crash("/proc/diskstats");
break;
}
sscanf(buff, " %d %d", &disk_type, &disk_num);
if (disk_num == 0){
fields = sscanf(buff, " %*d %*d %*s %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %u", &dummy);
if (fields == 1){
(*disks) = realloc(*disks, (cDisk+1)*sizeof(struct disk_stat));
sscanf(buff, " %d %*d %15s %u %u %llu %u %u %u %llu %u %u %u %u",
&(*disks)[cDisk].disk_type,
//&unused,
sscanf(buff, " %*d %*d %15s %u %u %llu %u %u %u %llu %u %u %u %u",
//&disk_major,
//&disk_minor,
(*disks)[cDisk].disk_name,
&(*disks)[cDisk].reads,
&(*disks)[cDisk].merged_reads,
@ -747,20 +730,20 @@ unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **parti
}else{
(*partitions) = realloc(*partitions, (cPartition+1)*sizeof(struct partition_stat));
fflush(stdout);
sscanf(buff, " %d %d %15s %u %llu %u %u",
&(*partitions)[cPartition].disk_type,
&(*partitions)[cPartition].partition_num,
sscanf(buff, " %*d %*d %15s %u %llu %u %u",
//&part_major,
//&part_minor,
(*partitions)[cPartition].partition_name,
&(*partitions)[cPartition].reads,
&(*partitions)[cPartition].reads_sectors,
&(*partitions)[cPartition].writes,
&(*partitions)[cPartition].requested_writes
);
(*partitions)[cPartition++].parent_disk = &((*disks)[cDisk-1]);
(*partitions)[cPartition++].parent_disk = cDisk-1;
(*disks)[cDisk-1].partitions++;
}
}
fclose(fd);
return cDisk;
}

View File

@ -94,7 +94,6 @@ typedef struct disk_stat{
unsigned long long reads_sectors;
unsigned long long written_sectors;
char disk_name [16];
unsigned int disk_type;
unsigned inprogress_IO;
unsigned merged_reads;
unsigned merged_writes;
@ -108,11 +107,9 @@ typedef struct disk_stat{
}disk_stat;
typedef struct partition_stat{
unsigned int disk_type;
unsigned int partition_num;
char partition_name [16];
unsigned long long reads_sectors;
struct disk_stat* parent_disk;
unsigned parent_disk; // index into a struct disk_stat array
unsigned reads;
unsigned writes;
unsigned requested_writes;

View File

@ -1085,6 +1085,7 @@ static const format_struct format_array[] = {
{"inblk", "INBLK", pr_nop, sr_nop, 5, 0, BSD, AN|RIGHT}, /*inblock*/
{"inblock", "INBLK", pr_nop, sr_nop, 5, 0, DEC, AN|RIGHT}, /*inblk*/
{"intpri", "PRI", pr_opri, sr_priority, 3, 0, HPU, TO|RIGHT},
{"jid", "JID", pr_nop, sr_nop, 1, 0, SGI, PO|RIGHT},
{"jobc", "JOBC", pr_nop, sr_nop, 4, 0, XXX, AN|RIGHT},
{"ktrace", "KTRACE", pr_nop, sr_nop, 8, 0, BSD, AN|RIGHT},
{"ktracep", "KTRACEP", pr_nop, sr_nop, 8, 0, BSD, AN|RIGHT},

View File

@ -253,6 +253,16 @@ static const char *parse_sysv_option(void){
trace("-H Process hierarchy (like ASCII art forest option)\n");
forest_type = 'u';
break;
#if 0
case 'J': // specify list of job IDs in hex (IRIX) -- like HP "-R" maybe?
trace("-J select by job ID\n"); // want a JID ("jid") for "-j" too
arg=get_opt_arg();
if(!arg) return "List of jobs must follow -J.";
err=parse_list(arg, parse_jid);
if(err) return err;
selection_list->typecode = SEL_JID;
return NULL; /* can't have any more options */
#endif
case 'L': /* */
/* In spite of the insane 2-level thread system, Sun appears to
* have made this option Linux-compatible. If a process has N
@ -264,7 +274,7 @@ static const char *parse_sysv_option(void){
thread_flags |= TF_U_L;
// format_modifiers |= FM_L;
break;
case 'M': /* someday, maybe, we will have MAC like SGI's Irix */
case 'M': // typically the SE Linux context
trace("-M Print security label for Mandatory Access Control.\n");
format_modifiers |= FM_M;
break;
@ -279,14 +289,18 @@ static const char *parse_sysv_option(void){
defer_sf_option(arg, SF_U_O);
return NULL; /* can't have any more options */
case 'P': /* SunOS 5 "psr" or unknown HP/UX feature */
trace("-P adds columns of PRM info (HP) or PSR column (Sun)\n");
trace("-P adds columns of PRM info (HP-UX), PSR (SunOS), or capabilities (IRIX)\n");
format_modifiers |= FM_P;
break;
#ifdef WE_UNDERSTAND_THIS
case 'R': /* unknown HP/UX feature */
trace("-R selects PRM groups\n");
return "Don't understand PRM on Linux.";
break;
#if 0
case 'R': // unknown HP/UX feature, like IRIX "-J" maybe?
trace("-R select by PRM group\n");
arg=get_opt_arg();
if(!arg) return "List of PRM groups must follow -R.";
err=parse_list(arg, parse_prm);
if(err) return err;
selection_list->typecode = SEL_PRM;
return NULL; /* can't have any more options */
#endif
case 'T':
/* IRIX 6.5 docs suggest POSIX threads get shown individually.
@ -312,9 +326,10 @@ static const char *parse_sysv_option(void){
display_version();
exit(0);
#if 0
// This must be verified against SVR4-MP (UnixWare or Powermax)
case 'Z': /* full Mandatory Access Control level info */
trace("-Z shows full MAC info\n");
return "Don't understand MAC on Linux.";
format_modifiers |= FM_M;
break;
#endif
case 'a':
@ -394,7 +409,7 @@ static const char *parse_sysv_option(void){
if(err) return err;
selection_list->typecode = SEL_PID;
return NULL; /* can't have any more options */
#ifdef KNOW_WHAT_TO_DO_WITH_THIS
#if 0
case 'r':
trace("-r some Digital Unix thing about warnings...\n");
trace(" or SCO's option to chroot() for new /proc and /dev.\n");
@ -448,9 +463,10 @@ static const char *parse_sysv_option(void){
format_modifiers |= FM_y;
break;
#if 0
// This must be verified against SVR4-MP (UnixWare or Powermax)
case 'z': /* alias of Mandatory Access Control level info */
trace("-z shows aliased MAC info\n");
return "Don't understand MAC aliases on Linux.";
format_modifiers |= FM_M;
break;
#endif
case '-':

View File

@ -163,27 +163,6 @@ static void new_header(void){
////////////////////////////////////////////////////////////////////////////
static void diskheader(void){
printf("disk ----------reads------------ -----------writes----------- -------IO-------\n");
printf("%3s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n", " ", "total", "merged","sectors","ms","total","merged","sectors","ms","cur","s");
}
////////////////////////////////////////////////////////////////////////////
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 slabheader(void){
printf("%-24s %6s %6s %6s %6s\n","Cache","Num", "Total", "Size", "Pages");
}
////////////////////////////////////////////////////////////////////////////
static unsigned long unitConvert(unsigned int size){
float cvSize;
cvSize=(float)size/dataUnit*((statMode==SLABSTAT)?1:1024);
@ -290,6 +269,12 @@ static void new_format(void) {
////////////////////////////////////////////////////////////////////////////
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){
FILE *fDiskstat;
struct disk_stat *disks;
@ -345,19 +330,41 @@ static int diskpartition_format(const char* partition_name){
////////////////////////////////////////////////////////////////////////////
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");
}
////////////////////////////////////////////////////////////////////////////
static void diskformat(void){
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions;
unsigned long ndisks,i,j,k;
const char format[]="%-3s %6u %6u %6llu %6u %6u %6u %6llu %6u %6u %6u\n";
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);
for(k=0; k<ndisks; k++){
if (moreheaders && ((k%height)==0)) diskheader();
printf(format,
disks[k].disk_name,disks[k].reads, disks[k].merged_reads,disks[k].reads_sectors, disks[k].milli_reading, disks[k].writes, disks[k].merged_writes, 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].disk_name,
disks[k].reads,
disks[k].merged_reads,
disks[k].reads_sectors,
disks[k].milli_reading,
disks[k].writes,
disks[k].merged_writes,
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*/
);
fflush(stdout);
}
free(disks);
@ -394,6 +401,12 @@ static void diskformat(void){
////////////////////////////////////////////////////////////////////////////
static void slabheader(void){
printf("%-24s %6s %6s %6s %6s\n","Cache","Num", "Total", "Size", "Pages");
}
////////////////////////////////////////////////////////////////////////////
static void slabformat (void){
FILE *fSlab;
struct slab_cache *slabs;