Hello community,

here is the log from the commit of package eventstat for openSUSE:Factory 
checked in at 2017-10-30 21:18:40
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/eventstat (Old)
 and      /work/SRC/openSUSE:Factory/.eventstat.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "eventstat"

Mon Oct 30 21:18:40 2017 rev:4 rq:537433 version:0.04.02

Changes:
--------
--- /work/SRC/openSUSE:Factory/eventstat/eventstat.changes      2017-09-09 
20:26:13.000780368 +0200
+++ /work/SRC/openSUSE:Factory/.eventstat.new/eventstat.changes 2017-10-30 
21:19:00.798044294 +0100
@@ -1,0 +2,15 @@
+Thu Oct 19 17:49:55 UTC 2017 - mar...@gmx.de
+
+- Update to version 4.04.02
+  * Makefile: bump version
+  * Iterate over arrays using size of array rather than using
+    sentinels at end of array
+  * Remove empty lines
+  * Voidify returns from various functions
+  * Add some UNLIKELY/LIKELY branch hinting
+  * debian/control: update Standards-Version to 4.1.1
+  * Prefix all globals with g_ to notify scope
+  * Use sizeof object rather than size of type
+  * Remove whitespace from source
+
+-------------------------------------------------------------------

Old:
----
  eventstat-0.04.01.tar.gz

New:
----
  eventstat-0.04.02.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ eventstat.spec ++++++
--- /var/tmp/diff_new_pack.AvqflS/_old  2017-10-30 21:19:01.366023644 +0100
+++ /var/tmp/diff_new_pack.AvqflS/_new  2017-10-30 21:19:01.390022771 +0100
@@ -18,7 +18,7 @@
 
 
 Name:           eventstat
-Version:        0.04.01
+Version:        0.04.02
 Release:        0
 Summary:        Kernel event states monitoring tool
 License:        GPL-2.0+

++++++ eventstat-0.04.01.tar.gz -> eventstat-0.04.02.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/eventstat-0.04.01/Makefile 
new/eventstat-0.04.02/Makefile
--- old/eventstat-0.04.01/Makefile      2017-08-16 20:47:11.000000000 +0200
+++ new/eventstat-0.04.02/Makefile      2017-10-18 23:15:10.000000000 +0200
@@ -16,7 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
 #
 
-VERSION=0.04.01
+VERSION=0.04.02
 
 CFLAGS += -Wall -Wextra -DVERSION='"$(VERSION)"' -O2
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/eventstat-0.04.01/eventstat.c 
new/eventstat-0.04.02/eventstat.c
--- old/eventstat-0.04.01/eventstat.c   2017-08-16 20:47:11.000000000 +0200
+++ new/eventstat-0.04.02/eventstat.c   2017-10-18 23:15:10.000000000 +0200
@@ -43,6 +43,8 @@
 
 #define TABLE_SIZE             (1009)          /* Should be a prime */
 
+#define SIZEOF_ARRAY(a)                (sizeof(a) / sizeof(a[0]))
+
 #define OPT_QUIET              (0x00000001)
 #define OPT_CUMULATIVE         (0x00000002)
 #define OPT_CMD_SHORT          (0x00000004)
@@ -95,6 +97,14 @@
 #define OPTIMIZE3
 #endif
 
+#if defined(__GNUC__)
+#define LIKELY(x)      __builtin_expect((x),1)
+#define UNLIKELY(x)    __builtin_expect((x),0)
+#else
+#define LIKELY(x)      (x)
+#define UNLIKELY(x)    (x)
+#endif
+
 #define FLOAT_TINY             (0.0000001)
 #define FLOAT_CMP(a, b)                (fabs(a - b) < FLOAT_TINY)
 
@@ -150,47 +160,47 @@
 
 #define KERN_TASK_INFO(str)            { str, sizeof(str) - 1 }
 
-static const char * const app_name = "eventstat";
-static const char * const sys_tracing_enable =
+static const char * const g_app_name = "eventstat";
+static const char * const g_sys_tracing_enable =
        "/sys/kernel/debug/tracing/events/timer/hrtimer_start/enable";
-static const char * const sys_tracing_pipe =
+static const char * const g_sys_tracing_pipe =
        "/sys/kernel/debug/tracing/trace_pipe";
-static const char * const sys_tracing_set_event =
+static const char * const g_sys_tracing_set_event =
        "/sys/kernel/debug/tracing/set_event";
-static const char * const sys_tracing_filter =
+static const char * const g_sys_tracing_filter =
        "/sys/kernel/debug/tracing/events/timer/filter";
 
 static void es_printf(const char *fmt, ...) __attribute__((format(printf, 1, 
2)));
 
-static timer_stat_t *timer_stat_free_list; /* free list of timer stats */
-static timer_info_t *timer_info_list;  /* cache list of timer_info */
-static timer_info_t *timer_info_hash[TABLE_SIZE]; /* hash of timer_info */
+static timer_stat_t *g_timer_stat_free_list;   /* free list of timer stats */
+static timer_info_t *g_timer_info_list;                /* cache list of 
timer_info */
+static timer_info_t *g_timer_info_hash[TABLE_SIZE]; /* hash of timer_info */
 
 /* head of list of samples, sorted in sample time order */
-static sample_delta_list_t *sample_delta_list_head;
+static sample_delta_list_t *g_sample_delta_list_head;
 
 /* tail of list of samples, sorted in sample time order */
-static sample_delta_list_t *sample_delta_list_tail;
+static sample_delta_list_t *g_sample_delta_list_tail;
 
 /* ignore samples with event delta less than this */
-static double opt_threshold;
+static double g_opt_threshold;
 
-static char *csv_results;              /* results in comma separated values */
-static char *get_events_buf;           /* buffer to glob events into */
-static uint32_t timer_info_list_length;        /* length of timer_info_list */
-static uint32_t opt_flags;             /* option flags */
-static volatile bool stop_eventstat = false;   /* set by sighandler */
-static bool sane_procs;                        /* false if we are in a 
container */
-static bool resized;                   /* window resized */
-static bool curses_init;               /* curses initialised */
-static int rows = 25;                  /* tty size, rows */
-static int cols = 80;                  /* tty size, columns */
+static char *g_csv_results;            /* results in comma separated values */
+static char *g_get_events_buf;         /* buffer to glob events into */
+static uint32_t g_timer_info_list_length; /* length of timer_info_list */
+static uint32_t g_opt_flags;           /* option flags */
+static volatile bool g_stop_eventstat = false; /* set by sighandler */
+static bool g_sane_procs;              /* false if we are in a container */
+static bool g_resized;                 /* window resized */
+static bool g_curses_init;             /* curses initialised */
+static int g_rows = 25;                        /* tty size, rows */
+static int g_cols = 80;                        /* tty size, columns */
 
 /*
  *  Attempt to catch a range of signals so
  *  we can clean
  */
-static const int signals[] = {
+static const int g_signals[] = {
        /* POSIX.1-1990 */
 #ifdef SIGHUP
        SIGHUP,
@@ -236,7 +246,6 @@
 #ifdef SIGVTALRM
        SIGVTALRM,
 #endif
-       -1,
 };
 
 /*
@@ -272,7 +281,6 @@
                max_digits = min_digits;
 ret:
        return max_digits;
-
 }
 
 /*
@@ -301,8 +309,8 @@
        struct winsize ws;
 
        if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1) {
-               rows = ws.ws_row;
-               cols = ws.ws_col;
+               g_rows = ws.ws_row;
+               g_cols = ws.ws_col;
        }
 }
 
@@ -312,7 +320,7 @@
  */
 static inline void eventstat_clear(void)
 {
-       if (curses_init)
+       if (g_curses_init)
                clear();
 }
 
@@ -322,7 +330,7 @@
  */
 static inline void eventstat_refresh(void)
 {
-       if (curses_init)
+       if (g_curses_init)
                refresh();
 }
 
@@ -332,7 +340,7 @@
  */
 static inline void eventstat_move(const int y, const int x)
 {
-       if (curses_init)
+       if (g_curses_init)
                move(y, x);
 }
 
@@ -342,7 +350,7 @@
  */
 static void eventstat_endwin(void)
 {
-       if (curses_init) {
+       if (g_curses_init) {
                clear();
                endwin();
        }
@@ -359,7 +367,7 @@
 
        va_start(ap, fmt);
        eventstat_endwin();
-       vfprintf(stderr,fmt, ap);
+       (void)vfprintf(stderr,fmt, ap);
        va_end(ap);
 
        exit(EXIT_FAILURE);
@@ -398,21 +406,21 @@
  */
 static inline void set_tracing_enable(const char *str, const bool carp)
 {
-       set_tracing(sys_tracing_enable, str, carp);
+       set_tracing(g_sys_tracing_enable, str, carp);
 }
 
 static void set_tracing_event(void)
 {
        char buffer[64];
 
-       set_tracing(sys_tracing_set_event, "\n", true);
-       set_tracing(sys_tracing_set_event, "hrtimer_start", true);
-       set_tracing(sys_tracing_filter, "0", true);
+       set_tracing(g_sys_tracing_set_event, "\n", true);
+       set_tracing(g_sys_tracing_set_event, "hrtimer_start", true);
+       set_tracing(g_sys_tracing_filter, "0", true);
 
        /* Ignore event stat and idle events */
-       snprintf(buffer, sizeof(buffer),
+       (void)snprintf(buffer, sizeof(buffer),
                "common_pid != %d && common_pid != 0", getpid());
-       set_tracing(sys_tracing_filter, buffer, true);
+       set_tracing(g_sys_tracing_filter, buffer, true);
 }
 
 
@@ -457,7 +465,7 @@
 {
        struct timeval tv;
 
-       if (gettimeofday(&tv, NULL) < 0)
+       if (UNLIKELY(gettimeofday(&tv, NULL) < 0))
                err_abort("gettimeofday failed: errno=%d (%s)\n",
                        errno, strerror(errno));
        return timeval_to_double(&tv);
@@ -498,7 +506,6 @@
                        ptr = pattern;
                }
        }
-
        (void)fclose(fp);
 
        return ret;
@@ -512,7 +519,7 @@
 {
        (void)dummy;    /* Stop unused parameter warning with -Wextra */
 
-       stop_eventstat = true;
+       g_stop_eventstat = true;
        set_tracing_enable("0\n", false);
 }
 
@@ -522,7 +529,7 @@
  */
 static inline void samples_free(void)
 {
-       sample_delta_list_t *sdl = sample_delta_list_head;
+       sample_delta_list_t *sdl = g_sample_delta_list_head;
 
        while (sdl) {
                sample_delta_list_t *sdl_next = sdl->next;
@@ -548,10 +555,10 @@
        sample_delta_list_t *sdl;
        sample_delta_item_t *sdi;
 
-       if (csv_results == NULL)        /* No need if not enabled */
+       if (g_csv_results == NULL)      /* No need if not enabled */
                return;
 
-       for (sdl = sample_delta_list_head; sdl; sdl = sdl->next) {
+       for (sdl = g_sample_delta_list_head; sdl; sdl = sdl->next) {
                if (FLOAT_CMP(sdl->whence, whence)) {
                        found = true;
                        break;
@@ -563,21 +570,21 @@
         * list since time is assumed to be increasing
         */
        if (!found) {
-               if ((sdl = calloc(1, sizeof(sample_delta_list_t))) == NULL)
+               if ((sdl = calloc(1, sizeof(*sdl))) == NULL)
                        err_abort("Cannot allocate sample delta list\n");
                sdl->whence = whence;
 
-               if (sample_delta_list_tail) {
-                       sample_delta_list_tail->next = sdl;
-                       sample_delta_list_tail = sdl;
+               if (g_sample_delta_list_tail) {
+                       g_sample_delta_list_tail->next = sdl;
+                       g_sample_delta_list_tail = sdl;
                } else {
-                       sample_delta_list_head = sdl;
-                       sample_delta_list_tail = sdl;
+                       g_sample_delta_list_head = sdl;
+                       g_sample_delta_list_tail = sdl;
                }
        }
 
        /* Now append the sdi onto the list */
-       if ((sdi = calloc(1, sizeof(sample_delta_item_t))) == NULL)
+       if (UNLIKELY(((sdi = calloc(1, sizeof(*sdi))) == NULL)))
                err_abort("Cannot allocate sample delta item\n");
        sdi->delta_events = timer_stat->info->delta_events;
        sdi->time_delta = timer_stat->info->last_used -
@@ -656,7 +663,7 @@
 
        size_t i;
 
-       for (i = 0; kernel_tasks[i].task != NULL; i++) {
+       for (i = 0; i < SIZEOF_ARRAY(kernel_tasks); i++) {
                if (!strncmp(task, kernel_tasks[i].task, kernel_tasks[i].len))
                        return true;
        }
@@ -672,7 +679,7 @@
        const pid_t pgid = id == 0 ? 0 : getpgid(id);
 
        /* We are either in a container, or with a task with a NULL cmdline */
-       if (sane_procs || (id >= 0))
+       if (g_sane_procs || (id >= 0))
                return (pgid == 0);
 
        /* Can't get pgid on that pid, so make a guess */
@@ -690,7 +697,7 @@
        int fd;
        ssize_t ret;
 
-       snprintf(buffer, sizeof(buffer), "/proc/%d/cmdline", id);
+       (void)snprintf(buffer, sizeof(buffer), "/proc/%d/cmdline", id);
 
        if ((fd = open(buffer, O_RDONLY)) < 0)
                return NULL;
@@ -707,7 +714,7 @@
        /*
         *  OPT_CMD_LONG option we get the full cmdline args
         */
-       if (opt_flags & OPT_CMD_LONG) {
+       if (g_opt_flags & OPT_CMD_LONG) {
                for (ptr = buffer; ptr < buffer + ret - 1; ptr++) {
                        if (*ptr == '\0')
                                *ptr = ' ';
@@ -717,14 +724,14 @@
        /*
         *  OPT_CMD_SHORT option we discard anything after a space
         */
-       if (opt_flags & OPT_CMD_SHORT) {
+       if (g_opt_flags & OPT_CMD_SHORT) {
                for (ptr = buffer; *ptr && (ptr < buffer + ret); ptr++) {
                        if (*ptr == ' ')
                                *ptr = '\0';
                }
        }
 
-       if (opt_flags & OPT_DIRNAME_STRIP)
+       if (g_opt_flags & OPT_DIRNAME_STRIP)
                return strdup(basename(buffer));
 
        return strdup(buffer);
@@ -753,17 +760,17 @@
                return;
 
        if ((fp = fopen(filename, "w")) == NULL) {
-               fprintf(stderr, "Cannot write to file %s\n", filename);
+               (void)fprintf(stderr, "Cannot write to file %s\n", filename);
                return;
        }
 
-       sorted_timer_infos = calloc(timer_info_list_length,
-                               sizeof(timer_info_t *));
+       sorted_timer_infos = calloc(g_timer_info_list_length,
+                               sizeof(*sorted_timer_infos));
        if (!sorted_timer_infos)
                err_abort("Cannot allocate buffer for sorting timer_infos\n");
 
        /* Just want the timers with some non-zero total */
-       for (n = 0, info = timer_info_list; info; info = info->next) {
+       for (n = 0, info = g_timer_info_list; info; info = info->next) {
                if (info->total_events > 0)
                        sorted_timer_infos[n++] = info;
        }
@@ -775,37 +782,37 @@
        for (i = 0; i < n; i++) {
                char *task;
 
-               if (opt_flags & OPT_CMD)
+               if (g_opt_flags & OPT_CMD)
                        task = sorted_timer_infos[i]->cmdline;
                else
                        task = sorted_timer_infos[i]->task_mangled;
 
-               fprintf(fp, ",%s", task);
+               (void)fprintf(fp, ",%s", task);
        }
-       fprintf(fp, "\n");
+       (void)fprintf(fp, "\n");
 
-       fprintf(fp, ",Init Function:");
+       (void)fprintf(fp, ",Init Function:");
        for (i = 0; i < n; i++)
-               fprintf(fp, ",%s", sorted_timer_infos[i]->func);
-       fprintf(fp, "\n");
+               (void)fprintf(fp, ",%s", sorted_timer_infos[i]->func);
+       (void)fprintf(fp, "\n");
 
-       fprintf(fp, ",Total:");
+       (void)fprintf(fp, ",Total:");
        for (i = 0; i < n; i++)
-               fprintf(fp, ",%" PRIu64, sorted_timer_infos[i]->total_events);
-       fprintf(fp, "\n");
+               (void)fprintf(fp, ",%" PRIu64, 
sorted_timer_infos[i]->total_events);
+       (void)fprintf(fp, "\n");
 
-       for (sdl = sample_delta_list_head; sdl; sdl = sdl->next) {
+       for (sdl = g_sample_delta_list_head; sdl; sdl = sdl->next) {
                time_t t = (time_t)sdl->whence;
                struct tm *tm;
 
                count++;
                tm = localtime(&t);
-               fprintf(fp, "%2.2d:%2.2d:%2.2d",
+               (void)fprintf(fp, "%2.2d:%2.2d:%2.2d",
                        tm->tm_hour, tm->tm_min, tm->tm_sec);
 
                if (first_time < 0)
                        first_time = sdl->whence;
-               fprintf(fp, ",%f", duration_round(sdl->whence - first_time));
+               (void)fprintf(fp, ",%f", duration_round(sdl->whence - 
first_time));
 
                /*
                 * Scan in timer info order to be consistent for all sdl rows
@@ -819,80 +826,80 @@
                         *  raw sample count by scaling by 1.0 (i.e. no scaling)
                         */
                        if (sdi) {
-                               double duration = duration_round((opt_flags & 
OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
-                               fprintf(fp, ",%f",
+                               double duration = duration_round((g_opt_flags & 
OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
+                               (void)fprintf(fp, ",%f",
                                        FLOAT_CMP(duration, 0.0) ? -99.99 :
                                        (double)sdi->delta_events / duration);
                        } else
-                               fprintf(fp, ",%f", 0.0);
+                               (void)fprintf(fp, ",%f", 0.0);
                }
-               fprintf(fp, "\n");
+               (void)fprintf(fp, "\n");
        }
 
        /*
         *  -S option - some statistics, min, max, average, std.dev.
         */
-       if (opt_flags & OPT_RESULT_STATS) {
-               fprintf(fp, ",Min:");
+       if (g_opt_flags & OPT_RESULT_STATS) {
+               (void)fprintf(fp, ",Min:");
                for (i = 0; i < n; i++) {
                        double min = DBL_MAX;
 
-                       for (sdl = sample_delta_list_head; sdl; sdl = 
sdl->next) {
+                       for (sdl = g_sample_delta_list_head; sdl; sdl = 
sdl->next) {
                                sample_delta_item_t *sdi =
                                        sample_find(sdl, sorted_timer_infos[i]);
 
                                if (sdi) {
-                                       double duration = 
duration_round((opt_flags & OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
+                                       double duration = 
duration_round((g_opt_flags & OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
                                        double val = FLOAT_CMP(duration, 0.0) ?
                                                0.0 : sdi->delta_events / 
duration;
                                        if (min > val)
                                                min = val;
                                }
                        }
-                       fprintf(fp, ",%f", min);
+                       (void)fprintf(fp, ",%f", min);
                }
-               fprintf(fp, "\n");
+               (void)fprintf(fp, "\n");
 
-               fprintf(fp, ",Max:");
+               (void)fprintf(fp, ",Max:");
                for (i = 0; i < n; i++) {
                        double max = DBL_MIN;
 
-                       for (sdl = sample_delta_list_head; sdl; sdl = 
sdl->next) {
+                       for (sdl = g_sample_delta_list_head; sdl; sdl = 
sdl->next) {
                                sample_delta_item_t *sdi =
                                        sample_find(sdl, sorted_timer_infos[i]);
 
                                if (sdi) {
-                                       double duration = 
duration_round((opt_flags & OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
+                                       double duration = 
duration_round((g_opt_flags & OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
                                        double val = FLOAT_CMP(duration, 0.0) ?
                                                0.0 : sdi->delta_events / 
duration;
                                        if (max < val)
                                                max = val;
                                }
                        }
-                       fprintf(fp, ",%f", max);
+                       (void)fprintf(fp, ",%f", max);
                }
-               fprintf(fp, "\n");
+               (void)fprintf(fp, "\n");
 
-               fprintf(fp, ",Average:");
+               (void)fprintf(fp, ",Average:");
                for (i = 0; i < n; i++)
-                       fprintf(fp, ",%f", count == 0 ? 0.0 :
+                       (void)fprintf(fp, ",%f", count == 0 ? 0.0 :
                                (double)sorted_timer_infos[i]->total_events / 
count);
-               fprintf(fp, "\n");
+               (void)fprintf(fp, "\n");
 
                /*
                 *  population standard deviation
                 */
-               fprintf(fp, ",Std.Dev.:");
+               (void)fprintf(fp, ",Std.Dev.:");
                for (i = 0; i < n; i++) {
                        double average = (double)
                                sorted_timer_infos[i]->total_events / 
(double)count;
                        double sum = 0.0;
 
-                       for (sdl = sample_delta_list_head; sdl; sdl = 
sdl->next) {
+                       for (sdl = g_sample_delta_list_head; sdl; sdl = 
sdl->next) {
                                sample_delta_item_t *sdi =
                                        sample_find(sdl, sorted_timer_infos[i]);
                                if (sdi) {
-                                       double duration = 
duration_round((opt_flags & OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
+                                       double duration = 
duration_round((g_opt_flags & OPT_SAMPLE_COUNT) ? 1.0 : sdi->time_delta);
                                        double diff = FLOAT_CMP(duration, 0.0) 
? 0.0 :
                                                ((double)sdi->delta_events - 
average) / duration;
                                        diff = diff * diff;
@@ -900,9 +907,9 @@
                                }
                        }
                        sum = sum / (double)count;
-                       fprintf(fp, ",%f", sqrt(sum));
+                       (void)fprintf(fp, ",%f", sqrt(sum));
                }
-               fprintf(fp, "\n");
+               (void)fprintf(fp, "\n");
        }
        free(sorted_timer_infos);
        (void)fclose(fp);
@@ -922,15 +929,15 @@
        timer_info_t *info;
        const uint32_t h = hash_djb2a(ident);
 
-       for (info = timer_info_hash[h]; info; info = info->hash_next) {
-               if (strcmp(ident, info->ident) == 0) {
+       for (info = g_timer_info_hash[h]; info; info = info->hash_next) {
+               if (UNLIKELY(strcmp(ident, info->ident) == 0)) {
                        info->prev_used = info->last_used;
                        info->last_used = time_now;
                        return info;
                }
        }
-       info = calloc(1, sizeof(timer_info_t));
-       if (!info)
+       info = calloc(1, sizeof(*info));
+       if (UNLIKELY(!info))
                err_abort("Cannot allocate timer info\n");
 
        info->pid = new_info->pid;
@@ -950,20 +957,20 @@
        info->total_events = 1;
        info->delta_events = 1;
 
-       if (info->task == NULL ||
-           info->task_mangled == NULL ||
-           info->cmdline == NULL ||
-           info->func == NULL ||
-           info->ident == NULL) {
+       if (UNLIKELY(info->task == NULL ||
+                    info->task_mangled == NULL ||
+                    info->cmdline == NULL ||
+                    info->func == NULL ||
+                    info->ident == NULL)) {
                err_abort("Out of memory allocating a timer stat fields\n");
        }
 
        /* Does not exist in list, append it */
-       info->next = timer_info_list;
-       timer_info_list = info;
-       timer_info_list_length++;
-       info->hash_next = timer_info_hash[h];
-       timer_info_hash[h] = info;
+       info->next = g_timer_info_list;
+       g_timer_info_list = info;
+       g_timer_info_list_length++;
+       info->hash_next = g_timer_info_hash[h];
+       g_timer_info_hash[h] = info;
 
        return info;
 }
@@ -1008,7 +1015,7 @@
                                *list = next;
                        else
                                prev->next = next;
-                       timer_info_list_length--;
+                       g_timer_info_list_length--;
                } else {
                        prev = info;
                }
@@ -1048,7 +1055,6 @@
        }
 }
 
-
 /*
  *  timer_info_purge_old()
  *     clean out old timer infos
@@ -1062,9 +1068,9 @@
                size_t i;
 
                count = 0;
-               timer_info_purge_old_from_timer_list(&timer_info_list, 
time_now);
+               timer_info_purge_old_from_timer_list(&g_timer_info_list, 
time_now);
                for (i = 0; i < TABLE_SIZE; i++)
-                       
timer_info_purge_old_from_hash_list(&timer_info_hash[i], time_now);
+                       
timer_info_purge_old_from_hash_list(&g_timer_info_hash[i], time_now);
        }
 }
 
@@ -1074,7 +1080,7 @@
  */
 static inline void timer_info_list_free(void)
 {
-       timer_info_t *info = timer_info_list;
+       timer_info_t *info = g_timer_info_list;
 
        /* Free list and timers on list */
        while (info) {
@@ -1092,11 +1098,11 @@
 {
        static char ident[128];
 
-       if (opt_flags & OPT_TIMER_ID) {
-               snprintf(ident, sizeof(ident), "%x%s%8.8s%" PRIx64,
+       if (g_opt_flags & OPT_TIMER_ID) {
+               (void)snprintf(ident, sizeof(ident), "%x%s%8.8s%" PRIx64,
                        info->pid, info->task, info->func, info->timer);
        } else {
-               snprintf(ident, sizeof(ident), "%x%s%8.8s",
+               (void)snprintf(ident, sizeof(ident), "%x%s%8.8s",
                        info->pid, info->task, info->func);
        }
        return ident;
@@ -1108,7 +1114,7 @@
  */
 static void timer_stat_free_list_free(void)
 {
-       timer_stat_t *ts = timer_stat_free_list;
+       timer_stat_t *ts = g_timer_stat_free_list;
 
        while (ts) {
                timer_stat_t *next = ts->next;
@@ -1116,7 +1122,7 @@
                free(ts);
                ts = next;
        }
-       timer_stat_free_list = NULL;
+       g_timer_stat_free_list = NULL;
 }
 
 /*
@@ -1136,8 +1142,8 @@
                        /* Decrement info ref count */
                        ts->info->ref_count--;
                        /* Add it onto the timer stat free list */
-                       ts->next = timer_stat_free_list;
-                       timer_stat_free_list = ts;
+                       ts->next = g_timer_stat_free_list;
+                       g_timer_stat_free_list = ts;
 
                        ts = next;
                }
@@ -1161,7 +1167,7 @@
        timer_stat_t *ts, *ts_new;
 
        for (ts = timer_stats[h]; ts; ts = ts->next) {
-               if (strcmp(ts->info->ident, ident) == 0) {
+               if (UNLIKELY(strcmp(ts->info->ident, ident) == 0)) {
                        ts->info->total_events++;
                        ts->info->delta_events++;
                        sample_add(ts, time_now);
@@ -1169,13 +1175,13 @@
                }
        }
        /* Not found, it is new */
-       if (timer_stat_free_list) {
+       if (g_timer_stat_free_list) {
                /* Get new one from free list */
-               ts_new = timer_stat_free_list;
-               timer_stat_free_list = timer_stat_free_list->next;
+               ts_new = g_timer_stat_free_list;
+               g_timer_stat_free_list = g_timer_stat_free_list->next;
        } else {
                /* Get one from heap */
-               if ((ts_new = malloc(sizeof(timer_stat_t))) == NULL)
+               if ((ts_new = malloc(sizeof(*ts_new))) == NULL)
                        err_abort("Out of memory allocating a timer stat\n");
        }
 
@@ -1197,7 +1203,7 @@
        timer_stat_t *new)              /* timer stat to add */
 {
        while (*sorted) {
-               if (opt_flags & OPT_CUMULATIVE) {
+               if (g_opt_flags & OPT_CUMULATIVE) {
                        if ((*sorted)->info->total_events < 
new->info->total_events) {
                                new->sorted_freq_next = *(sorted);
                                break;
@@ -1223,13 +1229,13 @@
        va_list ap;
 
        va_start(ap, fmt);
-       if (curses_init) {
+       if (g_curses_init) {
                char buf[256];
 
-               vsnprintf(buf, sizeof(buf), fmt, ap);
-               printw("%s", buf);
+               (void)vsnprintf(buf, sizeof(buf), fmt, ap);
+               (void)printw("%s", buf);
        } else {
-               vprintf(fmt, ap);
+               (void)vprintf(fmt, ap);
        }
        va_end(ap);
 }
@@ -1254,7 +1260,7 @@
                        timer_stat_sort_freq_add(&sorted, ts);
        }
 
-       if (!(opt_flags & OPT_QUIET)) {
+       if (!(g_opt_flags & OPT_QUIET)) {
                uint64_t total = 0UL, kt_total = 0UL;
                int32_t j = 0;
                const int pid_size = pid_max_digits();
@@ -1262,23 +1268,23 @@
                int min_width;
 
                eventstat_winsize();
-               if (resized && curses_init) {
-                       resizeterm(rows, cols);
+               if (g_resized && g_curses_init) {
+                       resizeterm(g_rows, g_cols);
                        refresh();
-                       resized = false;
+                       g_resized = false;
                }
 
                /* Minimum width w/o task or func info */
                min_width = EVENTS_WIDTH + 1 + \
                            1 + \
                            pid_size + 1;
-               if (!(opt_flags & OPT_BRIEF)) {
-                       if (opt_flags & OPT_TIMER_ID)
+               if (!(g_opt_flags & OPT_BRIEF)) {
+                       if (g_opt_flags & OPT_TIMER_ID)
                                min_width += TIMER_ID_WIDTH + 1;
                        fn_size = FUNC_WIDTH;
                }
 
-               sz = cols - min_width;
+               sz = g_cols - min_width;
                sz = (sz < 0) ? 0 : sz;
 
                if (fn_size) {
@@ -1287,21 +1293,21 @@
                                fn_size = FUNC_WIDTH_MAX;
 
                        min_width += fn_size;
-                       sz = cols - min_width;
+                       sz = g_cols - min_width;
                        sz = (sz < 0) ? 0 : sz;
                }
                ta_size = sz;
                if (ta_size < TASK_WIDTH)
                        ta_size = TASK_WIDTH;
-               
+
                es_printf("%*.*s %-*.*s %-*.*s",
                        EVENTS_WIDTH, EVENTS_WIDTH,
-                       (opt_flags & OPT_CUMULATIVE) ?
+                       (g_opt_flags & OPT_CUMULATIVE) ?
                                "Events" : "Event/s",
                        pid_size, pid_size, "PID",
                        ta_size, ta_size, "Task");
-               if (!(opt_flags & OPT_BRIEF)) {
-                       if (opt_flags & OPT_TIMER_ID) {
+               if (!(g_opt_flags & OPT_BRIEF)) {
+                       if (g_opt_flags & OPT_TIMER_ID) {
                                es_printf(" %-16.16s", "Timer ID");
                        }
                        es_printf("%-*.*s\n", fn_size, fn_size,
@@ -1313,14 +1319,14 @@
                while (sorted) {
                        if (((n_lines == -1) || (j < n_lines)) &&
                            (sorted->info->delta_events != 0)) {
-                               char *task = (opt_flags & OPT_CMD) ?
+                               char *task = (g_opt_flags & OPT_CMD) ?
                                        sorted->info->cmdline :
                                        sorted->info->task_mangled;
                                if (!*task)
                                        task = sorted->info->task_mangled;
 
                                j++;
-                               if (opt_flags & OPT_CUMULATIVE)
+                               if (g_opt_flags & OPT_CUMULATIVE)
                                        es_printf("%*" PRIu64 " ",
                                                EVENTS_WIDTH,
                                                sorted->info->total_events);
@@ -1329,7 +1335,7 @@
                                                EVENTS_WIDTH,
                                                
(double)sorted->info->delta_events / duration);
 
-                               if (opt_flags & OPT_BRIEF) {
+                               if (g_opt_flags & OPT_BRIEF) {
 
                                        es_printf("%*d %s\n",
                                                pid_size, sorted->info->pid,
@@ -1338,7 +1344,7 @@
                                        es_printf("%*d %-*.*s",
                                                pid_size, sorted->info->pid,
                                                ta_size, ta_size, task);
-                                       if (opt_flags & OPT_TIMER_ID) {
+                                       if (g_opt_flags & OPT_TIMER_ID) {
                                                es_printf(" %16" PRIx64,
                                                        sorted->info->timer);
                                        }
@@ -1359,7 +1365,7 @@
                        total, (double)total / duration,
                        (double)kt_total / duration,
                        (double)(total - kt_total) / duration);
-               if ((opt_flags & OPT_SHOW_WHENCE) && !curses_init) {
+               if ((g_opt_flags & OPT_SHOW_WHENCE) && !g_curses_init) {
                        time_t t = (time_t)whence;
                        char *timestr = ctime(&t);
                        char *pos = strchr(timestr, '\n');
@@ -1370,7 +1376,7 @@
                                "%.1f secs\n", timestr, time_delta);
                }
 
-               if (!sane_procs)
+               if (!g_sane_procs)
                        es_printf("Note: this was run inside a container, "
                                "kernel tasks were guessed.\n");
                es_printf("\n");
@@ -1390,19 +1396,19 @@
        static size_t get_events_size;
        size_t size;
 
-       if (get_events_buf == NULL) {
-               if ((get_events_buf = malloc(EVENT_BUF_SIZE << 1)) == NULL)
+       if (UNLIKELY(g_get_events_buf == NULL)) {
+               if ((g_get_events_buf = malloc(EVENT_BUF_SIZE << 1)) == NULL)
                        err_abort("Cannot read %s, out of memory\n",
-                               sys_tracing_pipe);
+                               g_sys_tracing_pipe);
 
                get_events_size = (EVENT_BUF_SIZE << 1);
        }
 
-       if ((fd = open(sys_tracing_pipe, O_RDONLY)) < 0)
-               err_abort("Cannot open %s\n", sys_tracing_pipe);
+       if ((fd = open(g_sys_tracing_pipe, O_RDONLY)) < 0)
+               err_abort("Cannot open %s\n", g_sys_tracing_pipe);
 
        size = 0;
-       while (!stop_eventstat) {
+       while (!g_stop_eventstat) {
                ssize_t ret;
                int rc;
                static char buffer[EVENT_BUF_SIZE];
@@ -1427,7 +1433,7 @@
                if (ret == 0)
                        continue;
                if (ret < 0) {
-                       if (!stop_eventstat &&
+                       if (!g_stop_eventstat &&
                            ((errno == EINTR) ||
                             (errno != EAGAIN))) {
                                continue;
@@ -1439,21 +1445,21 @@
                        char *tmpptr;
 
                        get_events_size += (EVENT_BUF_SIZE << 1);
-                       tmpptr = realloc(get_events_buf, get_events_size + 1);
+                       tmpptr = realloc(g_get_events_buf, get_events_size + 1);
                        if (!tmpptr) {
                                (void)close(fd);
                                err_abort("Cannot read %s, out of memory\n",
-                                       sys_tracing_pipe);
+                                       g_sys_tracing_pipe);
                        }
-                       get_events_buf = tmpptr;
+                       g_get_events_buf = tmpptr;
                }
-               memcpy(get_events_buf + size, buffer, ret);
+               (void)memcpy(g_get_events_buf + size, buffer, ret);
                size += ret;
-               *(get_events_buf + size) = '\0';
+               *(g_get_events_buf + size) = '\0';
        }
        (void)close(fd);
 
-       return get_events_buf;
+       return g_get_events_buf;
 }
 
 /*
@@ -1466,7 +1472,7 @@
        const double time_now,
        const double duration)
 {
-       const size_t app_name_len = strlen(app_name);
+       const size_t app_name_len = strlen(g_app_name);
        const double time_end = time_now + duration - 0.05;
        char *tmpptr = read_events(time_end);
 
@@ -1484,7 +1490,7 @@
 
                /* Find the end of a line */
                while (*eol) {
-                       if (*eol == '\n') {
+                       if (UNLIKELY(*eol == '\n')) {
                                *eol = '\0';
                                eol++;
                                break;
@@ -1492,9 +1498,9 @@
                        eol++;
                }
                if (strstr(tmpptr, "hrtimer_start")) {
-                       memset(&info, 0, sizeof(info));
-                       memset(task, 0, sizeof(task));
-                       memset(func, 0, sizeof(func));
+                       (void)memset(&info, 0, sizeof(info));
+                       (void)memset(task, 0, sizeof(task));
+                       (void)memset(func, 0, sizeof(func));
 
                        /*
                         *  Parse something like the following:
@@ -1522,7 +1528,7 @@
 
                if (sscanf(ptr, "%10d\n", &info.pid) != 1)
                        goto next;
-               if (info.pid == 0)
+               if (UNLIKELY(info.pid == 0))
                        goto next;
 
                /* Processes without a command line are kernel threads */
@@ -1534,21 +1540,21 @@
                        info.kernel_thread = true;
 
                mask = info.kernel_thread ? OPT_KERNEL : OPT_USER;
-               if (!(opt_flags & mask))
+               if (!(g_opt_flags & mask))
                        goto free_next;
 
                if (info.kernel_thread) {
                        char tmp[sizeof(task)];
 
-                       strcpy(tmp, task);
+                       (void)strcpy(tmp, task);
                        tmp[13] = '\0';
-                       snprintf(task_mangled, sizeof(task_mangled),
+                       (void)snprintf(task_mangled, sizeof(task_mangled),
                                "[%s]", tmp);
                } else {
-                       strcpy(task_mangled, task);
+                       (void)strcpy(task_mangled, task);
                }
 
-               if (strncmp(task, app_name, app_name_len)) {
+               if (strncmp(task, g_app_name, app_name_len)) {
                        info.task = task;
                        info.cmdline = cmdline ? cmdline : task_mangled;
                        info.task_mangled = task_mangled;
@@ -1571,9 +1577,9 @@
  */
 static void show_usage(void)
 {
-       printf("%s, version %s\n\n", app_name, VERSION);
-       printf("Usage: %s [options] [duration] [count]\n", app_name);
-       printf("Options are:\n"
+       (void)printf("%s, version %s\n\n", g_app_name, VERSION);
+       (void)printf("Usage: %s [options] [duration] [count]\n", g_app_name);
+       (void)printf("Options are:\n"
                "  -c\t\treport cumulative events rather than events per 
second.\n"
                "  -C\t\treport event count rather than event per second in CSV 
output.\n"
                "  -d\t\tremove pathname from long process name in CSV 
output.\n"
@@ -1601,7 +1607,7 @@
 
        eventstat_winsize();
 
-       resized = true;
+       g_resized = true;
 }
 
 int main(int argc, char **argv)
@@ -1613,7 +1619,7 @@
        bool forever = true;
        bool redo = false;
        struct sigaction new_action;
-       int i;
+       size_t i;
 
        for (;;) {
                int c = getopt(argc, argv, "bcCdksSlhin:qr:t:Tuw");
@@ -1621,22 +1627,22 @@
                        break;
                switch (c) {
                case 'b':
-                       opt_flags |= OPT_BRIEF;
+                       g_opt_flags |= OPT_BRIEF;
                        break;
                case 'c':
-                       opt_flags |= OPT_CUMULATIVE;
+                       g_opt_flags |= OPT_CUMULATIVE;
                        break;
                case 'C':
-                       opt_flags |= OPT_SAMPLE_COUNT;
+                       g_opt_flags |= OPT_SAMPLE_COUNT;
                        break;
                case 'd':
-                       opt_flags |= OPT_DIRNAME_STRIP;
+                       g_opt_flags |= OPT_DIRNAME_STRIP;
                        break;
                case 'h':
                        show_usage();
                        eventstat_exit(EXIT_SUCCESS);
                case 'i':
-                       opt_flags |= OPT_TIMER_ID;
+                       g_opt_flags |= OPT_TIMER_ID;
                        break;
                case 'n':
                        errno = 0;
@@ -1648,36 +1654,36 @@
                                err_abort("-n option must be greater than 0\n");
                        break;
                case 'S':
-                       opt_flags |= OPT_RESULT_STATS;
+                       g_opt_flags |= OPT_RESULT_STATS;
                        break;
                case 't':
-                       opt_threshold = strtoull(optarg, NULL, 10);
-                       if (opt_threshold < 1)
+                       g_opt_threshold = strtoull(optarg, NULL, 10);
+                       if (g_opt_threshold < 1)
                                err_abort("-t threshold must be 1 or more.\n");
                        break;
                case 'T':
-                       opt_flags |= OPT_TOP;
+                       g_opt_flags |= OPT_TOP;
                        break;
                case 'q':
-                       opt_flags |= OPT_QUIET;
+                       g_opt_flags |= OPT_QUIET;
                        break;
                case 'r':
-                       csv_results = optarg;
+                       g_csv_results = optarg;
                        break;
                case 's':
-                       opt_flags |= OPT_CMD_SHORT;
+                       g_opt_flags |= OPT_CMD_SHORT;
                        break;
                case 'l':
-                       opt_flags |= OPT_CMD_LONG;
+                       g_opt_flags |= OPT_CMD_LONG;
                        break;
                case 'k':
-                       opt_flags |= OPT_KERNEL;
+                       g_opt_flags |= OPT_KERNEL;
                        break;
                case 'u':
-                       opt_flags |= OPT_USER;
+                       g_opt_flags |= OPT_USER;
                        break;
                case 'w':
-                       opt_flags |= OPT_SHOW_WHENCE;
+                       g_opt_flags |= OPT_SHOW_WHENCE;
                        break;
                default:
                        show_usage();
@@ -1685,8 +1691,8 @@
                }
        }
 
-       if (!(opt_flags & (OPT_KERNEL | OPT_USER)))
-               opt_flags |= (OPT_KERNEL | OPT_USER);
+       if (!(g_opt_flags & (OPT_KERNEL | OPT_USER)))
+               g_opt_flags |= (OPT_KERNEL | OPT_USER);
 
        if (optind < argc) {
                duration_secs = atof(argv[optind++]);
@@ -1704,28 +1710,28 @@
                        err_abort("Count must be > 0\n");
        }
 
-       opt_threshold *= duration_secs;
+       g_opt_threshold *= duration_secs;
 
        if (geteuid() != 0)
                err_abort("%s requires root privileges to gather "
-                       "trace event data\n", app_name);
+                       "trace event data\n", g_app_name);
 
-       sane_procs = sane_proc_pid_info();
-       if (!sane_procs)
-               opt_flags &= ~(OPT_CMD_SHORT | OPT_CMD_LONG);
+       g_sane_procs = sane_proc_pid_info();
+       if (!g_sane_procs)
+               g_opt_flags &= ~(OPT_CMD_SHORT | OPT_CMD_LONG);
 
-       memset(&new_action, 0, sizeof(new_action));
-       for (i = 0; signals[i] != -1; i++) {
+       (void)memset(&new_action, 0, sizeof(new_action));
+       for (i = 0; i < SIZEOF_ARRAY(g_signals); i++) {
                new_action.sa_handler = handle_sig;
-               sigemptyset(&new_action.sa_mask);
+               (void)sigemptyset(&new_action.sa_mask);
                new_action.sa_flags = 0;
 
-               if (sigaction(signals[i], &new_action, NULL) < 0)
+               if (sigaction(g_signals[i], &new_action, NULL) < 0)
                        err_abort("sigaction failed: errno=%d (%s)\n",
                                errno, strerror(errno));
        }
 
-       if ((timer_stats = calloc(TABLE_SIZE, sizeof(timer_stat_t*))) == NULL)
+       if ((timer_stats = calloc(TABLE_SIZE, sizeof(*timer_stats))) == NULL)
                err_abort("Cannot allocate timer stats table\n");
 
        /* Should really catch signals and set back to zero before we die */
@@ -1734,10 +1740,10 @@
 
        time_now = time_start = gettime_to_double();
 
-       if (opt_flags & OPT_TOP) {
+       if (g_opt_flags & OPT_TOP) {
                struct sigaction sa;
 
-               memset(&sa, 0, sizeof(sa));
+               (void)memset(&sa, 0, sizeof(sa));
                sa.sa_handler = handle_sigwinch;
                if (sigaction(SIGWINCH, &sa, NULL) < 0)
                        err_abort("sigaction failed: errno=%d (%s)\n",
@@ -1748,10 +1754,10 @@
                nodelay(stdscr, 1);
                keypad(stdscr, 1);
                curs_set(0);
-               curses_init = true;
+               g_curses_init = true;
        }
 
-       while (!stop_eventstat && (forever || count--)) {
+       while (!g_stop_eventstat && (forever || count--)) {
                double secs, duration, time_delta;
 
                /* Timeout to wait for in the future for this sample */
@@ -1770,12 +1776,12 @@
 
                redo = false;
 
-               if (curses_init) {
+               if (g_curses_init) {
                        fd_set rfds;
                        int ch, ret;
                        struct timeval tv;
 
-                       memset(&tv, 0, sizeof(tv));
+                       (void)memset(&tv, 0, sizeof(tv));
 
                        FD_ZERO(&rfds);
                        FD_SET(fileno(stdin), &rfds);
@@ -1790,7 +1796,7 @@
                                if (errno != EINTR) {
                                        eventstat_endwin();
 
-                                       fprintf(stderr, "select() failed: "
+                                       (void)fprintf(stderr, "select() failed: 
"
                                                "errno=%d (%s)\n",
                                                errno, strerror(errno));
                                        goto abort;
@@ -1814,14 +1820,14 @@
        }
        eventstat_endwin();
 abort:
-       samples_dump(csv_results);
+       samples_dump(g_csv_results);
 
        timer_stat_free_contents(timer_stats);
        free(timer_stats);
        samples_free();
        timer_info_list_free();
        timer_stat_free_list_free();
-       free(get_events_buf);
+       free(g_get_events_buf);
 
        eventstat_exit(EXIT_SUCCESS);
 }


Reply via email to