library; add more of my gratuitous changes, <STAT> api
This commit is just my usual tweaking after an initial submission, once the dust has settled & some more desk checking was performed. Here are the changes included: . get function need not check the 'stat_was_read' flag ( first time in save_sec == 0 so branch always taken ) . some table logic appeared outside the proper section . cleanup_stack's loop made to work like assign_result . eliminated an include of procps.h from stat.h header . removed 'ext_numitems' from the stacks_extent struct . changed the alignment of three prototypes for stat.h . reorganized the pointers for 'stacks_extents' struct . improved types indentation in header for readability . lastly, some really gratuitous changes made to align - comments within that private 'stacks_alloc' function Signed-off-by: Jim Warner <james.warner@comcast.net
This commit is contained in:
parent
21360027e5
commit
1417ba56b5
63
proc/stat.c
63
proc/stat.c
@ -71,10 +71,9 @@ struct hist_tic {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct stacks_extent {
|
struct stacks_extent {
|
||||||
struct stat_stack **stacks;
|
|
||||||
int ext_numitems; // includes 'logical_end' delimiter
|
|
||||||
int ext_numstacks;
|
int ext_numstacks;
|
||||||
struct stacks_extent *next;
|
struct stacks_extent *next;
|
||||||
|
struct stat_stack **stacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fetch_support {
|
struct fetch_support {
|
||||||
@ -176,12 +175,11 @@ SYS_hst(SYS_DELTA_PROC_CREATED, s_int, procs_created)
|
|||||||
SYS_hst(SYS_DELTA_PROC_RUNNING, s_int, procs_running)
|
SYS_hst(SYS_DELTA_PROC_RUNNING, s_int, procs_running)
|
||||||
|
|
||||||
|
|
||||||
|
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
typedef void (*SET_t)(struct stat_result *, struct hist_sys *, struct hist_tic *);
|
typedef void (*SET_t)(struct stat_result *, struct hist_sys *, struct hist_tic *);
|
||||||
#define RS(e) (SET_t)setNAME(e)
|
#define RS(e) (SET_t)setNAME(e)
|
||||||
|
|
||||||
|
|
||||||
// ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Need it be said?
|
* Need it be said?
|
||||||
* This table must be kept in the exact same order as
|
* This table must be kept in the exact same order as
|
||||||
@ -190,7 +188,6 @@ static struct {
|
|||||||
SET_t setsfunc; // the actual result setting routine
|
SET_t setsfunc; // the actual result setting routine
|
||||||
} Item_table[] = {
|
} Item_table[] = {
|
||||||
/* setsfunc
|
/* setsfunc
|
||||||
|
|
||||||
--------------------------- */
|
--------------------------- */
|
||||||
{ RS(noop), },
|
{ RS(noop), },
|
||||||
{ RS(extra), },
|
{ RS(extra), },
|
||||||
@ -269,17 +266,14 @@ static inline void assign_results (
|
|||||||
|
|
||||||
|
|
||||||
static inline void cleanup_stack (
|
static inline void cleanup_stack (
|
||||||
struct stat_result *p,
|
struct stat_result *this)
|
||||||
int depth)
|
|
||||||
{
|
{
|
||||||
int i;
|
for (;;) {
|
||||||
|
if (this->item >= PROCPS_STAT_logical_end)
|
||||||
for (i = 0; i < depth; i++) {
|
|
||||||
if (p->item >= PROCPS_STAT_logical_end)
|
|
||||||
break;
|
break;
|
||||||
if (p->item > PROCPS_STAT_noop)
|
if (this->item > PROCPS_STAT_noop)
|
||||||
p->result.ull_int = 0;
|
this->result.ull_int = 0;
|
||||||
++p;
|
++this;
|
||||||
}
|
}
|
||||||
} // end: cleanup_stack
|
} // end: cleanup_stack
|
||||||
|
|
||||||
@ -292,7 +286,7 @@ static inline void cleanup_stacks_all (
|
|||||||
|
|
||||||
while (ext) {
|
while (ext) {
|
||||||
for (i = 0; ext->stacks[i]; i++)
|
for (i = 0; ext->stacks[i]; i++)
|
||||||
cleanup_stack(ext->stacks[i]->head, this->numitems);
|
cleanup_stack(ext->stacks[i]->head);
|
||||||
ext = ext->next;
|
ext = ext->next;
|
||||||
};
|
};
|
||||||
this->dirty_stacks = 0;
|
this->dirty_stacks = 0;
|
||||||
@ -587,27 +581,27 @@ static struct stacks_extent *stacks_alloc (
|
|||||||
if (maxstacks < 1)
|
if (maxstacks < 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
vect_size = sizeof(void *) * maxstacks; // address vectors themselves
|
vect_size = sizeof(void *) * maxstacks; // size of the addr vectors |
|
||||||
vect_size += sizeof(void *); // plus NULL delimiter
|
vect_size += sizeof(void *); // plus NULL addr delimiter |
|
||||||
head_size = sizeof(struct stat_stack); // a head struct
|
head_size = sizeof(struct stat_stack); // size of that head struct |
|
||||||
list_size = sizeof(struct stat_result) * this->numitems; // a results stack
|
list_size = sizeof(struct stat_result) * this->numitems; // any single results stack |
|
||||||
blob_size = sizeof(struct stacks_extent); // the extent anchor itself
|
blob_size = sizeof(struct stacks_extent); // the extent anchor itself |
|
||||||
blob_size += vect_size; // all vectors + delim
|
blob_size += vect_size; // plus room for addr vects |
|
||||||
blob_size += head_size * maxstacks; // all head structs
|
blob_size += head_size * maxstacks; // plus room for head thing |
|
||||||
blob_size += list_size * maxstacks; // all results stacks
|
blob_size += list_size * maxstacks; // plus room for our stacks |
|
||||||
|
|
||||||
/* note: all memory is allocated in a single blob, facilitating a later free().
|
/* note: all of our memory is allocated in a single blob, facilitating a later free(). |
|
||||||
as a minimum, it's important that the result structures themselves always be
|
as a minimum, it is important that the result structures themselves always be |
|
||||||
contiguous for each stack since they're accessed through relative position). */
|
contiguous for every stack since they are accessed through relative position. | */
|
||||||
if (NULL == (p_blob = calloc(1, blob_size)))
|
if (NULL == (p_blob = calloc(1, blob_size)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
p_blob->next = this->extents;
|
p_blob->next = this->extents; // push this extent onto... |
|
||||||
this->extents = p_blob;
|
this->extents = p_blob; // ...some existing extents |
|
||||||
p_blob->stacks = (void *)p_blob + sizeof(struct stacks_extent);
|
p_vect = (void *)p_blob + sizeof(struct stacks_extent); // prime our vector pointer |
|
||||||
p_vect = p_blob->stacks;
|
p_blob->stacks = p_vect; // set actual vectors start |
|
||||||
v_head = (void *)p_vect + vect_size;
|
v_head = (void *)p_vect + vect_size; // prime head pointer start |
|
||||||
v_list = v_head + (head_size * maxstacks);
|
v_list = v_head + (head_size * maxstacks); // prime our stacks pointer |
|
||||||
|
|
||||||
for (i = 0; i < maxstacks; i++) {
|
for (i = 0; i < maxstacks; i++) {
|
||||||
p_head = (struct stat_stack *)v_head;
|
p_head = (struct stat_stack *)v_head;
|
||||||
@ -616,7 +610,6 @@ static struct stacks_extent *stacks_alloc (
|
|||||||
v_list += list_size;
|
v_list += list_size;
|
||||||
v_head += head_size;
|
v_head += head_size;
|
||||||
}
|
}
|
||||||
p_blob->ext_numitems = this->numitems;
|
|
||||||
p_blob->ext_numstacks = maxstacks;
|
p_blob->ext_numstacks = maxstacks;
|
||||||
return p_blob;
|
return p_blob;
|
||||||
} // end: stacks_alloc
|
} // end: stacks_alloc
|
||||||
@ -849,7 +842,7 @@ PROCPS_EXPORT signed long long procps_stat_get (
|
|||||||
/* 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);
|
||||||
if (!info->stat_was_read || 1 <= cur_secs - sav_secs) {
|
if (1 <= cur_secs - sav_secs) {
|
||||||
if ((rc = read_stat_failed(info)))
|
if ((rc = read_stat_failed(info)))
|
||||||
return rc;
|
return rc;
|
||||||
sav_secs = cur_secs;
|
sav_secs = cur_secs;
|
||||||
|
61
proc/stat.h
61
proc/stat.h
@ -15,19 +15,18 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PROC_STAT_H
|
#ifndef PROC_STAT_H
|
||||||
#define PROC_STAT_H
|
#define PROC_STAT_H
|
||||||
|
|
||||||
#include <proc/procps.h>
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
enum stat_item {
|
enum stat_item {
|
||||||
PROCPS_STAT_noop, // ( never altered )
|
PROCPS_STAT_noop, // ( never altered )
|
||||||
PROCPS_STAT_extra, // ( reset to zero )
|
PROCPS_STAT_extra, // ( reset to zero )
|
||||||
|
|
||||||
PROCPS_STAT_TIC_ID, // s_int
|
PROCPS_STAT_TIC_ID, // s_int
|
||||||
PROCPS_STAT_TIC_NUMA_NODE, // s_int
|
PROCPS_STAT_TIC_NUMA_NODE, // s_int
|
||||||
PROCPS_STAT_TIC_USER, // ull_int
|
PROCPS_STAT_TIC_USER, // ull_int
|
||||||
PROCPS_STAT_TIC_NICE, // ull_int
|
PROCPS_STAT_TIC_NICE, // ull_int
|
||||||
PROCPS_STAT_TIC_SYSTEM, // ull_int
|
PROCPS_STAT_TIC_SYSTEM, // ull_int
|
||||||
@ -38,28 +37,28 @@ enum stat_item {
|
|||||||
PROCPS_STAT_TIC_STOLEN, // ull_int
|
PROCPS_STAT_TIC_STOLEN, // ull_int
|
||||||
PROCPS_STAT_TIC_GUEST, // ull_int
|
PROCPS_STAT_TIC_GUEST, // ull_int
|
||||||
PROCPS_STAT_TIC_GUEST_NICE, // ull_int
|
PROCPS_STAT_TIC_GUEST_NICE, // ull_int
|
||||||
PROCPS_STAT_TIC_DELTA_USER, // sl_int
|
PROCPS_STAT_TIC_DELTA_USER, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_NICE, // sl_int
|
PROCPS_STAT_TIC_DELTA_NICE, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_SYSTEM, // sl_int
|
PROCPS_STAT_TIC_DELTA_SYSTEM, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_IDLE, // sl_int
|
PROCPS_STAT_TIC_DELTA_IDLE, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_IOWAIT, // sl_int
|
PROCPS_STAT_TIC_DELTA_IOWAIT, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_IRQ, // sl_int
|
PROCPS_STAT_TIC_DELTA_IRQ, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_SOFTIRQ, // sl_int
|
PROCPS_STAT_TIC_DELTA_SOFTIRQ, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_STOLEN, // sl_int
|
PROCPS_STAT_TIC_DELTA_STOLEN, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_GUEST, // sl_int
|
PROCPS_STAT_TIC_DELTA_GUEST, // sl_int
|
||||||
PROCPS_STAT_TIC_DELTA_GUEST_NICE, // sl_int
|
PROCPS_STAT_TIC_DELTA_GUEST_NICE, // sl_int
|
||||||
|
|
||||||
PROCPS_STAT_SYS_CTX_SWITCHES, // ul_int
|
PROCPS_STAT_SYS_CTX_SWITCHES, // ul_int
|
||||||
PROCPS_STAT_SYS_INTERRUPTS, // ul_int
|
PROCPS_STAT_SYS_INTERRUPTS, // ul_int
|
||||||
PROCPS_STAT_SYS_PROC_BLOCKED, // ul_int
|
PROCPS_STAT_SYS_PROC_BLOCKED, // ul_int
|
||||||
PROCPS_STAT_SYS_PROC_CREATED, // ul_int
|
PROCPS_STAT_SYS_PROC_CREATED, // ul_int
|
||||||
PROCPS_STAT_SYS_PROC_RUNNING, // ul_int
|
PROCPS_STAT_SYS_PROC_RUNNING, // ul_int
|
||||||
PROCPS_STAT_SYS_TIME_OF_BOOT, // ul_int
|
PROCPS_STAT_SYS_TIME_OF_BOOT, // ul_int
|
||||||
PROCPS_STAT_SYS_DELTA_CTX_SWITCHES, // s_int
|
PROCPS_STAT_SYS_DELTA_CTX_SWITCHES, // s_int
|
||||||
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 {
|
||||||
@ -70,10 +69,10 @@ enum stat_reap_type {
|
|||||||
struct stat_result {
|
struct stat_result {
|
||||||
enum stat_item item;
|
enum stat_item item;
|
||||||
union {
|
union {
|
||||||
int s_int;
|
signed int s_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;
|
||||||
} result;
|
} result;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,8 +101,8 @@ struct stat_reaped {
|
|||||||
|
|
||||||
struct procps_statinfo;
|
struct procps_statinfo;
|
||||||
|
|
||||||
int procps_stat_new (struct procps_statinfo **info);
|
int procps_stat_new (struct procps_statinfo **info);
|
||||||
int procps_stat_ref (struct procps_statinfo *info);
|
int procps_stat_ref (struct procps_statinfo *info);
|
||||||
int procps_stat_unref (struct procps_statinfo **info);
|
int procps_stat_unref (struct procps_statinfo **info);
|
||||||
|
|
||||||
signed long long procps_stat_get (
|
signed long long procps_stat_get (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user