]> granicus.if.org Git - procps-ng/commitdiff
library: more tweaks for code and/or comments, 3rd gen
authorJim Warner <james.warner@comcast.net>
Tue, 14 Jun 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Fri, 17 Jun 2016 11:44:29 +0000 (21:44 +1000)
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>
proc/meminfo.c
proc/meminfo.h
proc/pids.h
proc/slabinfo.c
proc/slabinfo.h
proc/stat.c
proc/stat.h
proc/vmstat.c
proc/vmstat.h

index 6c9fa0fe477c332002b13c8493b34c0c47008f8c..fd313e37bef450840a58f58534b3e4aaceb22e48 100644 (file)
@@ -224,6 +224,10 @@ MEM_set(SWAP_FREE,              ul_int,  SwapFree)
 MEM_set(SWAP_TOTAL,             ul_int,  SwapTotal)
 MEM_set(SWAP_USED,              ul_int,  derived_swap_used)
 
+#undef setDECL
+#undef MEM_set
+#undef HST_set
+
 
 // ___ Results 'Get' Support ||||||||||||||||||||||||||||||||||||||||||||||||||
 
@@ -332,6 +336,10 @@ MEM_get(SWAP_FREE,             SwapFree)
 MEM_get(SWAP_TOTAL,            SwapTotal)
 MEM_get(SWAP_USED,             derived_swap_used)
 
+#undef getDECL
+#undef MEM_get
+#undef HST_get
+
 
 // ___ Controlling Table ||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
@@ -456,16 +464,11 @@ static struct {
 enum meminfo_item PROCPS_MEMINFO_logical_end = PROCPS_MEMINFO_SWAP_USED + 1;
 
 #undef setNAME
-#undef setDECL
-#undef MEM_set
-#undef HST_set
 #undef getNAME
-#undef getDECL
-#undef MEM_get
-#undef HST_get
 #undef RS
 #undef RG
 
+
 // ___ Private Functions ||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
 static inline void assign_results (
@@ -816,6 +819,8 @@ static struct stacks_extent *stacks_alloc (
 
 // ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
+// --- standard required functions --------------------------------------------
+
 /*
  * procps_meminfo_new:
  *
@@ -882,6 +887,8 @@ PROCPS_EXPORT int procps_meminfo_unref (
 } // end: procps_meminfo_unref
 
 
+// --- variable interface functions -------------------------------------------
+
 PROCPS_EXPORT signed long procps_meminfo_get (
         struct procps_meminfo *info,
         enum meminfo_item item)
@@ -904,9 +911,7 @@ PROCPS_EXPORT signed long procps_meminfo_get (
         sav_secs = cur_secs;
     }
 
-    if (item < PROCPS_MEMINFO_logical_end)
-        return Item_table[item].getsfunc(info);
-    return -EINVAL;
+    return Item_table[item].getsfunc(info);
 } // end: procps_meminfo_get
 
 
index 9343058c45422ef14d6c97bd1550997a61c10977..d5380d823dc70d0e0749e8e8a5ece437b572462c 100644 (file)
@@ -121,12 +121,11 @@ enum meminfo_item {
     PROCPS_MEMINFO_SWAP_USED              //  ul_int
 };
 
-struct procps_meminfo;
 
 struct meminfo_result {
     enum meminfo_item item;
     union {
-        signed int      s_int;
+        signed int     s_int;
         unsigned long  ul_int;
     } result;
 };
index c9838ccd7a4c75dde7dfa06369333bb06fa14f7e..b978a5df3feb152f56fb9f760af01bd6f3e75389 100644 (file)
@@ -144,7 +144,7 @@ enum pids_item {
     PROCPS_PIDS_VM_USED,           //  sl_int
     PROCPS_PIDS_VSIZE_PGS,         //  ul_int
     PROCPS_PIDS_WCHAN_ADDR,        //  ul_int
-    PROCPS_PIDS_WCHAN_NAME,        //     str
+    PROCPS_PIDS_WCHAN_NAME         //     str
 };
 
 enum pids_fetch_type {
@@ -163,19 +163,17 @@ enum pids_sort_order {
 };
 
 
-struct procps_pidsinfo;
-
 struct pids_result {
     enum pids_item item;
     union {
-        char                 s_ch;
-        int                  s_int;
-        unsigned int         u_int;
-        long                 sl_int;
-        unsigned long        ul_int;
-        unsigned long long   ull_int;
-        char               * str;
-        char              ** strv;
+        signed char         s_ch;
+        signed int          s_int;
+        unsigned int        u_int;
+        signed long         sl_int;
+        unsigned long       ul_int;
+        unsigned long long  ull_int;
+        char               *str;
+        char              **strv;
     } result;
 };
 
@@ -198,6 +196,8 @@ struct pids_fetch {
     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_ref   (struct procps_pidsinfo  *info);
 int procps_pids_unref (struct procps_pidsinfo **info);
index 4516c2325a553cf8f24c07bf1b9f7c45d2c1ed50..8249cc0331e40d295231825a19b350eab2b3bd32 100644 (file)
@@ -829,6 +829,8 @@ static int stacks_reconfig_maybe (
 
 // ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
+// --- standard required functions --------------------------------------------
+
 /*
  * procps_slabinfo_new():
  *
@@ -859,7 +861,7 @@ PROCPS_EXPORT int procps_slabinfo_new (
 
     /* do a priming read here for the following potential benefits: |
          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))) {
         procps_slabinfo_unref(&p);
         return rc;
@@ -919,6 +921,8 @@ PROCPS_EXPORT int procps_slabinfo_unref (
 } // end: procps_slabinfo_unref
 
 
+// --- variable interface functions -------------------------------------------
+
 PROCPS_EXPORT signed long procps_slabinfo_get (
         struct procps_slabinfo *info,
         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);
     return stacks;
- #undef QSORT_r
 } // end: procps_slabinfo_sort
index 0c3df56fa6051efcd9365ecc2203a69b973ce6df..6faa866ddafbdd8cfd07345286c42a2c5cabdc88 100644 (file)
@@ -78,10 +78,10 @@ enum slabinfo_sort_order {
 struct slabinfo_result {
     enum slabinfo_item item;
     union {
-        signed int      s_int;
-        unsigned int    u_int;
-        unsigned long   ul_int;
-        char          * str;
+        signed int     s_int;
+        unsigned int   u_int;
+        unsigned long  ul_int;
+        char          *str;
     } result;
 };
 
index 4f8ea3e27649bf3a39d60748b7cd8836ef137d75..8b7ef63fba0323c8e328daabc73501472d92bd00 100644 (file)
@@ -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)
 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 ||||||||||||||||||||||||||||||||||||||||||||||||||
 
@@ -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)
 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 ||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
@@ -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;
 
 #undef setNAME
-#undef setDECL
-#undef TIC_set
-#undef SYS_set
-#undef TICsetH
-#undef SYSsetH
 #undef getNAME
-#undef getDECL
-#undef TIC_get
-#undef SYS_get
-#undef TICgetH
-#undef SYSgetH
 #undef RS
 #undef RG
 
@@ -458,6 +460,7 @@ static int make_numa_hist (
        ( 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 ) */
     info->nodes.total = info->our_max_node() + 1;
+
     if (!info->nodes.hist.n_alloc
     || !(info->nodes.total < info->nodes.hist.n_alloc)) {
         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
     memset(info->nodes.hist.tics, 0, info->nodes.hist.n_alloc * sizeof(struct hist_tic));
     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;
     }
@@ -808,6 +811,8 @@ static struct stat_stack *update_single_stack (
 
 // ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
+// --- standard required functions --------------------------------------------
+
 /*
  * procps_stat_new:
  *
@@ -922,6 +927,8 @@ PROCPS_EXPORT int procps_stat_unref (
 } // end: procps_stat_unref
 
 
+// --- variable interface functions -------------------------------------------
+
 PROCPS_EXPORT signed long long procps_stat_get (
         struct procps_statinfo *info,
         enum stat_item item)
@@ -930,6 +937,11 @@ PROCPS_EXPORT signed long long procps_stat_get (
     time_t cur_secs;
     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
        who chooses not to use the much more efficient 'select' function ... */
     cur_secs = time(NULL);
@@ -939,9 +951,7 @@ PROCPS_EXPORT signed long long procps_stat_get (
         sav_secs = cur_secs;
     }
 
-    if (item < PROCPS_STAT_logical_end)
-        return Item_table[item].getsfunc(info);
-    return -EINVAL;
+    return Item_table[item].getsfunc(info);
 } // end: procps_stat_get
 
 
index 7fa3f2c74e67aca944fcf3264863c9b2451fba7d..1ebf7949302b184fa45d42cf0da8dd2a2db1606e 100644 (file)
@@ -60,7 +60,7 @@ enum stat_item {
     PROCPS_STAT_SYS_DELTA_INTERRUPTS,    //   s_int
     PROCPS_STAT_SYS_DELTA_PROC_BLOCKED,  //   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 {
@@ -71,9 +71,9 @@ enum stat_reap_type {
 struct stat_result {
     enum stat_item item;
     union {
-        signed int            s_int;
-        signed long          sl_int;
-        unsigned long        ul_int;
+        signed int          s_int;
+        signed long         sl_int;
+        unsigned long       ul_int;
         unsigned long long  ull_int;
     } result;
 };
index d0536668f52229015f4e40618e1e12203c6c2333..0881cce807acaf3d88fb23d295eeb499298ba30f 100644 (file)
@@ -1358,6 +1358,8 @@ static struct stacks_extent *stacks_alloc (
 
 // ___ Public Functions |||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
+// --- standard required functions --------------------------------------------
+
 /*
  * procps_vmstat_new:
  *
@@ -1424,6 +1426,8 @@ PROCPS_EXPORT int procps_vmstat_unref (
 } // end: procps_vmstat_unref
 
 
+// --- variable interface functions -------------------------------------------
+
 PROCPS_EXPORT signed long procps_vmstat_get (
         struct procps_vmstat *info,
         enum vmstat_item item)
@@ -1446,9 +1450,7 @@ PROCPS_EXPORT signed long procps_vmstat_get (
         sav_secs = cur_secs;
     }
 
-    if (item < PROCPS_VMSTAT_logical_end)
-        return Item_table[item].getsfunc(info);
-    return -EINVAL;
+    return Item_table[item].getsfunc(info);
 } // end: procps_vmstat_get
 
 
index 9b8ea5e981010c3fe77d7e489ff3d1b3f740ad8f..618f77ac41b1851e55bc0f5a7c225107f325e883 100644 (file)
@@ -275,8 +275,8 @@ enum vmstat_item {
 struct vmstat_result {
     enum vmstat_item item;
     union {
-        signed long   sl_int;
-        unsigned long ul_int;
+        signed long    sl_int;
+        unsigned long  ul_int;
     } result;
 };