library: Fix up stat API

Adjusted vmstat to use the new API for memory and CPU statistics
This commit is contained in:
Craig Small 2015-06-23 22:22:50 +10:00
parent ca4a09c432
commit 05efbebb66
8 changed files with 208 additions and 119 deletions

View File

@ -193,9 +193,10 @@ proc_libprocps_la_include_HEADERS = \
proc/sig.h \
proc/slab.h \
proc/sysinfo.h \
proc/uptime.h \
proc/version.h \
proc/wchan.h \
proc/whattime.h
proc/vmstat.h \
proc/wchan.h
dist_man_MANS += \
proc/openproc.3 \

63
free.c
View File

@ -27,8 +27,6 @@
*/
#include "config.h"
#include "proc/sysinfo.h"
#include "proc/version.h"
#include "c.h"
#include "nls.h"
#include "strutils.h"
@ -43,6 +41,10 @@
#include <stdlib.h>
#include <unistd.h>
#include <proc/sysinfo.h>
#include <proc/version.h>
#include <proc/meminfo.h>
#ifndef SIZE_MAX
#define SIZE_MAX 32
#endif
@ -204,6 +206,7 @@ int main(int argc, char **argv)
int c, flags = 0, unit_set = 0;
char *endptr;
struct commandline_arguments args;
struct procps_meminfo *mem_info;
/*
* For long options that have no equivalent short option, use a
@ -351,9 +354,14 @@ int main(int argc, char **argv)
usage(stderr);
}
if (procps_meminfo_new(&mem_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to create meminfo structure"));
do {
if (procps_meminfo_read(mem_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read meminfo information"));
meminfo();
/* Translation Hint: You can use 9 character words in
* the header, and the words need to be right align to
* beginning of a number. */
@ -364,17 +372,20 @@ int main(int argc, char **argv)
}
printf("\n");
printf("%-7s", _("Mem:"));
printf(" %11s", scale_size(kb_main_total, flags, args));
printf(" %11s", scale_size(kb_main_used, flags, args));
printf(" %11s", scale_size(kb_main_free, flags, args));
printf(" %11s", scale_size(kb_main_shared, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_TOTAL), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_USED), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_FREE), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_SHARED), flags, args));
if (flags & FREE_WIDE) {
printf(" %11s", scale_size(kb_main_buffers, flags, args));
printf(" %11s", scale_size(kb_main_cached, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_BUFFERS),
flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_CACHED)
, flags, args));
} else {
printf(" %11s", scale_size(kb_main_buffers+kb_main_cached, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_BUFFERS)+
procps_meminfo_get(mem_info, PROCPS_MEM_CACHED), flags, args));
}
printf(" %11s", scale_size(kb_main_available, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEM_AVAILABLE), flags, args));
printf("\n");
/*
* Print low vs. high information, if the user requested it.
@ -384,29 +395,35 @@ int main(int argc, char **argv)
*/
if (flags & FREE_LOHI) {
printf("%-7s", _("Low:"));
printf(" %11s", scale_size(kb_low_total, flags, args));
printf(" %11s", scale_size(kb_low_total - kb_low_free, flags, args));
printf(" %11s", scale_size(kb_low_free, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMLO_TOTAL), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMLO_USED), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMLO_FREE), flags, args));
printf("\n");
printf("%-7s", _("High:"));
printf(" %11s", scale_size(kb_high_total, flags, args));
printf(" %11s", scale_size(kb_high_total - kb_high_free, flags, args));
printf(" %11s", scale_size(kb_high_free, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMHI_TOTAL), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMHI_USED), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_MEMHI_FREE), flags, args));
printf("\n");
}
printf("%-7s", _("Swap:"));
printf(" %11s", scale_size(kb_swap_total, flags, args));
printf(" %11s", scale_size(kb_swap_used, flags, args));
printf(" %11s", scale_size(kb_swap_free, flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_SWAP_TOTAL), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_SWAP_USED), flags, args));
printf(" %11s", scale_size(procps_meminfo_get(mem_info, PROCPS_SWAP_FREE), flags, args));
printf("\n");
if (flags & FREE_TOTAL) {
printf("%-7s", _("Total:"));
printf(" %11s", scale_size(kb_main_total + kb_swap_total, flags, args));
printf(" %11s", scale_size(kb_main_used + kb_swap_used, flags, args));
printf(" %11s", scale_size(kb_main_free + kb_swap_free, flags, args));
printf(" %11s", scale_size(
procps_meminfo_get(mem_info, PROCPS_MEM_TOTAL)+
procps_meminfo_get(mem_info, PROCPS_SWAP_TOTAL), flags, args));
printf(" %11s", scale_size(
procps_meminfo_get(mem_info, PROCPS_MEM_USED)+
procps_meminfo_get(mem_info, PROCPS_SWAP_USED), flags, args));
printf(" %11s", scale_size(
procps_meminfo_get(mem_info, PROCPS_MEM_FREE)+
procps_meminfo_get(mem_info, PROCPS_SWAP_FREE), flags, args));
printf("\n");
}
fflush(stdout);

View File

@ -38,13 +38,13 @@ struct meminfo_data {
unsigned long high_total;
unsigned long low_free;
unsigned long low_total;
unsigned long main_available;
unsigned long main_buffers;
unsigned long main_cached;
unsigned long main_free;
unsigned long main_shared;
unsigned long main_total;
unsigned long main_used;
unsigned long available;
unsigned long buffers;
unsigned long cached;
unsigned long free;
unsigned long shared;
unsigned long total;
unsigned long used;
unsigned long swap_free;
unsigned long swap_total;
unsigned long swap_used;
@ -131,23 +131,23 @@ PROCPS_EXPORT int procps_meminfo_read(struct procps_meminfo *info)
} else if (0 == strcmp(head, "LowTotal:")) {
valptr = &(info->data.low_total);
} else if (0 == strcmp(head, "MemAvailable:")) {
valptr = &(info->data.main_available);
valptr = &(info->data.available);
} else if (0 == strcmp(head, "Buffers:")) {
valptr = &(info->data.main_buffers);
valptr = &(info->data.buffers);
} else if (0 == strcmp(head, "Cached:")) {
valptr = &(info->data.main_cached);
valptr = &(info->data.cached);
} else if (0 == strcmp(head, "MemFree:")) {
valptr = &(info->data.main_free);
valptr = &(info->data.free);
} else if (0 == strcmp(head, "Shmem:")) {
valptr = &(info->data.main_shared);
valptr = &(info->data.shared);
} else if (0 == strcmp(head, "MemTotal:")) {
valptr = &(info->data.main_total);
valptr = &(info->data.total);
} else if (0 == strcmp(head, "SwapFree:")) {
valptr = &(info->data.swap_free);
} else if (0 == strcmp(head, "SwapTotal:")) {
valptr = &(info->data.swap_total);
}
head - tail+1;
head = tail+1;
if (valptr) {
*valptr = strtoul(head, &tail, 10);
}
@ -186,9 +186,45 @@ PROCPS_EXPORT unsigned long procps_meminfo_get(
enum meminfo_item item)
{
switch(item) {
case PROCPS_MEMINFO_ACTIVE:
case PROCPS_MEM_ACTIVE:
return info->data.active;
case PROCPS_MEMINFO_SWAP_USED:
case PROCPS_MEM_INACTIVE:
return info->data.inactive;
case PROCPS_MEMHI_FREE:
return info->data.high_free;
case PROCPS_MEMHI_TOTAL:
return info->data.high_total;
case PROCPS_MEMHI_USED:
if (info->data.high_free > info->data.high_total)
return 0;
return info->data.high_total - info->data.high_free;
case PROCPS_MEMLO_FREE:
return info->data.low_free;
case PROCPS_MEMLO_TOTAL:
return info->data.low_total;
case PROCPS_MEMLO_USED:
if (info->data.low_free > info->data.low_total)
return 0;
return info->data.low_total - info->data.low_free;
case PROCPS_MEM_AVAILABLE:
return info->data.available;
case PROCPS_MEM_BUFFERS:
return info->data.buffers;
case PROCPS_MEM_CACHED:
return info->data.cached;
case PROCPS_MEM_FREE:
return info->data.free;
case PROCPS_MEM_SHARED:
return info->data.shared;
case PROCPS_MEM_TOTAL:
return info->data.total;
case PROCPS_MEM_USED:
return info->data.used;
case PROCPS_SWAP_FREE:
return info->data.swap_free;
case PROCPS_SWAP_TOTAL:
return info->data.swap_total;
case PROCPS_SWAP_USED:
if (info->data.swap_free > info->data.swap_total)
return 0;
return info->data.swap_total - info->data.swap_free;

View File

@ -33,22 +33,24 @@ struct procps_meminfo *procps_meminfo_ref(struct procps_meminfo *info);
struct procps_meminfo *procps_meminfo_unref(struct procps_meminfo *info);
enum meminfo_item {
PROCPS_MEMINFO_ACTIVE,
PROCPS_MEMINFO_INACTIVE,
PROCPS_MEMINFO_HIGH_FREE,
PROCPS_MEMINFO_HIGH_TOTAL,
PROCPS_MEMINFO_LOW_FREE,
PROCPS_MEMINFO_LOW_TOTAL,
PROCPS_MEMINFO_MAIN_AVAILABLE,
PROCPS_MEMINFO_MAIN_BUFFERS,
PROCPS_MEMINFO_MAIN_CACHED,
PROCPS_MEMINFO_MAIN_FREE,
PROCPS_MEMINFO_MAIN_SHARED,
PROCPS_MEMINFO_MAIN_TOTAL,
PROCPS_MEMINFO_MAIN_USED,
PROCPS_MEMINFO_SWAP_FREE,
PROCPS_MEMINFO_SWAP_TOTAL,
PROCPS_MEMINFO_SWAP_USED,
PROCPS_MEM_ACTIVE,
PROCPS_MEM_INACTIVE,
PROCPS_MEMHI_FREE,
PROCPS_MEMHI_TOTAL,
PROCPS_MEMHI_USED,
PROCPS_MEMLO_FREE,
PROCPS_MEMLO_TOTAL,
PROCPS_MEMLO_USED,
PROCPS_MEM_AVAILABLE,
PROCPS_MEM_BUFFERS,
PROCPS_MEM_CACHED,
PROCPS_MEM_FREE,
PROCPS_MEM_SHARED,
PROCPS_MEM_TOTAL,
PROCPS_MEM_USED,
PROCPS_SWAP_FREE,
PROCPS_SWAP_TOTAL,
PROCPS_SWAP_USED,
};
unsigned long procps_meminfo_get(struct procps_meminfo *info, enum meminfo_item item);

View File

@ -188,9 +188,9 @@ PROCPS_EXPORT jiff procps_stat_get_cpu(struct procps_stat_info *info, enum procp
PROCPS_EXPORT unsigned int procps_stat_get(struct procps_stat_info *info, enum procps_stat_item item)
{
switch(item) {
case PROCPS_STAT_INTERRUPTS:
case PROCPS_STAT_INTR:
return info->data.intr;
case PROCPS_STAT_CONTEXT:
case PROCPS_STAT_CTXT:
return info->data.ctxt;
case PROCPS_STAT_BTIME:
return info->data.btime;

View File

@ -36,8 +36,8 @@ enum procps_cpu_item {
};
enum procps_stat_item {
PROCPS_STAT_INTERRUPTS,
PROCPS_STAT_CONTEXT,
PROCPS_STAT_INTR,
PROCPS_STAT_CTXT,
PROCPS_STAT_BTIME,
PROCPS_STAT_PROCS,
PROCPS_STAT_PROCS_BLK,

View File

@ -107,13 +107,14 @@ PROCPS_EXPORT char *sprint_uptime(void)
double uptime_secs, idle_secs;
double av1, av5, av15;
upbuf[0] = '\0';
if (time(&realseconds) < 0)
return NULL;
return upbuf;
realtime = localtime(&realseconds);
pos = sprintf(upbuf, " %02d:%02d:%02d ",
realtime->tm_hour, realtime->tm_min, realtime->tm_sec);
if (uptime(&uptime_secs, &idle_secs) < 0)
return NULL;
return upbuf;
updays = ((int) uptime_secs / (60*60*24));
uphours = ((int) uptime_secs / (60*24)) % 24;
@ -134,7 +135,7 @@ PROCPS_EXPORT char *sprint_uptime(void)
users, users == 1 ? "" : "s",
av1, av5, av15);
return upbuf;
}
PROCPS_EXPORT char *sprint_uptime_short(void)
@ -146,8 +147,9 @@ PROCPS_EXPORT char *sprint_uptime_short(void)
struct tm *realtime;
double uptime_secs, idle_secs;
shortbuf[0] = '\0';
if (uptime(&uptime_secs, &idle_secs) < 0)
return NULL;
return shortbuf;
updecades = (int) uptime_secs / (60*60*24*365*10);
upyears = ((int) uptime_secs / (60*60*24*365)) % 10;

139
vmstat.c
View File

@ -52,6 +52,7 @@
#include "proc/version.h"
#include <proc/vmstat.h>
#include <proc/readstat.h>
#include <proc/meminfo.h>
#define UNIT_B 1
#define UNIT_k 1000
@ -285,11 +286,10 @@ static void new_format(void)
unsigned int tog = 0; /* toggle switch for cleaner code */
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], cpu_sto[2];
jiff duse, dsys, didl, diow, dstl, Div, divo2;
unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
unsigned long pgpgin[2], pgpgout[2], pswpin[2] = {0,0}, pswpout[2];
unsigned int intr[2], ctxt[2];
unsigned int sleep_half;
unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
@ -299,10 +299,10 @@ static void new_format(void)
char timebuf[32];
struct procps_vmstat *vm_info;
struct procps_stat_info *sys_info;
struct procps_meminfo *mem_info;
sleep_half = (sleep_time / 2);
new_header();
meminfo();
if (procps_vmstat_new(&vm_info) < 0)
xerrx(EXIT_FAILURE,
@ -316,40 +316,59 @@ static void new_format(void)
if (procps_stat_read(sys_info, 0) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read system stat information"));
if (procps_meminfo_new(&mem_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to create meminfo structure"));
if (procps_meminfo_read(mem_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read meminfo information"));
if (t_option) {
(void) time( &the_time );
tm_ptr = localtime( &the_time );
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
}
duse = procps_stat_get_cpu(sys_info, PROCPS_CPU_USER) +
/* Do the intial fill */
cpu_use[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_USER) +
procps_stat_get_cpu(sys_info, PROCPS_CPU_NICE);
dsys = procps_stat_get_cpu(sys_info, PROCPS_CPU_SYSTEM) +
cpu_sys[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_SYSTEM);
procps_stat_get_cpu(sys_info, PROCPS_CPU_IRQ) +
procps_stat_get_cpu(sys_info, PROCPS_CPU_SIRQ);
didl = procps_stat_get_cpu(sys_info, PROCPS_CPU_IDLE);
diow = procps_stat_get_cpu(sys_info, PROCPS_CPU_IOWAIT);
dstl = procps_stat_get_cpu(sys_info, PROCPS_CPU_STOLEN);
Div = duse + dsys + didl + diow + dstl;
if (!Div) Div = 1, didl = 1;
cpu_idl[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_IDLE);
cpu_iow[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_IOWAIT);
cpu_sto[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_STOLEN);
intr[tog] = procps_stat_get(sys_info, PROCPS_STAT_INTR);
ctxt[tog] = procps_stat_get(sys_info, PROCPS_STAT_CTXT);
pgpgin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN);
pgpgout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT);
pswpin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN);
pswpout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT);
Div = cpu_use[tog] + cpu_sys[tog] + cpu_idl[tog] + cpu_iow[tog] + cpu_sto[tog];
if (!Div) {
Div = 1;
cpu_idl[tog] = 1;
}
divo2 = Div / 2UL;
printf(w_option ? wide_format : 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),
procps_stat_get(sys_info, PROCPS_STAT_PROCS_RUN),
procps_stat_get(sys_info, PROCPS_STAT_PROCS_BLK),
unitConvert(procps_meminfo_get(mem_info, PROCPS_SWAP_USED)),
unitConvert(procps_meminfo_get(mem_info, PROCPS_MEM_FREE)),
unitConvert(procps_meminfo_get(mem_info, (a_option?PROCPS_MEM_INACTIVE:PROCPS_MEM_BUFFERS))),
unitConvert(procps_meminfo_get(mem_info, a_option?PROCPS_MEM_ACTIVE:PROCPS_MEM_CACHED)),
(unsigned)( (unitConvert(procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN) * kb_per_page) * hz + divo2) / Div ),
(unsigned)( (unitConvert(procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT) * kb_per_page) * hz + divo2) / Div ),
(unsigned)( (procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN) * hz + divo2) / Div ),
(unsigned)( (procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT) * hz + divo2) / Div ),
(unsigned)( (procps_stat_get(sys_info, PROCPS_STAT_INTERRUPTS) * hz + divo2) / Div ),
(unsigned)( (procps_stat_get(sys_info, PROCPS_STAT_CONTEXT) * hz + divo2) / Div ),
(unsigned)( (100*duse + divo2) / Div ),
(unsigned)( (100*dsys + divo2) / Div ),
(unsigned)( (100*didl + divo2) / Div ),
(unsigned)( (100*diow + divo2) / Div ),
(unsigned)( (100*dstl + divo2) / Div )
(unsigned)( (intr[tog] * hz + divo2) / Div ),
(unsigned)( (ctxt[tog] * hz + divo2) / Div ),
(unsigned)( (100*cpu_use[tog] + divo2) / Div ),
(unsigned)( (100*cpu_sys[tog] + divo2) / Div ),
(unsigned)( (100*cpu_idl[tog] + divo2) / Div ),
(unsigned)( (100*cpu_iow[tog] + divo2) / Div ),
(unsigned)( (100*cpu_sto[tog] + divo2) / Div )
);
if (t_option) {
@ -365,28 +384,31 @@ static void new_format(void)
new_header();
tog = !tog;
meminfo();
if (procps_stat_read(sys_info,0) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read system stat information"));
cpu_use[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_USER);
cpu_nic[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_NICE);
if (procps_vmstat_read(vm_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read vmstat information"));
cpu_use[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_USER) +
procps_stat_get_cpu(sys_info, PROCPS_CPU_NICE);
cpu_sys[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_SYSTEM);
procps_stat_get_cpu(sys_info, PROCPS_CPU_IRQ) +
procps_stat_get_cpu(sys_info, PROCPS_CPU_SIRQ);
cpu_idl[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_IDLE);
cpu_iow[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_IOWAIT);
cpu_sto[tog] = procps_stat_get_cpu(sys_info, PROCPS_CPU_STOLEN);
if (procps_vmstat_read(vm_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read vmstat information"));
intr[tog] = procps_stat_get(sys_info, PROCPS_STAT_INTR);
ctxt[tog] = procps_stat_get(sys_info, PROCPS_STAT_CTXT);
pgpgin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN);
pgpgout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT);
pswpin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN);
pswpout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT);
if (procps_meminfo_read(mem_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read memory information"));
if (t_option) {
(void) time( &the_time );
@ -394,11 +416,8 @@ static void new_format(void)
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
}
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];
duse = cpu_use[tog] - cpu_use[!tog];
dsys = cpu_sys[tog] - cpu_sys[!tog];
didl = cpu_idl[tog] - cpu_idl[!tog];
diow = cpu_iow[tog] - cpu_iow[!tog];
dstl = cpu_sto[tog] - cpu_sto[!tog];
@ -417,11 +436,14 @@ static void new_format(void)
if (!Div) Div = 1, didl = 1;
divo2 = Div / 2UL;
printf(w_option ? wide_format : 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),
procps_stat_get(sys_info, PROCPS_STAT_PROCS_RUN),
procps_stat_get(sys_info, PROCPS_STAT_PROCS_BLK),
unitConvert(procps_meminfo_get(mem_info, PROCPS_SWAP_USED)),
unitConvert(procps_meminfo_get(mem_info, PROCPS_MEM_FREE)),
unitConvert(procps_meminfo_get(mem_info,
(a_option?PROCPS_MEM_INACTIVE:PROCPS_MEM_BUFFERS))),
unitConvert(procps_meminfo_get(mem_info,
(a_option?PROCPS_MEM_ACTIVE:PROCPS_MEM_CACHED))),
/*si */
(unsigned)( ( unitConvert((pswpin [tog] - pswpin [!tog])*kb_per_page)+sleep_half )/sleep_time ),
/* so */
@ -816,8 +838,7 @@ static void sum_format(void)
{
struct procps_stat_info *sys_info;
struct procps_vmstat *vm_info;
meminfo();
struct procps_meminfo *mem_info;
if (procps_stat_new(&sys_info) < 0)
xerrx(EXIT_FAILURE,
@ -832,16 +853,26 @@ static void sum_format(void)
xerrx(EXIT_FAILURE,
_("Unable to read vmstat information"));
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 %s total memory\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_MEM_TOTAL)), szDataUnit);
printf(_("%13lu %s used memory\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_MEM_USED)), szDataUnit);
printf(_("%13lu %s active memory\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_MEM_ACTIVE)), szDataUnit);
printf(_("%13lu %s inactive memory\n"), unitConvert(
procps_meminfo_get(mem_info, PROCPS_MEM_INACTIVE)), szDataUnit);
printf(_("%13lu %s free memory\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_MEM_FREE)), szDataUnit);
printf(_("%13lu %s buffer memory\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_MEM_BUFFERS)), szDataUnit);
printf(_("%13lu %s swap cache\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_MEM_CACHED)), szDataUnit);
printf(_("%13lu %s total swap\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_SWAP_TOTAL)), szDataUnit);
printf(_("%13lu %s used swap\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_SWAP_USED)), szDataUnit);
printf(_("%13lu %s free swap\n"), unitConvert(procps_meminfo_get(
mem_info, PROCPS_SWAP_FREE)), szDataUnit);
printf(_("%13lld non-nice user cpu ticks\n"), procps_stat_get_cpu(sys_info, PROCPS_CPU_USER));
printf(_("%13lld nice user cpu ticks\n"), procps_stat_get_cpu(sys_info, PROCPS_CPU_NICE));
printf(_("%13lld system cpu ticks\n"), procps_stat_get_cpu(sys_info, PROCPS_CPU_SYSTEM));
@ -856,8 +887,8 @@ static void sum_format(void)
printf(_("%13lu pages paged out\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT));
printf(_("%13lu pages swapped in\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN));
printf(_("%13lu pages swapped out\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT));
printf(_("%13u interrupts\n"), procps_stat_get(sys_info, PROCPS_STAT_INTERRUPTS));
printf(_("%13u CPU context switches\n"), procps_stat_get(sys_info, PROCPS_STAT_CONTEXT));
printf(_("%13u interrupts\n"), procps_stat_get(sys_info, PROCPS_STAT_INTR));
printf(_("%13u CPU context switches\n"), procps_stat_get(sys_info, PROCPS_STAT_CTXT));
printf(_("%13u boot time\n"), procps_stat_get(sys_info, PROCPS_STAT_BTIME));
printf(_("%13u forks\n"), procps_stat_get(sys_info, PROCPS_STAT_PROCS));
}