vmstat: adapted for changes in an i/f, <DISKSTATS> api
This patch is a response to changes to the <diskstats> interface. And the following represents the summary of significant unrelated alterations that were also made. + corrected that 'milli weighted IO' output, which has been wrong since that original patch referenced below. as implemented, it duplicated 'milli spent IO' output. + restored original commit intent regarding disks with a partition switch as represented in references below. + moved all item enumerators up near the source start. + removed all remaining tabs and inconsistent indents. + reformatted the silly style applied to 'xerrx' uses. Reference(s): . disallowed 'disks' under 'partition' switch commit 7df7795b929c2c0911127d9fff64e62fe9e2975f . original commit with disk/partition rational commit e445f7e6c5539594600ace7a722dafa3b91a5374 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
ecd64f4445
commit
69557ac9dc
424
vmstat.c
424
vmstat.c
@ -84,6 +84,124 @@ static unsigned long num_updates =1;
|
||||
static unsigned int height;
|
||||
static unsigned int moreheaders = TRUE;
|
||||
|
||||
static enum stat_item First_stat_items[] = {
|
||||
PROCPS_STAT_SYS_PROC_RUNNING,
|
||||
PROCPS_STAT_SYS_PROC_BLOCKED,
|
||||
PROCPS_STAT_SYS_INTERRUPTS,
|
||||
PROCPS_STAT_SYS_CTX_SWITCHES,
|
||||
PROCPS_STAT_TIC_USER,
|
||||
PROCPS_STAT_TIC_NICE,
|
||||
PROCPS_STAT_TIC_SYSTEM,
|
||||
PROCPS_STAT_TIC_IRQ,
|
||||
PROCPS_STAT_TIC_SOFTIRQ,
|
||||
PROCPS_STAT_TIC_IDLE,
|
||||
PROCPS_STAT_TIC_IOWAIT,
|
||||
PROCPS_STAT_TIC_STOLEN
|
||||
};
|
||||
static enum stat_item Loop_stat_items[] = {
|
||||
PROCPS_STAT_SYS_PROC_RUNNING,
|
||||
PROCPS_STAT_SYS_PROC_BLOCKED,
|
||||
PROCPS_STAT_SYS_DELTA_INTERRUPTS,
|
||||
PROCPS_STAT_SYS_DELTA_CTX_SWITCHES,
|
||||
PROCPS_STAT_TIC_DELTA_USER,
|
||||
PROCPS_STAT_TIC_DELTA_NICE,
|
||||
PROCPS_STAT_TIC_DELTA_SYSTEM,
|
||||
PROCPS_STAT_TIC_DELTA_IRQ,
|
||||
PROCPS_STAT_TIC_DELTA_SOFTIRQ,
|
||||
PROCPS_STAT_TIC_DELTA_IDLE,
|
||||
PROCPS_STAT_TIC_DELTA_IOWAIT,
|
||||
PROCPS_STAT_TIC_DELTA_STOLEN
|
||||
};
|
||||
enum Rel_statitems {
|
||||
stat_PRU, stat_PBL, stat_INT, stat_CTX,
|
||||
stat_USR, stat_NIC, stat_SYS, stat_IRQ, stat_SRQ,
|
||||
stat_IDL, stat_IOW, stat_STO, MAX_stat
|
||||
};
|
||||
|
||||
static enum meminfo_item Mem_items[] = {
|
||||
PROCPS_MEMINFO_SWAP_USED,
|
||||
PROCPS_MEMINFO_MEM_FREE,
|
||||
PROCPS_MEMINFO_MEM_ACTIVE,
|
||||
PROCPS_MEMINFO_MEM_INACTIVE,
|
||||
PROCPS_MEMINFO_MEM_BUFFERS,
|
||||
PROCPS_MEMINFO_MEM_CACHED
|
||||
};
|
||||
enum Rel_memitems {
|
||||
mem_SUS, mem_FREE, mem_ACT, mem_INA, mem_BUF, mem_CAC, MAX_mem
|
||||
};
|
||||
|
||||
static enum diskstats_item Disk_items[] = {
|
||||
PROCPS_DISKSTATS_TYPE,
|
||||
PROCPS_DISKSTATS_NAME,
|
||||
PROCPS_DISKSTATS_READS,
|
||||
PROCPS_DISKSTATS_READS_MERGED,
|
||||
PROCPS_DISKSTATS_READ_SECTORS,
|
||||
PROCPS_DISKSTATS_READ_TIME,
|
||||
PROCPS_DISKSTATS_WRITES,
|
||||
PROCPS_DISKSTATS_WRITES_MERGED,
|
||||
PROCPS_DISKSTATS_WRITE_SECTORS,
|
||||
PROCPS_DISKSTATS_WRITE_TIME,
|
||||
PROCPS_DISKSTATS_IO_INPROGRESS,
|
||||
PROCPS_DISKSTATS_IO_TIME,
|
||||
PROCPS_DISKSTATS_IO_WTIME
|
||||
};
|
||||
enum Rel_diskitems {
|
||||
disk_TYPE, disk_NAME,
|
||||
disk_READ, disk_READ_MERGE, disk_READ_SECT, disk_READ_TIME,
|
||||
disk_WRITE, disk_WRITE_MERGE, disk_WRITE_SECT, disk_WRITE_TIME,
|
||||
disk_IO, disk_IO_TIME, disk_IO_WTIME, MAX_disk
|
||||
};
|
||||
|
||||
static enum diskstats_item Part_items[] = {
|
||||
PROCPS_DISKSTATS_READS,
|
||||
PROCPS_DISKSTATS_READ_SECTORS,
|
||||
PROCPS_DISKSTATS_WRITES,
|
||||
PROCPS_DISKSTATS_WRITE_SECTORS
|
||||
};
|
||||
enum Rel_partitems {
|
||||
part_READ, part_READ_SECT, part_WRITE, part_WRITE_SECT, MAX_part
|
||||
};
|
||||
|
||||
static enum stat_item Sum_stat_items[] = {
|
||||
PROCPS_STAT_TIC_USER,
|
||||
PROCPS_STAT_TIC_NICE,
|
||||
PROCPS_STAT_TIC_SYSTEM,
|
||||
PROCPS_STAT_TIC_IDLE,
|
||||
PROCPS_STAT_TIC_IOWAIT,
|
||||
PROCPS_STAT_TIC_IRQ,
|
||||
PROCPS_STAT_TIC_SOFTIRQ,
|
||||
PROCPS_STAT_TIC_STOLEN,
|
||||
PROCPS_STAT_TIC_GUEST,
|
||||
PROCPS_STAT_TIC_GUEST_NICE,
|
||||
PROCPS_STAT_SYS_CTX_SWITCHES,
|
||||
PROCPS_STAT_SYS_INTERRUPTS,
|
||||
PROCPS_STAT_SYS_TIME_OF_BOOT,
|
||||
PROCPS_STAT_SYS_PROC_CREATED
|
||||
};
|
||||
enum Rel_sumstatitems {
|
||||
sstat_USR, sstat_NIC, sstat_SYS, sstat_IDL, sstat_IOW, sstat_IRQ,
|
||||
sstat_SRQ, sstat_STO, sstat_GST, sstat_GNI, sstat_CTX, sstat_INT,
|
||||
sstat_TOB, sstat_PCR
|
||||
};
|
||||
|
||||
static enum meminfo_item Sum_mem_items[] = {
|
||||
PROCPS_MEMINFO_MEM_TOTAL,
|
||||
PROCPS_MEMINFO_MEM_USED,
|
||||
PROCPS_MEMINFO_MEM_ACTIVE,
|
||||
PROCPS_MEMINFO_MEM_INACTIVE,
|
||||
PROCPS_MEMINFO_MEM_FREE,
|
||||
PROCPS_MEMINFO_MEM_BUFFERS,
|
||||
PROCPS_MEMINFO_MEM_CACHED,
|
||||
PROCPS_MEMINFO_SWAP_TOTAL,
|
||||
PROCPS_MEMINFO_SWAP_USED,
|
||||
PROCPS_MEMINFO_SWAP_FREE,
|
||||
};
|
||||
enum Rel_summemitems {
|
||||
smem_MTOT, smem_MUSE, smem_MACT, smem_MIAC, smem_MFRE,
|
||||
smem_MBUF, smem_MCAC, smem_STOT, smem_SUSE, smem_SFRE
|
||||
};
|
||||
|
||||
|
||||
static void __attribute__ ((__noreturn__))
|
||||
usage(FILE * out)
|
||||
{
|
||||
@ -203,57 +321,6 @@ static unsigned long unitConvert(unsigned long size)
|
||||
return ((unsigned long)cvSize);
|
||||
}
|
||||
|
||||
static enum stat_item First_stat_items[] = {
|
||||
PROCPS_STAT_SYS_PROC_RUNNING,
|
||||
PROCPS_STAT_SYS_PROC_BLOCKED,
|
||||
PROCPS_STAT_SYS_INTERRUPTS,
|
||||
PROCPS_STAT_SYS_CTX_SWITCHES,
|
||||
PROCPS_STAT_TIC_USER,
|
||||
PROCPS_STAT_TIC_NICE,
|
||||
PROCPS_STAT_TIC_SYSTEM,
|
||||
PROCPS_STAT_TIC_IRQ,
|
||||
PROCPS_STAT_TIC_SOFTIRQ,
|
||||
PROCPS_STAT_TIC_IDLE,
|
||||
PROCPS_STAT_TIC_IOWAIT,
|
||||
PROCPS_STAT_TIC_STOLEN
|
||||
};
|
||||
|
||||
static enum stat_item Loop_stat_items[] = {
|
||||
PROCPS_STAT_SYS_PROC_RUNNING,
|
||||
PROCPS_STAT_SYS_PROC_BLOCKED,
|
||||
PROCPS_STAT_SYS_DELTA_INTERRUPTS,
|
||||
PROCPS_STAT_SYS_DELTA_CTX_SWITCHES,
|
||||
PROCPS_STAT_TIC_DELTA_USER,
|
||||
PROCPS_STAT_TIC_DELTA_NICE,
|
||||
PROCPS_STAT_TIC_DELTA_SYSTEM,
|
||||
PROCPS_STAT_TIC_DELTA_IRQ,
|
||||
PROCPS_STAT_TIC_DELTA_SOFTIRQ,
|
||||
PROCPS_STAT_TIC_DELTA_IDLE,
|
||||
PROCPS_STAT_TIC_DELTA_IOWAIT,
|
||||
PROCPS_STAT_TIC_DELTA_STOLEN
|
||||
};
|
||||
|
||||
enum Rel_statitems {
|
||||
stat_PRU, stat_PBL,
|
||||
stat_INT, stat_CTX,
|
||||
stat_USR, stat_NIC, stat_SYS, stat_IRQ, stat_SRQ,
|
||||
stat_IDL, stat_IOW, stat_STO};
|
||||
|
||||
static enum meminfo_item Mem_items[] = {
|
||||
PROCPS_MEMINFO_SWAP_USED,
|
||||
PROCPS_MEMINFO_MEM_FREE,
|
||||
PROCPS_MEMINFO_MEM_ACTIVE,
|
||||
PROCPS_MEMINFO_MEM_INACTIVE,
|
||||
PROCPS_MEMINFO_MEM_BUFFERS,
|
||||
PROCPS_MEMINFO_MEM_CACHED
|
||||
};
|
||||
|
||||
enum Rel_memitems {
|
||||
mem_SUS, mem_FREE,
|
||||
mem_ACT, mem_INA,
|
||||
mem_BUF, mem_CAC
|
||||
};
|
||||
|
||||
static void new_format(void)
|
||||
{
|
||||
#define TICv(E) PROCPS_STAT_VAL(E, ull_int, stat_stack)
|
||||
@ -289,11 +356,9 @@ static void new_format(void)
|
||||
new_header();
|
||||
|
||||
if (procps_vmstat_new(&vm_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to create vmstat structure"));
|
||||
xerrx(EXIT_FAILURE, _("Unable to create vmstat structure"));
|
||||
if (procps_stat_new(&sys_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to create system stat structure"));
|
||||
xerrx(EXIT_FAILURE, _("Unable to create system stat structure"));
|
||||
if (procps_meminfo_new(&mem_info) < 0)
|
||||
xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
|
||||
|
||||
@ -303,10 +368,8 @@ static void new_format(void)
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
|
||||
}
|
||||
/* Do the initial fill */
|
||||
if ((stat_stack = procps_stat_select(sys_info, First_stat_items, 12)) ==
|
||||
NULL)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to select stat information"));
|
||||
if (!(stat_stack = procps_stat_select(sys_info, First_stat_items, MAX_stat)))
|
||||
xerrx(EXIT_FAILURE, _("Unable to select stat information"));
|
||||
cpu_use = TICv(stat_USR) + TICv(stat_NIC);
|
||||
cpu_sys = TICv(stat_SYS) + TICv(stat_IRQ) + TICv(stat_SRQ);
|
||||
cpu_idl = TICv(stat_IDL);
|
||||
@ -318,10 +381,8 @@ static void new_format(void)
|
||||
pswpin[tog] = PROCPS_VMSTAT_GET(vm_info, PROCPS_VMSTAT_PSWPIN, ul_int);
|
||||
pswpout[tog] = PROCPS_VMSTAT_GET(vm_info, PROCPS_VMSTAT_PSWPOUT, ul_int);
|
||||
|
||||
if ((mem_stack = procps_meminfo_select(mem_info, Mem_items, 6)) ==
|
||||
NULL)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to select memory information"));
|
||||
if (!(mem_stack = procps_meminfo_select(mem_info, Mem_items, MAX_mem)))
|
||||
xerrx(EXIT_FAILURE, _("Unable to select memory information"));
|
||||
|
||||
Div = cpu_use + cpu_sys + cpu_idl + cpu_iow + cpu_sto;
|
||||
if (!Div) {
|
||||
@ -363,9 +424,8 @@ static void new_format(void)
|
||||
new_header();
|
||||
tog = !tog;
|
||||
|
||||
if ((stat_stack = procps_stat_select(sys_info, Loop_stat_items, 12)) == NULL)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to select stat information"));
|
||||
if (!(stat_stack = procps_stat_select(sys_info, Loop_stat_items, MAX_stat)))
|
||||
xerrx(EXIT_FAILURE, _("Unable to select stat information"));
|
||||
|
||||
cpu_use = DTICv(stat_USR) + DTICv(stat_NIC);
|
||||
cpu_sys = DTICv(stat_SYS) + DTICv(stat_IRQ) + DTICv(stat_SRQ);
|
||||
@ -448,6 +508,7 @@ static void diskpartition_header(const char *partition_name)
|
||||
{
|
||||
printf("%-10s %10s %10s %10s %10s\n",
|
||||
partition_name,
|
||||
|
||||
/* Translation Hint: Translating folloging disk partition
|
||||
* header fields that follow (marked with max x chars) might
|
||||
* not work, unless manual page is translated as well. */
|
||||
@ -465,46 +526,37 @@ static void diskpartition_header(const char *partition_name)
|
||||
_("requested writes"));
|
||||
}
|
||||
|
||||
static int diskpartition_format(const char *partition_name)
|
||||
static void diskpartition_format(const char *partition_name)
|
||||
{
|
||||
#define PARTGET(x) procps_diskstat_dev_get(disk_stat, (x), partid)
|
||||
struct procps_diskstat *disk_stat;
|
||||
#define partVAL(x) PROCPS_DISKSTATS_VAL(x, ul_int, stack)
|
||||
struct procps_diskstats *disk_stat;
|
||||
struct diskstats_stack *stack;
|
||||
struct diskstats_result *got;
|
||||
const char format[] = "%20lu %10lu %10lu %10lu\n";
|
||||
int i, partid;
|
||||
int i;
|
||||
|
||||
if (procps_diskstat_new(&disk_stat) < 0)
|
||||
if (procps_diskstats_new(&disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to create diskstat structure"));
|
||||
|
||||
if (procps_diskstat_read(disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to read diskstat"));
|
||||
if ((partid = procps_diskstat_dev_getbyname(disk_stat, partition_name)) < 0
|
||||
|| procps_diskstat_dev_isdisk(disk_stat, partid))
|
||||
xerrx(EXIT_FAILURE, _("Partition %s not found"), partition_name);
|
||||
if (!(got = procps_diskstats_get(disk_stat, partition_name, PROCPS_DISKSTATS_TYPE)))
|
||||
xerrx(EXIT_FAILURE, _("Disk/Partition %s not found"), partition_name);
|
||||
|
||||
diskpartition_header(partition_name);
|
||||
|
||||
for (i = 0; infinite_updates || i < num_updates ; i++) {
|
||||
if (procps_diskstat_read(disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to read diskstat"));
|
||||
if ((partid = procps_diskstat_dev_getbyname(disk_stat, partition_name))
|
||||
< 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Partition %s not found"), partition_name);
|
||||
|
||||
if (!(stack = procps_diskstats_select(disk_stat, partition_name, Part_items, MAX_part)))
|
||||
xerrx(EXIT_FAILURE, _("Disk/Partition %s not found"), partition_name);
|
||||
printf(format,
|
||||
PARTGET(PROCPS_DISKSTAT_READS),
|
||||
PARTGET(PROCPS_DISKSTAT_READ_SECTORS),
|
||||
PARTGET(PROCPS_DISKSTAT_WRITES),
|
||||
PARTGET(PROCPS_DISKSTAT_WRITE_SECTORS)
|
||||
);
|
||||
|
||||
partVAL(part_READ),
|
||||
partVAL(part_READ_SECT),
|
||||
partVAL(part_WRITE),
|
||||
partVAL(part_WRITE_SECT));
|
||||
if (infinite_updates || i+1 < num_updates)
|
||||
sleep(sleep_time);
|
||||
}
|
||||
procps_diskstat_unref(&disk_stat);
|
||||
return 0;
|
||||
procps_diskstats_unref(&disk_stat);
|
||||
#undef partVAL
|
||||
}
|
||||
|
||||
static void diskheader(void)
|
||||
@ -574,49 +626,49 @@ static void diskheader(void)
|
||||
|
||||
static void diskformat(void)
|
||||
{
|
||||
#define DSTAT(x) procps_diskstat_dev_get(disk_stat, (x), diskid)
|
||||
struct procps_diskstat *disk_stat;
|
||||
int i,diskid, disk_count;
|
||||
#define diskVAL(e,t) PROCPS_DISKSTATS_VAL(e, t, reap->stacks[j])
|
||||
struct procps_diskstats *disk_stat;
|
||||
struct diskstats_reap *reap;
|
||||
int i, j;
|
||||
time_t the_time;
|
||||
struct tm *tm_ptr;
|
||||
char timebuf[32];
|
||||
const char format[] = "%-5s %6lu %6lu %7lu %7lu %6lu %6lu %7lu %7lu %6lu %6lu";
|
||||
const char wide_format[] = "%-5s %9lu %9lu %11lu %11lu %9lu %9lu %11lu %11lu %7lu %7lu";
|
||||
|
||||
if (procps_diskstat_new(&disk_stat) < 0)
|
||||
if (procps_diskstats_new(&disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to create diskstat structure"));
|
||||
|
||||
if (!moreheaders)
|
||||
diskheader();
|
||||
for (i=0; infinite_updates || i < num_updates ; i++) {
|
||||
if (procps_diskstat_read(disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to read diskstat data"));
|
||||
|
||||
for (i=0; infinite_updates || i < num_updates ; i++) {
|
||||
if (!(reap = procps_diskstats_reap(disk_stat, Disk_items, MAX_disk)))
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to retrieve disk statistics"));
|
||||
if (t_option) {
|
||||
(void) time( &the_time );
|
||||
tm_ptr = localtime( &the_time );
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
|
||||
}
|
||||
disk_count = procps_diskstat_dev_count(disk_stat);
|
||||
for (diskid = 0; diskid < disk_count; diskid++) {
|
||||
if (procps_diskstat_dev_isdisk(disk_stat, diskid) != 1)
|
||||
for (j = 0; j < reap->total; j++) {
|
||||
if (diskVAL(disk_TYPE, s_int) != PROCPS_DISKSTATS_TYPE_DISK)
|
||||
continue; /* not a disk */
|
||||
if (moreheaders && ((diskid % height) == 0))
|
||||
if (moreheaders && ((j % height) == 0))
|
||||
diskheader();
|
||||
printf(w_option ? wide_format : format,
|
||||
procps_diskstat_dev_getname(disk_stat, diskid),
|
||||
DSTAT(PROCPS_DISKSTAT_READS),
|
||||
DSTAT(PROCPS_DISKSTAT_READS_MERGED),
|
||||
DSTAT(PROCPS_DISKSTAT_READ_SECTORS),
|
||||
DSTAT(PROCPS_DISKSTAT_READ_TIME),
|
||||
DSTAT(PROCPS_DISKSTAT_WRITES),
|
||||
DSTAT(PROCPS_DISKSTAT_WRITES_MERGED),
|
||||
DSTAT(PROCPS_DISKSTAT_WRITE_SECTORS),
|
||||
DSTAT(PROCPS_DISKSTAT_WRITE_TIME),
|
||||
DSTAT(PROCPS_DISKSTAT_IO_INPROGRESS) / 1000,
|
||||
DSTAT(PROCPS_DISKSTAT_IO_TIME) / 1000);
|
||||
diskVAL(disk_NAME, str),
|
||||
diskVAL(disk_READ, ul_int),
|
||||
diskVAL(disk_READ_MERGE, ul_int),
|
||||
diskVAL(disk_READ_SECT, ul_int),
|
||||
diskVAL(disk_READ_TIME, ul_int),
|
||||
diskVAL(disk_WRITE, ul_int),
|
||||
diskVAL(disk_WRITE_MERGE, ul_int),
|
||||
diskVAL(disk_WRITE_SECT, ul_int),
|
||||
diskVAL(disk_WRITE_TIME, ul_int),
|
||||
diskVAL(disk_IO, ul_int) / 1000,
|
||||
diskVAL(disk_IO_TIME, ul_int) / 1000);
|
||||
if (t_option)
|
||||
printf(" %s\n", timebuf);
|
||||
else
|
||||
@ -626,8 +678,8 @@ static void diskformat(void)
|
||||
if (infinite_updates || i+1 < num_updates)
|
||||
sleep(sleep_time);
|
||||
}
|
||||
#undef DSTAT
|
||||
procps_diskstat_unref(&disk_stat);
|
||||
#undef diskVAL
|
||||
procps_diskstats_unref(&disk_stat);
|
||||
}
|
||||
|
||||
static void slabheader(void)
|
||||
@ -693,18 +745,10 @@ static void slabformat (void)
|
||||
|
||||
static void disksum_format(void)
|
||||
{
|
||||
#define DSTAT(x) procps_diskstat_dev_get(disk_stat, (x), devid)
|
||||
struct procps_diskstat *disk_stat;
|
||||
|
||||
if (procps_diskstat_new(&disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to create diskstat structure"));
|
||||
|
||||
if (procps_diskstat_read(disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to read diskstat"));
|
||||
|
||||
int devid, dev_count, disk_count, part_count ;
|
||||
#define diskVAL(e,t) PROCPS_DISKSTATS_VAL(e, t, reap->stacks[j])
|
||||
struct procps_diskstats *disk_stat;
|
||||
struct diskstats_reap *reap;
|
||||
int j, disk_count, part_count;
|
||||
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;
|
||||
@ -714,31 +758,35 @@ static void disksum_format(void)
|
||||
milli_spent_IO = weighted_milli_spent_IO = 0;
|
||||
disk_count = part_count = 0;
|
||||
|
||||
if ((dev_count = procps_diskstat_dev_count(disk_stat)) < 0)
|
||||
if (procps_diskstats_new(&disk_stat) < 0)
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to count diskstat devices"));
|
||||
_("Unable to create diskstat structure"));
|
||||
if (!(reap = procps_diskstats_reap(disk_stat, Disk_items, MAX_disk)))
|
||||
xerr(EXIT_FAILURE,
|
||||
_("Unable to retrieve disk statistics"));
|
||||
|
||||
for (devid=0; devid < dev_count; devid++) {
|
||||
if (procps_diskstat_dev_isdisk(disk_stat, devid) != 1) {
|
||||
for (j = 0; j < reap->total; j++) {
|
||||
if (diskVAL(disk_TYPE, s_int) != PROCPS_DISKSTATS_TYPE_DISK) {
|
||||
part_count++;
|
||||
continue; /* not a disk */
|
||||
}
|
||||
disk_count++;
|
||||
reads += DSTAT(PROCPS_DISKSTAT_READS);
|
||||
merged_reads += DSTAT(PROCPS_DISKSTAT_READS_MERGED);
|
||||
read_sectors += DSTAT(PROCPS_DISKSTAT_READ_SECTORS);
|
||||
milli_reading += DSTAT(PROCPS_DISKSTAT_READ_TIME);
|
||||
writes += DSTAT(PROCPS_DISKSTAT_WRITES);
|
||||
merged_writes += DSTAT(PROCPS_DISKSTAT_WRITES_MERGED);
|
||||
written_sectors += DSTAT(PROCPS_DISKSTAT_WRITE_SECTORS);
|
||||
milli_writing += DSTAT(PROCPS_DISKSTAT_WRITE_TIME);
|
||||
inprogress_IO += DSTAT(PROCPS_DISKSTAT_IO_INPROGRESS) / 1000;
|
||||
milli_spent_IO += DSTAT(PROCPS_DISKSTAT_IO_TIME) / 1000;
|
||||
weighted_milli_spent_IO += DSTAT(PROCPS_DISKSTAT_IO_TIME) / 1000;
|
||||
|
||||
reads += diskVAL(disk_READ, ul_int);
|
||||
merged_reads += diskVAL(disk_READ_MERGE, ul_int);
|
||||
read_sectors += diskVAL(disk_READ_SECT, ul_int);
|
||||
milli_reading += diskVAL(disk_READ_TIME, ul_int);
|
||||
writes += diskVAL(disk_WRITE, ul_int);
|
||||
merged_writes += diskVAL(disk_WRITE_MERGE, ul_int);
|
||||
written_sectors += diskVAL(disk_WRITE_SECT, ul_int);
|
||||
milli_writing += diskVAL(disk_WRITE_TIME, ul_int);
|
||||
inprogress_IO += diskVAL(disk_IO, ul_int) / 1000;
|
||||
milli_spent_IO += diskVAL(disk_IO_TIME, ul_int) / 1000;
|
||||
weighted_milli_spent_IO += diskVAL(disk_IO_WTIME, ul_int) / 1000;
|
||||
}
|
||||
printf(_("%13d disks\n"), disk_count);
|
||||
printf(_("%13d partitions\n"), part_count);
|
||||
printf(_("%13lu reads\n"), reads);
|
||||
printf(_("%13d disks\n"), disk_count); // <== old vmstat had a trailing space here
|
||||
printf(_("%13d partitions\n"), part_count); // <== old vmstat had a trailing space here too
|
||||
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);
|
||||
@ -749,54 +797,11 @@ static void disksum_format(void)
|
||||
printf(_("%13lu inprogress IO\n"), inprogress_IO);
|
||||
printf(_("%13lu milli spent IO\n"), milli_spent_IO);
|
||||
printf(_("%13lu milli weighted IO\n"), weighted_milli_spent_IO);
|
||||
#undef DSTAT
|
||||
procps_diskstat_unref(&disk_stat);
|
||||
|
||||
procps_diskstats_unref(&disk_stat);
|
||||
#undef diskVAL
|
||||
}
|
||||
|
||||
static enum stat_item Sum_stat_items[] = {
|
||||
PROCPS_STAT_TIC_USER,
|
||||
PROCPS_STAT_TIC_NICE,
|
||||
PROCPS_STAT_TIC_SYSTEM,
|
||||
PROCPS_STAT_TIC_IDLE,
|
||||
PROCPS_STAT_TIC_IOWAIT,
|
||||
PROCPS_STAT_TIC_IRQ,
|
||||
PROCPS_STAT_TIC_SOFTIRQ,
|
||||
PROCPS_STAT_TIC_STOLEN,
|
||||
PROCPS_STAT_TIC_GUEST,
|
||||
PROCPS_STAT_TIC_GUEST_NICE,
|
||||
PROCPS_STAT_SYS_CTX_SWITCHES,
|
||||
PROCPS_STAT_SYS_INTERRUPTS,
|
||||
PROCPS_STAT_SYS_TIME_OF_BOOT,
|
||||
PROCPS_STAT_SYS_PROC_CREATED
|
||||
};
|
||||
|
||||
enum Rel_sumstatitems {
|
||||
sstat_USR, sstat_NIC, sstat_SYS, sstat_IDL,
|
||||
sstat_IOW, sstat_IRQ, sstat_SRQ, sstat_STO,
|
||||
sstat_GST, sstat_GNI,
|
||||
sstat_CTX, sstat_INT, sstat_TOB,
|
||||
sstat_PCR
|
||||
};
|
||||
|
||||
static enum meminfo_item Sum_mem_items[] = {
|
||||
PROCPS_MEMINFO_MEM_TOTAL,
|
||||
PROCPS_MEMINFO_MEM_USED,
|
||||
PROCPS_MEMINFO_MEM_ACTIVE,
|
||||
PROCPS_MEMINFO_MEM_INACTIVE,
|
||||
PROCPS_MEMINFO_MEM_FREE,
|
||||
PROCPS_MEMINFO_MEM_BUFFERS,
|
||||
PROCPS_MEMINFO_MEM_CACHED,
|
||||
PROCPS_MEMINFO_SWAP_TOTAL,
|
||||
PROCPS_MEMINFO_SWAP_USED,
|
||||
PROCPS_MEMINFO_SWAP_FREE,
|
||||
};
|
||||
|
||||
enum Rel_summemitems {
|
||||
smem_MTOT, smem_MUSE, smem_MACT, smem_MIAC, smem_MFRE,
|
||||
smem_MBUF, smem_MCAC,
|
||||
smem_STOT, smem_SUSE, smem_SFRE
|
||||
};
|
||||
|
||||
static void sum_format(void)
|
||||
{
|
||||
#define TICv(E) PROCPS_STAT_VAL(E, ull_int, stat_stack)
|
||||
@ -809,22 +814,15 @@ static void sum_format(void)
|
||||
struct meminfo_stack *mem_stack;
|
||||
|
||||
if (procps_stat_new(&sys_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to create system stat structure"));
|
||||
if ((stat_stack = procps_stat_select(sys_info, Sum_stat_items, 14)) ==
|
||||
NULL)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to select stat information"));
|
||||
|
||||
xerrx(EXIT_FAILURE, _("Unable to create system stat structure"));
|
||||
if (!(stat_stack = procps_stat_select(sys_info, Sum_stat_items, 14)))
|
||||
xerrx(EXIT_FAILURE, _("Unable to select stat information"));
|
||||
if (procps_vmstat_new(&vm_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to create vmstat structure"));
|
||||
xerrx(EXIT_FAILURE, _("Unable to create vmstat structure"));
|
||||
if (procps_meminfo_new(&mem_info) < 0)
|
||||
xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
|
||||
if ((mem_stack = procps_meminfo_select(mem_info, Sum_mem_items, 10)) ==
|
||||
NULL)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to select memory information"));
|
||||
if (!(mem_stack = procps_meminfo_select(mem_info, Sum_mem_items, 10)))
|
||||
xerrx(EXIT_FAILURE, _("Unable to select memory information"));
|
||||
|
||||
printf(_("%13lu %s total memory\n"), MEMv(smem_MTOT), szDataUnit);
|
||||
printf(_("%13lu %s used memory\n"), MEMv(smem_MUSE), szDataUnit);
|
||||
@ -869,8 +867,7 @@ static void fork_format(void)
|
||||
struct procps_statinfo *sys_info = NULL;
|
||||
|
||||
if (procps_stat_new(&sys_info) < 0)
|
||||
xerrx(EXIT_FAILURE,
|
||||
_("Unable to create system stat structure"));
|
||||
xerrx(EXIT_FAILURE, _("Unable to create system stat structure"));
|
||||
|
||||
printf(_("%13lu forks\n"), PROCPS_STAT_GET(sys_info, PROCPS_STAT_SYS_PROC_CREATED, ul_int));
|
||||
/* Cleanup */
|
||||
@ -920,8 +917,7 @@ int main(int argc, char *argv[])
|
||||
atexit(close_stdout);
|
||||
|
||||
while ((c =
|
||||
getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts,
|
||||
NULL)) != EOF)
|
||||
getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts, NULL)) != EOF)
|
||||
switch (c) {
|
||||
case 'V':
|
||||
printf(PROCPS_NG_VERSION);
|
||||
@ -974,9 +970,8 @@ int main(int argc, char *argv[])
|
||||
dataUnit = UNIT_M;
|
||||
break;
|
||||
default:
|
||||
xerrx(EXIT_FAILURE,
|
||||
/* Translation Hint: do not change argument characters */
|
||||
_("-S requires k, K, m or M (default is KiB)"));
|
||||
xerrx(EXIT_FAILURE, _("-S requires k, K, m or M (default is KiB)"));
|
||||
}
|
||||
szDataUnit[0] = optarg[0];
|
||||
break;
|
||||
@ -1027,8 +1022,7 @@ int main(int argc, char *argv[])
|
||||
diskformat();
|
||||
break;
|
||||
case (PARTITIONSTAT):
|
||||
if (diskpartition_format(partition) == -1)
|
||||
printf(_("partition was not found\n"));
|
||||
diskpartition_format(partition);
|
||||
break;
|
||||
case (SLABSTAT):
|
||||
slabformat();
|
||||
|
Loading…
x
Reference in New Issue
Block a user