library: add chaining provisions to readstat cpu & sys

If a caller chooses to reduce the overhead of repeated
function calls, this commit provides for acquiring all
the desired information in just a single library call.

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 6bb1a033b4
commit 0c162f7af0
3 changed files with 101 additions and 0 deletions

View File

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

View File

@ -193,6 +193,54 @@ PROCPS_EXPORT jiff procps_stat_get_cpu (
return 0; return 0;
} }
PROCPS_EXPORT int procps_get_cpu_chain (
struct procps_statinfo *info,
struct procps_cpu_result *item)
{
if (item == NULL)
return -EINVAL;
do {
switch (item->item) {
case PROCPS_CPU_USER:
item->result = info->data.cpu_user;
break;
case PROCPS_CPU_NICE:
item->result = info->data.cpu_nice;
break;
case PROCPS_CPU_SYSTEM:
item->result = info->data.cpu_sys;
break;
case PROCPS_CPU_IDLE:
item->result = info->data.cpu_idle;
break;
case PROCPS_CPU_IOWAIT:
item->result = info->data.cpu_iowait;
break;
case PROCPS_CPU_IRQ:
item->result = info->data.cpu_irq;
break;
case PROCPS_CPU_SIRQ:
item->result = info->data.cpu_sirq;
break;
case PROCPS_CPU_STOLEN:
item->result = info->data.cpu_stol;
break;
case PROCPS_CPU_GUEST:
item->result = info->data.cpu_guest;
break;
case PROCPS_CPU_GNICE:
item->result = info->data.cpu_gnice;
break;
default:
return -EINVAL;
}
item = item->next;
} while (item);
return 0;
}
PROCPS_EXPORT unsigned int procps_stat_get_sys ( PROCPS_EXPORT unsigned int procps_stat_get_sys (
struct procps_statinfo *info, struct procps_statinfo *info,
enum procps_stat_item item) enum procps_stat_item item)
@ -213,3 +261,39 @@ PROCPS_EXPORT unsigned int procps_stat_get_sys (
} }
return 0; return 0;
} }
PROCPS_EXPORT int procps_stat_get_sys_chain (
struct procps_statinfo *info,
struct procps_sys_result *item)
{
if (item == NULL)
return -EINVAL;
do {
switch (item->item) {
case PROCPS_STAT_INTR:
item->result = info->data.intr;
break;
case PROCPS_STAT_CTXT:
item->result = info->data.ctxt;
break;
case PROCPS_STAT_BTIME:
item->result = info->data.btime;
break;
case PROCPS_STAT_PROCS:
item->result = info->data.procs;
break;
case PROCPS_STAT_PROCS_BLK:
item->result = info->data.procs_blocked;
break;
case PROCPS_STAT_PROCS_RUN:
item->result = info->data.procs_running;
break;
default:
return -EINVAL;
}
item = item->next;
} while (item);
return 0;
}

View File

@ -46,6 +46,18 @@ enum procps_stat_item {
typedef unsigned long long jiff; typedef unsigned long long jiff;
struct procps_cpu_result {
enum procps_cpu_item item;
jiff result;
struct procps_cpu_result *next;
};
struct procps_sys_result {
enum procps_stat_item item;
int result;
struct procps_sys_result *next;
};
struct procps_statinfo; struct procps_statinfo;
int procps_stat_new (struct procps_statinfo **info); int procps_stat_new (struct procps_statinfo **info);
@ -55,7 +67,10 @@ struct procps_statinfo *procps_stat_ref (struct procps_statinfo *info);
struct procps_statinfo *procps_stat_unref (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); jiff procps_stat_get_cpu (struct procps_statinfo *info, enum procps_cpu_item item);
int procps_stat_get_cpu_chain (struct procps_statinfo *info, struct procps_cpu_result *item);
unsigned int procps_stat_get_sys (struct procps_statinfo *info, enum procps_stat_item item); unsigned int procps_stat_get_sys (struct procps_statinfo *info, enum procps_stat_item item);
int procps_stat_get_sys_chain (struct procps_statinfo *info, struct procps_sys_result *item);
__END_DECLS __END_DECLS
#endif #endif