]> granicus.if.org Git - procps-ng/commitdiff
library: add chaining provisions to readstat cpu & sys
authorJim Warner <james.warner@comcast.net>
Sun, 28 Jun 2015 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Mon, 29 Jun 2015 11:30:04 +0000 (21:30 +1000)
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>
proc/libprocps.sym
proc/readstat.c
proc/readstat.h

index fd7d0cb6c012d44b294234a8ff1e648f2da6ff22..e1866935685f70a50eb13d4f576e06bd76507166 100644 (file)
@@ -73,7 +73,9 @@ global:
        procps_stat_ref;
        procps_stat_unref;
        procps_stat_get_cpu;
+       procps_stat_get_cpu_chain;
        procps_stat_get_sys;
+       procps_stat_get_sys_chain;
        procps_vmstat_new;
        procps_vmstat_read;
        procps_vmstat_ref;
index bf8501b98bd4b0c92c09e438fcc96396f0290930..c8873e77096a5a57cbd31846daf0244fa7a95a1f 100644 (file)
@@ -193,6 +193,54 @@ PROCPS_EXPORT jiff procps_stat_get_cpu (
     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 (
         struct procps_statinfo *info,
         enum procps_stat_item item)
@@ -213,3 +261,39 @@ PROCPS_EXPORT unsigned int procps_stat_get_sys (
     }
     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;
+}
index 53103d73554328b9e0188cb048b3e289225b79bb..77cffc98220bc05fa7be9b2b4d141680557efa0a 100644 (file)
@@ -46,6 +46,18 @@ enum procps_stat_item {
 
 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;
 
 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);
 
 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);
+int procps_stat_get_sys_chain (struct procps_statinfo *info, struct procps_sys_result *item);
 
 __END_DECLS
 #endif