library: tweak formatting for readstat header and code

This patch mostly just eliminates darn tab characters.

Plus the library function declarations and definitions
have been standardized. Most visibly, the input params
now have all been indented on their own separate line.

The following names were changed to more closely match
meminfo.c or provide a certain symmetry. Unfortunately
that also impacted some other pgms which were updated.

. 'procps_stat_get' evolved into 'procps_stat_get_sys'
. 'procps_stat_info' is now known as 'procps_statinfo'

[and just a little trailing whitespace was eliminated]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2015-06-28 00:00:00 -05:00 committed by Craig Small
parent c3fd7473c5
commit 6bb1a033b4
5 changed files with 137 additions and 122 deletions

View File

@ -73,7 +73,7 @@ global:
procps_stat_ref;
procps_stat_unref;
procps_stat_get_cpu;
procps_stat_get;
procps_stat_get_sys;
procps_vmstat_new;
procps_vmstat_read;
procps_vmstat_ref;

View File

@ -31,12 +31,13 @@ struct stat_data {
unsigned int procs_running;
};
struct procps_stat_info {
struct procps_statinfo {
int refcount;
int stat_fd;
struct stat_data data;
};
/*
* procps_stat_new:
*
@ -47,10 +48,11 @@ struct procps_stat_info {
*
* Returns: a new stat info container
*/
PROCPS_EXPORT int procps_stat_new(struct procps_stat_info **info)
PROCPS_EXPORT int procps_stat_new (
struct procps_statinfo **info)
{
struct procps_stat_info *v;
v = calloc(1, sizeof(struct procps_stat_info));
struct procps_statinfo *v;
v = calloc(1, sizeof(struct procps_statinfo));
if (!v)
return -ENOMEM;
@ -68,7 +70,9 @@ PROCPS_EXPORT int procps_stat_new(struct procps_stat_info **info)
*
* If CPU stats only needed, set cpu_only to non-zero
*/
PROCPS_EXPORT int procps_stat_read(struct procps_stat_info *info, const int cpu_only)
PROCPS_EXPORT int procps_stat_read (
struct procps_statinfo *info,
const int cpu_only)
{
char buf[8192];
char *head, *tail;
@ -133,13 +137,14 @@ PROCPS_EXPORT int procps_stat_read(struct procps_stat_info *info, const int cpu_
if (!tail)
break;
head = tail + 1;
} while(tail);
} while (tail);
if (info->data.procs)
info->data.procs--; // exclude this process
return 0;
}
PROCPS_EXPORT struct procps_stat_info *procps_stat_ref(struct procps_stat_info *info)
PROCPS_EXPORT struct procps_statinfo *procps_stat_ref (
struct procps_statinfo *info)
{
if (info == NULL)
return NULL;
@ -147,7 +152,8 @@ PROCPS_EXPORT struct procps_stat_info *procps_stat_ref(struct procps_stat_info *
return info;
}
PROCPS_EXPORT struct procps_stat_info *procps_stat_unref(struct procps_stat_info *info)
PROCPS_EXPORT struct procps_statinfo *procps_stat_unref (
struct procps_statinfo *info)
{
if (info == NULL)
return NULL;
@ -158,9 +164,11 @@ PROCPS_EXPORT struct procps_stat_info *procps_stat_unref(struct procps_stat_info
return NULL;
}
PROCPS_EXPORT jiff procps_stat_get_cpu(struct procps_stat_info *info, enum procps_cpu_item item)
PROCPS_EXPORT jiff procps_stat_get_cpu (
struct procps_statinfo *info,
enum procps_cpu_item item)
{
switch(item) {
switch (item) {
case PROCPS_CPU_USER:
return info->data.cpu_user;
case PROCPS_CPU_NICE:
@ -185,9 +193,11 @@ PROCPS_EXPORT jiff procps_stat_get_cpu(struct procps_stat_info *info, enum procp
return 0;
}
PROCPS_EXPORT unsigned int procps_stat_get(struct procps_stat_info *info, enum procps_stat_item item)
PROCPS_EXPORT unsigned int procps_stat_get_sys (
struct procps_statinfo *info,
enum procps_stat_item item)
{
switch(item) {
switch (item) {
case PROCPS_STAT_INTR:
return info->data.intr;
case PROCPS_STAT_CTXT:

View File

@ -45,12 +45,17 @@ enum procps_stat_item {
};
typedef unsigned long long jiff;
struct procps_stat_info;
int procps_stat_new(struct procps_stat_info **info);
int procps_stat_read(struct procps_stat_info *info, const int cpu_only);
struct procps_stat_info *procps_stat_ref(struct procps_stat_info *info);
struct procps_stat_info *procps_stat_unref(struct procps_stat_info *info);
jiff procps_stat_get_cpu(struct procps_stat_info *info, enum procps_cpu_item item);
unsigned int procps_stat_get(struct procps_stat_info *info, enum procps_stat_item item);
struct procps_statinfo;
int procps_stat_new (struct procps_statinfo **info);
int procps_stat_read (struct procps_statinfo *info, const int cpu_only);
struct procps_statinfo *procps_stat_ref (struct procps_statinfo *info);
struct procps_statinfo *procps_stat_unref (struct procps_statinfo *info);
jiff procps_stat_get_cpu (struct procps_statinfo *info, enum procps_cpu_item item);
unsigned int procps_stat_get_sys (struct procps_statinfo *info, enum procps_stat_item item);
__END_DECLS
#endif

View File

@ -98,14 +98,14 @@ extern long Hertz;
static void get_boot_time(void)
{
struct procps_stat_info *sys_info;
struct procps_statinfo *sys_info;
if (procps_stat_new(&sys_info) < 0)
xerrx(EXIT_FAILURE,
_("Unable to create system stat structure"));
if (procps_stat_read(sys_info,0) < 0)
xerrx(EXIT_FAILURE,
_("Unable to read system stat information"));
boot_time = procps_stat_get(sys_info, PROCPS_STAT_BTIME);
boot_time = procps_stat_get_sys(sys_info, PROCPS_STAT_BTIME);
procps_stat_unref(sys_info);
}

View File

@ -298,7 +298,7 @@ static void new_format(void)
time_t the_time;
char timebuf[32];
struct procps_vmstat *vm_info;
struct procps_stat_info *sys_info;
struct procps_statinfo *sys_info;
struct procps_meminfo *mem_info;
sleep_half = (sleep_time / 2);
@ -329,7 +329,7 @@ static void new_format(void)
tm_ptr = localtime( &the_time );
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr);
}
/* Do the intial fill */
/* Do the initial fill */
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);
@ -338,8 +338,8 @@ static void new_format(void)
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);
intr[tog] = procps_stat_get_sys(sys_info, PROCPS_STAT_INTR);
ctxt[tog] = procps_stat_get_sys(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);
@ -353,8 +353,8 @@ static void new_format(void)
divo2 = Div / 2UL;
printf(w_option ? wide_format : format,
procps_stat_get(sys_info, PROCPS_STAT_PROCS_RUN),
procps_stat_get(sys_info, PROCPS_STAT_PROCS_BLK),
procps_stat_get_sys(sys_info, PROCPS_STAT_PROCS_RUN),
procps_stat_get_sys(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))),
@ -400,8 +400,8 @@ static void new_format(void)
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);
intr[tog] = procps_stat_get_sys(sys_info, PROCPS_STAT_INTR);
ctxt[tog] = procps_stat_get_sys(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);
@ -437,8 +437,8 @@ static void new_format(void)
if (!Div) Div = 1, didl = 1;
divo2 = Div / 2UL;
printf(w_option ? wide_format : format,
procps_stat_get(sys_info, PROCPS_STAT_PROCS_RUN),
procps_stat_get(sys_info, PROCPS_STAT_PROCS_BLK),
procps_stat_get_sys(sys_info, PROCPS_STAT_PROCS_RUN),
procps_stat_get_sys(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,
@ -837,7 +837,7 @@ static void disksum_format(void)
static void sum_format(void)
{
struct procps_stat_info *sys_info;
struct procps_statinfo *sys_info;
struct procps_vmstat *vm_info;
struct procps_meminfo *mem_info;
@ -888,15 +888,15 @@ 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_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));
printf(_("%13u interrupts\n"), procps_stat_get_sys(sys_info, PROCPS_STAT_INTR));
printf(_("%13u CPU context switches\n"), procps_stat_get_sys(sys_info, PROCPS_STAT_CTXT));
printf(_("%13u boot time\n"), procps_stat_get_sys(sys_info, PROCPS_STAT_BTIME));
printf(_("%13u forks\n"), procps_stat_get_sys(sys_info, PROCPS_STAT_PROCS));
}
static void fork_format(void)
{
struct procps_stat_info *sys_info;
struct procps_statinfo *sys_info;
if (procps_stat_new(&sys_info) < 0)
xerrx(EXIT_FAILURE,
@ -905,7 +905,7 @@ static void fork_format(void)
xerrx(EXIT_FAILURE,
_("Unable to read system stat information"));
printf(_("%13u forks\n"), procps_stat_get(sys_info, PROCPS_STAT_PROCS));
printf(_("%13u forks\n"), procps_stat_get_sys(sys_info, PROCPS_STAT_PROCS));
}
static int winhi(void)