]> granicus.if.org Git - procps-ng/commitdiff
library: add chaining provisions to meminfo and vmstat
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:29:29 +0000 (21:29 +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/meminfo.c
proc/meminfo.h
proc/vmstat.c
proc/vmstat.h

index 6245ee1de09de1f3a5c614db0967ec8a4550423d..6b3bcc1069e35ab9400989f7d98abe8b017cabe9 100644 (file)
@@ -67,6 +67,7 @@ global:
        procps_meminfo_ref;
        procps_meminfo_unref;
        procps_meminfo_get;
+       procps_meminfo_get_chain;
        procps_stat_new;
        procps_stat_read;
        procps_stat_ref;
@@ -78,6 +79,7 @@ global:
        procps_vmstat_ref;
        procps_vmstat_unref;
        procps_vmstat_get;
+       procps_vmstat_get_chain;
 local:
        *;
 };
index ad332c598e752dab30ad5f0c77873f09b024d70e..7ab1cc9e8d9d0c4d90c060828d4a5dd853f5a16a 100644 (file)
@@ -279,3 +279,85 @@ PROCPS_EXPORT unsigned long procps_meminfo_get (
     }
     return 0;
 }
+
+PROCPS_EXPORT int procps_meminfo_get_chain (
+        struct procps_meminfo *info,
+        struct meminfo_result *item)
+{
+
+    if (item == NULL)
+        return -EINVAL;
+
+    do {
+        switch (item->item) {
+            case PROCPS_MEM_ACTIVE:
+                item->result = info->data.active;
+                break;
+            case PROCPS_MEM_INACTIVE:
+                item->result = info->data.inactive;
+                break;
+            case PROCPS_MEMHI_FREE:
+                item->result = info->data.high_free;
+                break;
+            case PROCPS_MEMHI_TOTAL:
+                item->result = info->data.high_total;
+                break;
+            case PROCPS_MEMHI_USED:
+                if (info->data.high_free > info->data.high_total)
+                    item->result = 0;
+                else
+                    item->result = info->data.high_total - info->data.high_free;
+                break;
+            case PROCPS_MEMLO_FREE:
+                item->result = info->data.low_free;
+                break;
+            case PROCPS_MEMLO_TOTAL:
+                item->result = info->data.low_total;
+                break;
+            case PROCPS_MEMLO_USED:
+                if (info->data.low_free > info->data.low_total)
+                    item->result = 0;
+                else
+                    item->result = info->data.low_total - info->data.low_free;
+                break;
+            case PROCPS_MEM_AVAILABLE:
+                item->result = info->data.available;
+                break;
+            case PROCPS_MEM_BUFFERS:
+                item->result = info->data.buffers;
+                break;
+            case PROCPS_MEM_CACHED:
+                item->result = info->data.cached;
+                break;
+            case PROCPS_MEM_FREE:
+                item->result = info->data.free;
+                break;
+            case PROCPS_MEM_SHARED:
+                item->result = info->data.shared;
+                break;
+            case PROCPS_MEM_TOTAL:
+                item->result = info->data.total;
+                break;
+            case PROCPS_MEM_USED:
+                item->result = info->data.used;
+                break;
+            case PROCPS_SWAP_FREE:
+                item->result = info->data.swap_free;
+                break;
+            case PROCPS_SWAP_TOTAL:
+                item->result = info->data.swap_total;
+                break;
+            case PROCPS_SWAP_USED:
+                if (info->data.swap_free > info->data.swap_total)
+                    item->result = 0;
+                else
+                    item->result = info->data.swap_total - info->data.swap_free;
+                break;
+            default:
+                return -EINVAL;
+        }
+        item = item->next;
+    } while (item);
+
+    return 0;
+}
index aaa5dece47ad15a23b8fb16954cca98a47e4e318..31b46d45eb48091c225b8681069003e2eff0819e 100644 (file)
@@ -47,6 +47,12 @@ enum meminfo_item {
     PROCPS_SWAP_USED
 };
 
+struct meminfo_result {
+    enum meminfo_item item;
+    unsigned long result;
+    struct meminfo_result *next;
+};
+
 struct procps_meminfo;
 
 int procps_meminfo_new (struct procps_meminfo **info);
@@ -56,6 +62,7 @@ struct procps_meminfo *procps_meminfo_ref (struct procps_meminfo *info);
 struct procps_meminfo *procps_meminfo_unref (struct procps_meminfo *info);
 
 unsigned long procps_meminfo_get (struct procps_meminfo *info, enum meminfo_item item);
+int procps_meminfo_get_chain (struct procps_meminfo *info, struct meminfo_result *item);
 
 __END_DECLS
 #endif
index 9bb9db2153b5f08b87daed785f1e97e52eb744c7..8f9f1f6f376295e66b6b314a4ad7cbf1068e489d 100644 (file)
@@ -157,3 +157,32 @@ PROCPS_EXPORT unsigned long procps_vmstat_get (
     return 0;
 }
 
+PROCPS_EXPORT int procps_vmstat_get_chain (
+        struct procps_vmstat *info,
+        struct vmstat_result *item)
+{
+    if (item == NULL)
+        return -EINVAL;
+
+    do {
+        switch (item->item) {
+            case PROCPS_VMSTAT_PGPGIN:
+                item->result = info->data.pgpgin;
+                break;
+            case PROCPS_VMSTAT_PGPGOUT:
+                item->result = info->data.pgpgout;
+                break;
+            case PROCPS_VMSTAT_PSWPIN:
+                item->result = info->data.pswpin;
+                break;
+            case PROCPS_VMSTAT_PSWPOUT:
+                item->result = info->data.pswpout;
+                break;
+            default:
+                return -EINVAL;
+        }
+        item = item->next;
+    } while (item);
+
+    return 0;
+}
index 7c55dcf73b19f9deebe20c70a38525dc70efb1de..7c22bd7154a429ccfa8563fbb126c8b18d390c92 100644 (file)
@@ -34,6 +34,12 @@ enum vmstat_item {
     PROCPS_VMSTAT_PSWPOUT
 };
 
+struct vmstat_result {
+    enum vmstat_item item;
+    unsigned long result;
+    struct vmstat_result *next;
+};
+
 struct procps_vmstat;
 
 int procps_vmstat_new (struct procps_vmstat **info);
@@ -43,6 +49,7 @@ struct procps_vmstat *procps_vmstat_ref (struct procps_vmstat *info);
 struct procps_vmstat *procps_vmstat_unref (struct procps_vmstat *info);
 
 unsigned long procps_vmstat_get (struct procps_vmstat *info, enum vmstat_item item);
+int procps_vmstat_get_chain (struct procps_vmstat *info, struct vmstat_result *item);
 
 __END_DECLS
 #endif