got most of procps-3.1.11ff2.diff

This commit is contained in:
albert 2003-08-10 23:40:41 +00:00
parent 9cd9c44fb8
commit 8618adeaaf
7 changed files with 197 additions and 24 deletions

View File

@ -607,6 +607,8 @@ const char * wchan(unsigned KLONG address, unsigned pid) {
/* good_symb->name has the data, but needs to be trimmed */ /* good_symb->name has the data, but needs to be trimmed */
ret = good_symb->name; ret = good_symb->name;
// lame ppc64 has a '.' in front of every name
if(*ret=='.') ret++;
switch(*ret){ switch(*ret){
case 's': if(!strncmp(ret, "sys_", 4)) ret += 4; break; case 's': if(!strncmp(ret, "sys_", 4)) ret += 4; break;
case 'd': if(!strncmp(ret, "do_", 3)) ret += 3; break; case 'd': if(!strncmp(ret, "do_", 3)) ret += 3; break;

View File

@ -10,7 +10,7 @@ global:
Hertz; smp_num_cpus; Hertz; smp_num_cpus;
sprint_uptime; uptime; user_from_uid; print_uptime; loadavg; sprint_uptime; uptime; user_from_uid; print_uptime; loadavg;
pretty_print_signals; print_given_signals; unix_print_signals; signal_name_to_number; signal_number_to_name; pretty_print_signals; print_given_signals; unix_print_signals; signal_name_to_number; signal_number_to_name;
meminfo; vminfo; getstat; getdiskstat; getslabinfo; get_pid_digits; meminfo; vminfo; getstat; getdiskstat; getpartitions_num; getslabinfo; get_pid_digits;
kb_active; kb_inactive; kb_main_buffers; kb_main_cached; kb_active; kb_inactive; kb_main_buffers; kb_main_cached;
kb_main_free; kb_main_total; kb_main_used; kb_swap_free; kb_main_free; kb_main_total; kb_main_used; kb_swap_free;
kb_swap_total; kb_swap_used; kb_main_shared; kb_swap_total; kb_swap_used; kb_main_shared;

View File

@ -671,6 +671,21 @@ static unsigned int getFileLines(const char* szFile){
return lines; return lines;
} }
/////////////////////////////////////////////////////////////////////////////
unsigned int getpartitions_num(struct disk_stat *disks, int ndisks){
int i=0;
int partitions=0;
for (i=0;i<ndisks;i++){
partitions+=disks[i].partitions;
}
return partitions;
}
/////////////////////////////////////////////////////////////////////////////
unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **partitions){ unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **partitions){
FILE* fd; FILE* fd;
int units, int units,
@ -711,6 +726,7 @@ unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **parti
&(*disks)[cDisk].milli_spent_IO, &(*disks)[cDisk].milli_spent_IO,
&(*disks)[cDisk].weighted_milli_spent_IO &(*disks)[cDisk].weighted_milli_spent_IO
); );
(*disks)[cDisk].partitions=0;
cDisk++; cDisk++;
}else{ }else{
(*partitions) = realloc(*partitions, (cPartition+1)*sizeof(struct partition_stat)); (*partitions) = realloc(*partitions, (cPartition+1)*sizeof(struct partition_stat));
@ -725,6 +741,7 @@ unsigned int getdiskstat(struct disk_stat **disks, struct partition_stat **parti
&(*partitions)[cPartition].requested_writes &(*partitions)[cPartition].requested_writes
); );
(*partitions)[cPartition++].parent_disk = &((*disks)[cDisk-1]); (*partitions)[cPartition++].parent_disk = &((*disks)[cDisk-1]);
(*disks)[cDisk-1].partitions++;
} }
} }
fclose(fd); fclose(fd);

View File

@ -102,6 +102,7 @@ typedef struct disk_stat{
unsigned inprogress_IO; unsigned inprogress_IO;
unsigned milli_spent_IO; unsigned milli_spent_IO;
unsigned weighted_milli_spent_IO; unsigned weighted_milli_spent_IO;
unsigned partitions;
}disk_stat; }disk_stat;
typedef struct partition_stat{ typedef struct partition_stat{
@ -115,6 +116,7 @@ typedef struct partition_stat{
unsigned requested_writes; unsigned requested_writes;
}partition_stat; }partition_stat;
extern unsigned int getpartitions_num(struct disk_stat *disks, int ndisks);
extern unsigned int getdiskstat (struct disk_stat**,struct partition_stat**); extern unsigned int getdiskstat (struct disk_stat**,struct partition_stat**);
typedef struct slab_cache{ typedef struct slab_cache{

View File

@ -26,7 +26,7 @@ make SKIP="/bin/kill /usr/share/man/man1/kill.1" CC="gcc $RPM_OPT_FLAGS" LDFLAGS
%install %install
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT
make SKIP="/bin/kill /usr/share/man/man1/kill.1" DESTDIR=$RPM_BUILD_ROOT ldconfig=echo install="install -D" install make SKIP="/bin/kill /usr/share/man/man1/kill.1" DESTDIR=$RPM_BUILD_ROOT ldconfig=echo install="install -D" lib="$RPM_BUILD_ROOT/%{_lib}" install
%clean %clean
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT

View File

@ -22,6 +22,9 @@ vmstat \- Report virtual memory statistics
.RB [ "\-d"] .RB [ "\-d"]
.br .br
.B vmstat .B vmstat
.RB [ "\-p disk partition"]
.br
.B vmstat
.RB [ "\-V" ] .RB [ "\-V" ]
.SH DESCRIPTION .SH DESCRIPTION
\fBvmstat\fP reports information about processes, memory, paging, \fBvmstat\fP reports information about processes, memory, paging,
@ -57,6 +60,8 @@ defined, \fIcount\fP defaults to infinity.
.PP .PP
The \fB-d\fP reports disk statistics (2.5.70 or above required) The \fB-d\fP reports disk statistics (2.5.70 or above required)
.PP .PP
The \fB-p\fP followed by some partition name for detailed statistics (2.5.70 or above required)
.PP
The \fB-S\fP followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes The \fB-S\fP followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes
.PP .PP
The \fB-V\fP switch results in displaying version information. The \fB-V\fP switch results in displaying version information.
@ -137,6 +142,15 @@ cur: I/O in progress
s: seconds spent for I/O s: seconds spent for I/O
.fi .fi
.PP
.SH FIELD DESCRIPTION FOR DISK PARTITION MODE
.nf
reads: Total number of reads issued to this partition
read sectors: Total read sectors for partition
writes : Total number of writes issued to this partition
requested writes: Total number of write requests made for partition
.fi
.PP .PP
.SH FIELD DESCRIPTION FOR SLAB MODE .SH FIELD DESCRIPTION FOR SLAB MODE
@ -180,4 +194,4 @@ Does not tabulate the block io per device or count the number of system calls.
.SH AUTHORS .SH AUTHORS
.nf .nf
Written by Henry Ware <al172@yfn.ysu.edu>. Written by Henry Ware <al172@yfn.ysu.edu>.
Diskstat,slab mode and some improvements by Fabian Frederick <fabian.frederick@gmx.fr> Fabian Fr\('ed\('erick <ffrederick@users.sourceforge.net> (diskstat, slab, partitions...)

144
vmstat.c
View File

@ -1,12 +1,16 @@
// 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) : 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
// -Adding disk table
// -Syncing help / usage
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -36,6 +40,8 @@ static char szDataUnit [16];
#define DISKSTAT 0x00000001 #define DISKSTAT 0x00000001
#define VMSUMSTAT 0x00000002 #define VMSUMSTAT 0x00000002
#define SLABSTAT 0x00000004 #define SLABSTAT 0x00000004
#define PARTITIONSTAT 0x00000008
#define DISKSUMSTAT 0x00000010
static int statMode=VMSTAT; static int statMode=VMSTAT;
@ -60,6 +66,9 @@ static void usage(void) {
fprintf(stderr," -n causes the headers not to be reprinted regularly.\n"); fprintf(stderr," -n causes the headers not to be reprinted regularly.\n");
fprintf(stderr," -a print inactive/active page stats.\n"); fprintf(stderr," -a print inactive/active page stats.\n");
fprintf(stderr," -d prints disk statistics\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," -m prints slabinfo\n");
fprintf(stderr," -S unit size\n"); fprintf(stderr," -S unit size\n");
fprintf(stderr," delay is the delay between updates in seconds. \n"); fprintf(stderr," delay is the delay between updates in seconds. \n");
@ -137,6 +146,8 @@ static int format_1000(unsigned long long val64, char *restrict dst){
} }
#endif #endif
////////////////////////////////////////////////////////////////////////////
static void new_header(void){ static void new_header(void){
printf("procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----\n"); printf("procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----\n");
printf( printf(
@ -161,11 +172,16 @@ static void new_diskheader(void){
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
static void new_diskpartition_header(const char *partition_name){
printf("%-10s %10s %10s %10s %10s\n",partition_name, "reads ", "read sectors", "writes ", "requested writes");
}
////////////////////////////////////////////////////////////////////////////
static void new_slabheader(void){ static void new_slabheader(void){
printf("%-24s %6s %6s %6s %6s\n","Cache","Num", "Total", "Size", "Pages"); printf("%-24s %6s %6s %6s %6s\n","Cache","Num", "Total", "Size", "Pages");
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
static unsigned long unitConvert(unsigned int size){ static unsigned long unitConvert(unsigned int size){
@ -274,6 +290,59 @@ static void new_format(void) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
static int new_diskpartition_format(const char* partition_name){
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions, *current_partition=NULL;
unsigned long ndisks,i,j,k,npartitions;
const char format[]="%20u %10llu %10u %10u\n";
if ((fDiskstat=fopen("/proc/diskstats", "rb"))){
fclose(fDiskstat);
ndisks=getdiskstat(&disks,&partitions);
npartitions=getpartitions_num(disks, ndisks);
for(k=0; k<npartitions; k++){
if(!strcmp(partition_name, partitions[k].partition_name)){
current_partition=&(partitions[k]);
}
}
if(!current_partition){
return -1;
}
new_diskpartition_header(partition_name);
printf (format,
current_partition->reads,current_partition->reads_sectors,current_partition->writes,current_partition->requested_writes);
fflush(stdout);
free(disks);
free(partitions);
for(j=1; j<num_updates; j++){
if (moreheaders && ((j%height)==0)) new_diskpartition_header(partition_name);
sleep(sleep_time);
ndisks=getdiskstat(&disks,&partitions);
npartitions=getpartitions_num(disks, ndisks);
current_partition=NULL;
for(k=0; k<npartitions; k++){
if(!strcmp(partition_name, partitions[k].partition_name)){
current_partition=&(partitions[k]);
}
}
if(!current_partition){
return -1;
}
printf (format,
current_partition->reads,current_partition->reads_sectors,current_partition->writes,current_partition->requested_writes);
fflush(stdout);
free(disks);
free(partitions);
}
}else{
fprintf(stderr, "Your kernel doesn't support diskstat (2.5.70 or above required)");
exit(0);
}
}
////////////////////////////////////////////////////////////////////////////
static void new_diskformat(void){ static void new_diskformat(void){
FILE *fDiskstat; FILE *fDiskstat;
struct disk_stat *disks; struct disk_stat *disks;
@ -366,6 +435,57 @@ static void new_slabformat (void){
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
static void disksum_format(void) {
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions;
int ndisks, i;
unsigned long reads, merged_reads, read_sectors, milli_reading, writes,
merged_writes, written_sectors, milli_writing, inprogress_IO,
milli_spent_IO, weighted_milli_spent_IO;
reads=merged_reads=read_sectors=milli_reading=writes=merged_writes= \
written_sectors=milli_writing=inprogress_IO=milli_spent_IO= \
weighted_milli_spent_IO=0;
if ((fDiskstat=fopen("/proc/diskstats", "rb"))){
fclose(fDiskstat);
ndisks=getdiskstat(&disks, &partitions);
printf("%13d disks \n", ndisks);
printf("%13d partitions \n", getpartitions_num(disks, ndisks));
for(i=0; i<ndisks; i++){
reads+=disks[i].reads;
merged_reads+=disks[i].merged_reads;
read_sectors+=disks[i].reads_sectors;
milli_reading+=disks[i].milli_reading;
writes+=disks[i].writes;
merged_writes+=disks[i].merged_writes;
written_sectors+=disks[i].written_sectors;
milli_writing+=disks[i].milli_writing;
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;
}
printf("%13lu total reads\n",reads);
printf("%13lu merged reads\n",merged_reads);
printf("%13lu read sectors\n",read_sectors);
printf("%13lu milli reading\n",milli_reading);
printf("%13lu writes\n",writes);
printf("%13lu merged writes\n",merged_writes);
printf("%13lu written sectors\n",written_sectors);
printf("%13lu milli writing\n",milli_writing);
printf("%13lu inprogress IO\n",inprogress_IO);
printf("%13lu milli spent IO\n",milli_spent_IO);
free(disks);
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; jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow;
@ -437,6 +557,7 @@ static int winhi(void) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char partition[16];
argc=0; /* redefined as number of integer arguments */ argc=0; /* redefined as number of integer arguments */
for (argv++;*argv;argv++) { for (argv++;*argv;argv++) {
if ('-' ==(**argv)) { if ('-' ==(**argv)) {
@ -459,10 +580,22 @@ int main(int argc, char *argv[]) {
case 'm': case 'm':
statMode |= SLABSTAT; statMode |= SLABSTAT;
break; break;
case 'D':
statMode |= DISKSUMSTAT;
break;
case 'n': case 'n':
/* print only one header */ /* print only one header */
moreheaders=FALSE; moreheaders=FALSE;
break; break;
case 'p':
statMode |= PARTITIONSTAT;
if (argv[1]){
++argv;
sprintf(partition, "%s", *argv);
}else{fprintf(stderr, "-p requires an argument\n");
exit(EXIT_FAILURE);
}
break;
case 'S': case 'S':
if (argv[1]){ if (argv[1]){
++argv; ++argv;
@ -509,12 +642,17 @@ int main(int argc, char *argv[]) {
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): new_diskformat(); case(DISKSTAT): new_diskformat();
break; break;
case(PARTITIONSTAT): if(new_diskpartition_format(partition)==-1)
printf("Partition was not found\n");
break;
case(SLABSTAT): new_slabformat(); case(SLABSTAT): new_slabformat();
break; break;
case(DISKSUMSTAT): disksum_format();
break;
default: usage(); default: usage();
break; break;
} }