library: more tweaks for code and/or comments, 3rd gen
Following is a summary of significant changes (if any) to each of these now upgraded 3rd gen library modules. <meminfo> ............................................ . eliminated duplicate decl of 'struct procps_meminfo' . standardized/normalized results struct union members . added 'std' & 'var' dividers in .c file, like <pids> . how did i miss relocating all these friggin' #undefs . cleanup 'get' return logic (remove a redundant 'if') <pids> ............................................... . repositioned the procps_pidsinfo structure in header . removed the extra trailing comma from enum pids_item . standardized/normalized results struct union members <slabinfo> ........................................... . corrected comment typo (jeeze, in an 'aligned' para) . standardized/normalized results struct union members . added 'std' & 'var' dividers in .c file, like <pids> . removed an obsolete #undef from procps_slabinfo_sort . cleanup 'get' return logic (remove a redundant 'if') <stat> ............................................... . how did i miss relocating all these friggin' #undefs . corrected an initialization fencepost used with numa <=== see Craig, here's a bug fix . removed the extra trailing comma from enum stat_item . standardized/normalized results struct union members . added 'std' & 'var' dividers in .c file, like <pids> . strengthen those parm checks in procps_stat_get func . cleanup 'get' return logic (remove a redundant 'if') <vmstat> ............................................. . standardized/normalized results struct union members . added 'std' & 'var' dividers in .c file, like <pids> . cleanup 'get' return logic (remove a redundant 'if') [ virtually all of these tweaks reflect the author's ] [ continuing pursuit of an unreasonable goal -- that ] [ of a 'perfect' (plus 'pretty') C language program! ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
61647f1b95
commit
4a0e974b7f
@ -224,6 +224,10 @@ MEM_set(SWAP_FREE, ul_int, SwapFree)
|
|||||||
MEM_set(SWAP_TOTAL, ul_int, SwapTotal)
|
MEM_set(SWAP_TOTAL, ul_int, SwapTotal)
|
||||||
MEM_set(SWAP_USED, ul_int, derived_swap_used)
|
MEM_set(SWAP_USED, ul_int, derived_swap_used)
|
||||||
|
|
||||||
|
#undef setDECL
|
||||||
|
#undef MEM_set
|
||||||
|
#undef HST_set
|
||||||
|
|
||||||
|
|
||||||
// ___ Results 'Get' Support ||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Results 'Get' Support ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
@ -332,6 +336,10 @@ MEM_get(SWAP_FREE, SwapFree)
|
|||||||
MEM_get(SWAP_TOTAL, SwapTotal)
|
MEM_get(SWAP_TOTAL, SwapTotal)
|
||||||
MEM_get(SWAP_USED, derived_swap_used)
|
MEM_get(SWAP_USED, derived_swap_used)
|
||||||
|
|
||||||
|
#undef getDECL
|
||||||
|
#undef MEM_get
|
||||||
|
#undef HST_get
|
||||||
|
|
||||||
|
|
||||||
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
@ -456,16 +464,11 @@ static struct {
|
|||||||
enum meminfo_item PROCPS_MEMINFO_logical_end = PROCPS_MEMINFO_SWAP_USED + 1;
|
enum meminfo_item PROCPS_MEMINFO_logical_end = PROCPS_MEMINFO_SWAP_USED + 1;
|
||||||
|
|
||||||
#undef setNAME
|
#undef setNAME
|
||||||
#undef setDECL
|
|
||||||
#undef MEM_set
|
|
||||||
#undef HST_set
|
|
||||||
#undef getNAME
|
#undef getNAME
|
||||||
#undef getDECL
|
|
||||||
#undef MEM_get
|
|
||||||
#undef HST_get
|
|
||||||
#undef RS
|
#undef RS
|
||||||
#undef RG
|
#undef RG
|
||||||
|
|
||||||
|
|
||||||
// ___ Private Functions ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Private Functions ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
static inline void assign_results (
|
static inline void assign_results (
|
||||||
@ -816,6 +819,8 @@ static struct stacks_extent *stacks_alloc (
|
|||||||
|
|
||||||
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
|
// --- standard required functions --------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* procps_meminfo_new:
|
* procps_meminfo_new:
|
||||||
*
|
*
|
||||||
@ -882,6 +887,8 @@ PROCPS_EXPORT int procps_meminfo_unref (
|
|||||||
} // end: procps_meminfo_unref
|
} // end: procps_meminfo_unref
|
||||||
|
|
||||||
|
|
||||||
|
// --- variable interface functions -------------------------------------------
|
||||||
|
|
||||||
PROCPS_EXPORT signed long procps_meminfo_get (
|
PROCPS_EXPORT signed long procps_meminfo_get (
|
||||||
struct procps_meminfo *info,
|
struct procps_meminfo *info,
|
||||||
enum meminfo_item item)
|
enum meminfo_item item)
|
||||||
@ -904,9 +911,7 @@ PROCPS_EXPORT signed long procps_meminfo_get (
|
|||||||
sav_secs = cur_secs;
|
sav_secs = cur_secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item < PROCPS_MEMINFO_logical_end)
|
return Item_table[item].getsfunc(info);
|
||||||
return Item_table[item].getsfunc(info);
|
|
||||||
return -EINVAL;
|
|
||||||
} // end: procps_meminfo_get
|
} // end: procps_meminfo_get
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,12 +121,11 @@ enum meminfo_item {
|
|||||||
PROCPS_MEMINFO_SWAP_USED // ul_int
|
PROCPS_MEMINFO_SWAP_USED // ul_int
|
||||||
};
|
};
|
||||||
|
|
||||||
struct procps_meminfo;
|
|
||||||
|
|
||||||
struct meminfo_result {
|
struct meminfo_result {
|
||||||
enum meminfo_item item;
|
enum meminfo_item item;
|
||||||
union {
|
union {
|
||||||
signed int s_int;
|
signed int s_int;
|
||||||
unsigned long ul_int;
|
unsigned long ul_int;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
22
proc/pids.h
22
proc/pids.h
@ -144,7 +144,7 @@ enum pids_item {
|
|||||||
PROCPS_PIDS_VM_USED, // sl_int
|
PROCPS_PIDS_VM_USED, // sl_int
|
||||||
PROCPS_PIDS_VSIZE_PGS, // ul_int
|
PROCPS_PIDS_VSIZE_PGS, // ul_int
|
||||||
PROCPS_PIDS_WCHAN_ADDR, // ul_int
|
PROCPS_PIDS_WCHAN_ADDR, // ul_int
|
||||||
PROCPS_PIDS_WCHAN_NAME, // str
|
PROCPS_PIDS_WCHAN_NAME // str
|
||||||
};
|
};
|
||||||
|
|
||||||
enum pids_fetch_type {
|
enum pids_fetch_type {
|
||||||
@ -163,19 +163,17 @@ enum pids_sort_order {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct procps_pidsinfo;
|
|
||||||
|
|
||||||
struct pids_result {
|
struct pids_result {
|
||||||
enum pids_item item;
|
enum pids_item item;
|
||||||
union {
|
union {
|
||||||
char s_ch;
|
signed char s_ch;
|
||||||
int s_int;
|
signed int s_int;
|
||||||
unsigned int u_int;
|
unsigned int u_int;
|
||||||
long sl_int;
|
signed long sl_int;
|
||||||
unsigned long ul_int;
|
unsigned long ul_int;
|
||||||
unsigned long long ull_int;
|
unsigned long long ull_int;
|
||||||
char * str;
|
char *str;
|
||||||
char ** strv;
|
char **strv;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -198,6 +196,8 @@ struct pids_fetch {
|
|||||||
stack -> head [ rel_enum ] . result . type
|
stack -> head [ rel_enum ] . result . type
|
||||||
|
|
||||||
|
|
||||||
|
struct procps_pidsinfo;
|
||||||
|
|
||||||
int procps_pids_new (struct procps_pidsinfo **info, enum pids_item *items, int numitems);
|
int procps_pids_new (struct procps_pidsinfo **info, enum pids_item *items, int numitems);
|
||||||
int procps_pids_ref (struct procps_pidsinfo *info);
|
int procps_pids_ref (struct procps_pidsinfo *info);
|
||||||
int procps_pids_unref (struct procps_pidsinfo **info);
|
int procps_pids_unref (struct procps_pidsinfo **info);
|
||||||
|
@ -829,6 +829,8 @@ static int stacks_reconfig_maybe (
|
|||||||
|
|
||||||
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
|
// --- standard required functions --------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* procps_slabinfo_new():
|
* procps_slabinfo_new():
|
||||||
*
|
*
|
||||||
@ -859,7 +861,7 @@ PROCPS_EXPORT int procps_slabinfo_new (
|
|||||||
|
|
||||||
/* do a priming read here for the following potential benefits: |
|
/* do a priming read here for the following potential benefits: |
|
||||||
1) see if that caller's permissions were sufficient (root) |
|
1) see if that caller's permissions were sufficient (root) |
|
||||||
2) make delta results potentially useful, even is 1st time | */
|
2) make delta results potentially useful, even if 1st time | */
|
||||||
if ((rc = read_slabinfo_failed(p))) {
|
if ((rc = read_slabinfo_failed(p))) {
|
||||||
procps_slabinfo_unref(&p);
|
procps_slabinfo_unref(&p);
|
||||||
return rc;
|
return rc;
|
||||||
@ -919,6 +921,8 @@ PROCPS_EXPORT int procps_slabinfo_unref (
|
|||||||
} // end: procps_slabinfo_unref
|
} // end: procps_slabinfo_unref
|
||||||
|
|
||||||
|
|
||||||
|
// --- variable interface functions -------------------------------------------
|
||||||
|
|
||||||
PROCPS_EXPORT signed long procps_slabinfo_get (
|
PROCPS_EXPORT signed long procps_slabinfo_get (
|
||||||
struct procps_slabinfo *info,
|
struct procps_slabinfo *info,
|
||||||
enum slabinfo_item item)
|
enum slabinfo_item item)
|
||||||
@ -1056,5 +1060,4 @@ PROCPS_EXPORT struct slabinfo_stack **procps_slabinfo_sort (
|
|||||||
|
|
||||||
qsort_r(stacks, numstacked, sizeof(void *), (QSR_t)Item_table[p->item].sortfunc, &parms);
|
qsort_r(stacks, numstacked, sizeof(void *), (QSR_t)Item_table[p->item].sortfunc, &parms);
|
||||||
return stacks;
|
return stacks;
|
||||||
#undef QSORT_r
|
|
||||||
} // end: procps_slabinfo_sort
|
} // end: procps_slabinfo_sort
|
||||||
|
@ -78,10 +78,10 @@ enum slabinfo_sort_order {
|
|||||||
struct slabinfo_result {
|
struct slabinfo_result {
|
||||||
enum slabinfo_item item;
|
enum slabinfo_item item;
|
||||||
union {
|
union {
|
||||||
signed int s_int;
|
signed int s_int;
|
||||||
unsigned int u_int;
|
unsigned int u_int;
|
||||||
unsigned long ul_int;
|
unsigned long ul_int;
|
||||||
char * str;
|
char *str;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
38
proc/stat.c
38
proc/stat.c
@ -185,6 +185,12 @@ setDECL(SYS_DELTA_PROC_BLOCKED) { (void)T; R->result.s_int = S->new.procs_blocke
|
|||||||
SYSsetH(SYS_DELTA_PROC_CREATED, s_int, procs_created)
|
SYSsetH(SYS_DELTA_PROC_CREATED, s_int, procs_created)
|
||||||
setDECL(SYS_DELTA_PROC_RUNNING) { (void)T; R->result.s_int = S->new.procs_running - S->old.procs_running; }
|
setDECL(SYS_DELTA_PROC_RUNNING) { (void)T; R->result.s_int = S->new.procs_running - S->old.procs_running; }
|
||||||
|
|
||||||
|
#undef setDECL
|
||||||
|
#undef TIC_set
|
||||||
|
#undef SYS_set
|
||||||
|
#undef TICsetH
|
||||||
|
#undef SYSsetH
|
||||||
|
|
||||||
|
|
||||||
// ___ Results 'Get' Support ||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Results 'Get' Support ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
@ -244,6 +250,12 @@ getDECL(SYS_DELTA_PROC_BLOCKED) { return I->sys_hist.new.procs_blocked - I->sys_
|
|||||||
SYSgetH(SYS_DELTA_PROC_CREATED, procs_created)
|
SYSgetH(SYS_DELTA_PROC_CREATED, procs_created)
|
||||||
getDECL(SYS_DELTA_PROC_RUNNING) { return I->sys_hist.new.procs_running - I->sys_hist.old.procs_running; }
|
getDECL(SYS_DELTA_PROC_RUNNING) { return I->sys_hist.new.procs_running - I->sys_hist.old.procs_running; }
|
||||||
|
|
||||||
|
#undef getDECL
|
||||||
|
#undef TIC_get
|
||||||
|
#undef SYS_get
|
||||||
|
#undef TICgetH
|
||||||
|
#undef SYSgetH
|
||||||
|
|
||||||
|
|
||||||
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
@ -314,17 +326,7 @@ enum stat_item PROCPS_STAT_TIC_highest = PROCPS_STAT_TIC_DELTA_GUEST_NICE;
|
|||||||
enum stat_item PROCPS_STAT_logical_end = PROCPS_STAT_SYS_DELTA_PROC_RUNNING + 1;
|
enum stat_item PROCPS_STAT_logical_end = PROCPS_STAT_SYS_DELTA_PROC_RUNNING + 1;
|
||||||
|
|
||||||
#undef setNAME
|
#undef setNAME
|
||||||
#undef setDECL
|
|
||||||
#undef TIC_set
|
|
||||||
#undef SYS_set
|
|
||||||
#undef TICsetH
|
|
||||||
#undef SYSsetH
|
|
||||||
#undef getNAME
|
#undef getNAME
|
||||||
#undef getDECL
|
|
||||||
#undef TIC_get
|
|
||||||
#undef SYS_get
|
|
||||||
#undef TICgetH
|
|
||||||
#undef SYSgetH
|
|
||||||
#undef RS
|
#undef RS
|
||||||
#undef RG
|
#undef RG
|
||||||
|
|
||||||
@ -458,6 +460,7 @@ static int make_numa_hist (
|
|||||||
( and be careful, this libnuma call returns the highest node id in use, )
|
( and be careful, this libnuma call returns the highest node id in use, )
|
||||||
( NOT an actual number of nodes - some of those 'slots' might be unused ) */
|
( NOT an actual number of nodes - some of those 'slots' might be unused ) */
|
||||||
info->nodes.total = info->our_max_node() + 1;
|
info->nodes.total = info->our_max_node() + 1;
|
||||||
|
|
||||||
if (!info->nodes.hist.n_alloc
|
if (!info->nodes.hist.n_alloc
|
||||||
|| !(info->nodes.total < info->nodes.hist.n_alloc)) {
|
|| !(info->nodes.total < info->nodes.hist.n_alloc)) {
|
||||||
info->nodes.hist.n_alloc = info->nodes.total + NEWOLD_INCR;
|
info->nodes.hist.n_alloc = info->nodes.total + NEWOLD_INCR;
|
||||||
@ -469,7 +472,7 @@ static int make_numa_hist (
|
|||||||
// forget all of the prior node statistics & anticipate unassigned slots
|
// forget all of the prior node statistics & anticipate unassigned slots
|
||||||
memset(info->nodes.hist.tics, 0, info->nodes.hist.n_alloc * sizeof(struct hist_tic));
|
memset(info->nodes.hist.tics, 0, info->nodes.hist.n_alloc * sizeof(struct hist_tic));
|
||||||
nod_ptr = info->nodes.hist.tics;
|
nod_ptr = info->nodes.hist.tics;
|
||||||
for (i = 0; i < info->cpus.hist.n_alloc; i++) {
|
for (i = 0; i < info->nodes.total; i++) {
|
||||||
nod_ptr->id = nod_ptr->numa_node = PROCPS_STAT_NODE_INVALID;
|
nod_ptr->id = nod_ptr->numa_node = PROCPS_STAT_NODE_INVALID;
|
||||||
++nod_ptr;
|
++nod_ptr;
|
||||||
}
|
}
|
||||||
@ -808,6 +811,8 @@ static struct stat_stack *update_single_stack (
|
|||||||
|
|
||||||
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
|
// --- standard required functions --------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* procps_stat_new:
|
* procps_stat_new:
|
||||||
*
|
*
|
||||||
@ -922,6 +927,8 @@ PROCPS_EXPORT int procps_stat_unref (
|
|||||||
} // end: procps_stat_unref
|
} // end: procps_stat_unref
|
||||||
|
|
||||||
|
|
||||||
|
// --- variable interface functions -------------------------------------------
|
||||||
|
|
||||||
PROCPS_EXPORT signed long long procps_stat_get (
|
PROCPS_EXPORT signed long long procps_stat_get (
|
||||||
struct procps_statinfo *info,
|
struct procps_statinfo *info,
|
||||||
enum stat_item item)
|
enum stat_item item)
|
||||||
@ -930,6 +937,11 @@ PROCPS_EXPORT signed long long procps_stat_get (
|
|||||||
time_t cur_secs;
|
time_t cur_secs;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
if (info == NULL)
|
||||||
|
return -EINVAL;
|
||||||
|
if (item < 0 || item >= PROCPS_STAT_logical_end)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
/* no sense reading the stat with every call from a program like vmstat
|
/* no sense reading the stat with every call from a program like vmstat
|
||||||
who chooses not to use the much more efficient 'select' function ... */
|
who chooses not to use the much more efficient 'select' function ... */
|
||||||
cur_secs = time(NULL);
|
cur_secs = time(NULL);
|
||||||
@ -939,9 +951,7 @@ PROCPS_EXPORT signed long long procps_stat_get (
|
|||||||
sav_secs = cur_secs;
|
sav_secs = cur_secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item < PROCPS_STAT_logical_end)
|
return Item_table[item].getsfunc(info);
|
||||||
return Item_table[item].getsfunc(info);
|
|
||||||
return -EINVAL;
|
|
||||||
} // end: procps_stat_get
|
} // end: procps_stat_get
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ enum stat_item {
|
|||||||
PROCPS_STAT_SYS_DELTA_INTERRUPTS, // s_int
|
PROCPS_STAT_SYS_DELTA_INTERRUPTS, // s_int
|
||||||
PROCPS_STAT_SYS_DELTA_PROC_BLOCKED, // s_int
|
PROCPS_STAT_SYS_DELTA_PROC_BLOCKED, // s_int
|
||||||
PROCPS_STAT_SYS_DELTA_PROC_CREATED, // s_int
|
PROCPS_STAT_SYS_DELTA_PROC_CREATED, // s_int
|
||||||
PROCPS_STAT_SYS_DELTA_PROC_RUNNING, // s_int
|
PROCPS_STAT_SYS_DELTA_PROC_RUNNING // s_int
|
||||||
};
|
};
|
||||||
|
|
||||||
enum stat_reap_type {
|
enum stat_reap_type {
|
||||||
@ -71,9 +71,9 @@ enum stat_reap_type {
|
|||||||
struct stat_result {
|
struct stat_result {
|
||||||
enum stat_item item;
|
enum stat_item item;
|
||||||
union {
|
union {
|
||||||
signed int s_int;
|
signed int s_int;
|
||||||
signed long sl_int;
|
signed long sl_int;
|
||||||
unsigned long ul_int;
|
unsigned long ul_int;
|
||||||
unsigned long long ull_int;
|
unsigned long long ull_int;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
@ -1358,6 +1358,8 @@ static struct stacks_extent *stacks_alloc (
|
|||||||
|
|
||||||
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
|
// --- standard required functions --------------------------------------------
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* procps_vmstat_new:
|
* procps_vmstat_new:
|
||||||
*
|
*
|
||||||
@ -1424,6 +1426,8 @@ PROCPS_EXPORT int procps_vmstat_unref (
|
|||||||
} // end: procps_vmstat_unref
|
} // end: procps_vmstat_unref
|
||||||
|
|
||||||
|
|
||||||
|
// --- variable interface functions -------------------------------------------
|
||||||
|
|
||||||
PROCPS_EXPORT signed long procps_vmstat_get (
|
PROCPS_EXPORT signed long procps_vmstat_get (
|
||||||
struct procps_vmstat *info,
|
struct procps_vmstat *info,
|
||||||
enum vmstat_item item)
|
enum vmstat_item item)
|
||||||
@ -1446,9 +1450,7 @@ PROCPS_EXPORT signed long procps_vmstat_get (
|
|||||||
sav_secs = cur_secs;
|
sav_secs = cur_secs;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item < PROCPS_VMSTAT_logical_end)
|
return Item_table[item].getsfunc(info);
|
||||||
return Item_table[item].getsfunc(info);
|
|
||||||
return -EINVAL;
|
|
||||||
} // end: procps_vmstat_get
|
} // end: procps_vmstat_get
|
||||||
|
|
||||||
|
|
||||||
|
@ -275,8 +275,8 @@ enum vmstat_item {
|
|||||||
struct vmstat_result {
|
struct vmstat_result {
|
||||||
enum vmstat_item item;
|
enum vmstat_item item;
|
||||||
union {
|
union {
|
||||||
signed long sl_int;
|
signed long sl_int;
|
||||||
unsigned long ul_int;
|
unsigned long ul_int;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user