]> granicus.if.org Git - procps-ng/commitdiff
top: tweak newlib interface, as more experience gained
authorJim Warner <james.warner@comcast.net>
Tue, 30 Jun 2015 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Wed, 1 Jul 2015 11:32:16 +0000 (21:32 +1000)
Now that the dust is settling following an initial API
library effort, it is apparent my naming standards may
not have always been observed. This was a minor crime,
since those standards are unwritten (& not apparent?).

Basically, top has always capitalized the first letter
of global variables in an effort to distinguish global
definitions from local variables later in the program.

So this patch alters the new API variables to conform,
while also explicitly using 'context' for key structs.

Lastly, top now employs the new '#include <proc/name>'
conventions for the new/converted module header files.

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c
top/top_nls.c
top/top_nls.h

index e46cf50bb79704856e8bfb00d0e501100109f31c..c573dab44bc7ea6b699604fdb6c419dcd77c473f 100644 (file)
--- a/top/top.c
+++ b/top/top.c
 #include "../include/nls.h"
 
 #include "../proc/devname.h"
-#include "../proc/meminfo.h"
+#include <proc/meminfo.h>
 #include "../proc/procps.h"
 #include "../proc/readproc.h"
-#include "../proc/readstat.h"
+#include <proc/readstat.h>
 #include "../proc/sysinfo.h"
-#include "../proc/version.h"
+#include <proc/version.h>
 #include "../proc/wchan.h"
-#include "../proc/uptime.h"
+#include <proc/uptime.h>
 
 #include "top.h"
 #include "top_nls.h"
@@ -251,25 +251,25 @@ static const char Graph_bars[] = "||||||||||||||||||||||||||||||||||||||||||||||
 
         /* Support for the new library API -- acquired (if necessary)
            at program startup and referenced throughout our lifetime */
-static struct procps_meminfo *mem_info;
-static struct meminfo_result mem_chain[] = {
-   { PROCPS_MEM_FREE,      0, &mem_chain[1] },
-   { PROCPS_MEM_USED,      0, &mem_chain[2] },
-   { PROCPS_MEM_TOTAL,     0, &mem_chain[3] },
-   { PROCPS_MEM_CACHED,    0, &mem_chain[4] },
-   { PROCPS_MEM_BUFFERS,   0, &mem_chain[5] },
-   { PROCPS_MEM_AVAILABLE, 0, &mem_chain[6] },
-   { PROCPS_SWAP_TOTAL,    0, &mem_chain[7] },
-   { PROCPS_SWAP_FREE,     0, &mem_chain[8] },
+static struct procps_meminfo *Mem_context;
+static struct meminfo_result Mem_chain[] = {
+   { PROCPS_MEM_FREE,      0, &Mem_chain[1] },
+   { PROCPS_MEM_USED,      0, &Mem_chain[2] },
+   { PROCPS_MEM_TOTAL,     0, &Mem_chain[3] },
+   { PROCPS_MEM_CACHED,    0, &Mem_chain[4] },
+   { PROCPS_MEM_BUFFERS,   0, &Mem_chain[5] },
+   { PROCPS_MEM_AVAILABLE, 0, &Mem_chain[6] },
+   { PROCPS_SWAP_TOTAL,    0, &Mem_chain[7] },
+   { PROCPS_SWAP_FREE,     0, &Mem_chain[8] },
    { PROCPS_SWAP_USED,     0, NULL          }
 };
 enum mem_enums {
    mem_FREE,  mem_USED,  mem_TOTAL, mem_CACHE, mem_BUFFS,
    mem_AVAIL, swp_TOTAL, swp_FREE,  swp_USED
 };
-#define MEM_VAL(e) mem_chain[e].result
+#define MEM_VAL(e) Mem_chain[e].result
 
-static struct procps_stat *sys_info;
+static struct procps_stat *Cpu_context;
 static struct procps_jiffs_hist *Cpu_jiffs;
 \f
 /*######  Sort callbacks  ################################################*/
@@ -578,8 +578,8 @@ static void bye_bye (const char *str) {
 #endif // end: ATEOJ_RPTHSH
 #endif // end: OFF_HST_HASH
 
-   procps_stat_unref(&sys_info);
-   procps_meminfo_unref(&mem_info);
+   procps_stat_unref(&Cpu_context);
+   procps_meminfo_unref(&Mem_context);
 #ifndef NUMA_DISABLE
   if (Libnuma_handle) dlclose(Libnuma_handle);
 #endif
@@ -2399,16 +2399,16 @@ static void cpus_refresh (void) {
       Cpu_jiffs = alloc_c(totSLOT * sizeof(struct procps_jiffs_hist));
    }
 
-   // first. snapshot the proc/stat cpu jiffs
-   if (procps_stat_read_jiffs(sys_info) < 0)
-      error_exit(N_txt(LIB_errorsys_txt));
-   // second, retrieve just the cpu summary jiffs
-   if (procps_stat_get_jiffs_hist(sys_info, &Cpu_jiffs[sumSLOT], -1) < 0)
-      error_exit(N_txt(LIB_errorsys_txt));
-   // then retrieve all of the actual cpu jiffs
-   Cpu_faux_cnt = procps_stat_get_jiffs_hist_all(sys_info, Cpu_jiffs, sumSLOT);
+   // 1st, snapshot the proc/stat cpu jiffs
+   if (procps_stat_read_jiffs(Cpu_context) < 0)
+      error_exit(N_txt(LIB_errorcpu_txt));
+   // 2nd, retrieve just the cpu summary jiffs
+   if (procps_stat_get_jiffs_hist(Cpu_context, &Cpu_jiffs[sumSLOT], -1) < 0)
+      error_exit(N_txt(LIB_errorcpu_txt));
+   // 3rd, retrieve all of the actual cpu jiffs
+   Cpu_faux_cnt = procps_stat_get_jiffs_hist_all(Cpu_context, Cpu_jiffs, sumSLOT);
    if (Cpu_faux_cnt < 0)
-      error_exit(N_txt(LIB_errorsys_txt));
+      error_exit(N_txt(LIB_errorcpu_txt));
 
 #ifndef NUMA_DISABLE
    /* henceforth, with just a little more arithmetic we can avoid
@@ -2669,9 +2669,10 @@ static void sysinfo_refresh (int forced) {
 
    /*** hotplug_acclimated ***/
    if (3 <= cur_secs - mem_secs) {
-      if (procps_meminfo_read(mem_info) < 0)
-         error_exit(N_txt(LIB_errormem_txt));
-      procps_meminfo_get_chain(mem_info, mem_chain);
+      if ((procps_meminfo_read(Mem_context) < 0)
+         || (procps_meminfo_get_chain(Mem_context, Mem_chain) < 0))
+            error_exit(N_txt(LIB_errormem_txt));
+      procps_meminfo_get_chain(Mem_context, Mem_chain);
       mem_secs = cur_secs;
    }
 #ifndef PRETEND8CPUS
@@ -3265,13 +3266,13 @@ static void before (char *me) {
 
    // get virtual page stuff
    i = page_bytes; // from sysinfo.c, at lib init
-   while(i > 1024) { i >>= 1; Pg2K_shft++; }
+   while (i > 1024) { i >>= 1; Pg2K_shft++; }
 
    // prepare for new library API ...
-   if (procps_meminfo_new(&mem_info) < 0)
+   if (procps_meminfo_new(&Mem_context) < 0)
       error_exit(N_txt(LIB_errormem_txt));
-   if (procps_stat_new(&sys_info) < 0)
-      error_exit(N_txt(LIB_errorsys_txt));
+   if (procps_stat_new(&Cpu_context) < 0)
+      error_exit(N_txt(LIB_errorcpu_txt));
 
 #ifndef OFF_HST_HASH
    // prep for HST_t's put/get hashing optimizations
index 0579cd7792af5351f0aebf139d2e77819668b0ed..a4342e48f4636af2dead83fdf1c736291d460bd5 100644 (file)
@@ -470,8 +470,8 @@ static void build_norm_nlstab (void) {
    .                 padding with extra spaces as necessary */
    Norm_nlstab[WORD_abv_mem_txt] = _("Mem ");
    Norm_nlstab[WORD_abv_swp_txt] = _("Swap");
-   Norm_nlstab[LIB_errormem_txt] = _("library failed memory stats");
-   Norm_nlstab[LIB_errorsys_txt] = _("library failed system stats");
+   Norm_nlstab[LIB_errormem_txt] = _("library failed memory statistics");
+   Norm_nlstab[LIB_errorcpu_txt] = _("library failed cpu statistics");
 }
 
 
index 050fba4f3c2d7cb66a84238d4db226e0660c20f0..361ea8ca01e97d6be188c6f6d940e77c5100c1bf 100644 (file)
@@ -73,7 +73,7 @@ enum norm_nls {
    FAIL_widepid_txt, FIND_no_find_fmt, FIND_no_next_txt, FOREST_modes_fmt,
    FOREST_views_txt, GET_find_str_txt, GET_max_task_fmt, GET_nice_num_fmt,
    GET_pid2kill_fmt, GET_pid2nice_fmt, GET_sigs_num_fmt, GET_user_ids_txt,
-   HELP_cmdline_fmt, IRIX_curmode_fmt, LIB_errormem_txt, LIB_errorsys_txt,
+   HELP_cmdline_fmt, IRIX_curmode_fmt, LIB_errorcpu_txt, LIB_errormem_txt,
    LIMIT_exceed_fmt, MISSING_args_fmt, NAME_windows_fmt, NOT_onsecure_txt,
    NOT_smp_cpus_txt, NUMA_nodebad_txt, NUMA_nodeget_fmt, NUMA_nodenam_fmt,
    NUMA_nodenot_txt, OFF_one_word_txt, ON_word_only_txt, OSEL_casenot_txt,