Hello community,

here is the log from the commit of package eventstat for openSUSE:Factory 
checked in at 2018-07-12 09:19:37
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/eventstat (Old)
 and      /work/SRC/openSUSE:Factory/.eventstat.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "eventstat"

Thu Jul 12 09:19:37 2018 rev:6 rq:622036 version:0.04.04

Changes:
--------
--- /work/SRC/openSUSE:Factory/eventstat/eventstat.changes      2018-02-09 
15:53:32.246480297 +0100
+++ /work/SRC/openSUSE:Factory/.eventstat.new/eventstat.changes 2018-07-12 
09:21:31.226616196 +0200
@@ -1,0 +2,13 @@
+Thu Jun 14 06:17:28 UTC 2018 - mar...@gmx.de
+
+- Update to version 0.04.04
+  * Makefile: bump version
+  * debian/copyright: use secure url https:// etc
+  * debian/control: remove trailing empty line
+  * Fix -b brief mode headings
+  * Ensure we have at least 1 task accounted for
+  * Add CPU load, real time priority and niceness fields
+  * Add fast check if we are inside a container
+- Fix version number typos in changelog
+
+-------------------------------------------------------------------
@@ -4 +17 @@
-- Update to version 4.04.03
+- Update to version 0.04.03
@@ -14 +27 @@
-- Update to version 4.04.02
+- Update to version 0.04.02
@@ -29 +42 @@
-- Update to version 4.04.01
+- Update to version 0.04.01
@@ -45 +58 @@
-- Update to version 4.04.00
+- Update to version 0.04.00

Old:
----
  eventstat-0.04.03.tar.gz

New:
----
  eventstat-0.04.04.tar.gz

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

Other differences:
------------------
++++++ eventstat.spec ++++++
--- /var/tmp/diff_new_pack.5kkYgd/_old  2018-07-12 09:21:31.894617132 +0200
+++ /var/tmp/diff_new_pack.5kkYgd/_new  2018-07-12 09:21:31.898617136 +0200
@@ -18,10 +18,10 @@
 
 
 Name:           eventstat
-Version:        0.04.03
+Version:        0.04.04
 Release:        0
 Summary:        Kernel event states monitoring tool
-License:        GPL-2.0+
+License:        GPL-2.0-or-later
 Group:          System/Monitoring
 Url:            http://kernel.ubuntu.com/~cking/eventstat/
 Source:         
http://kernel.ubuntu.com/~cking/tarballs/%{name}/%{name}-%{version}.tar.gz

++++++ eventstat-0.04.03.tar.gz -> eventstat-0.04.04.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/eventstat-0.04.03/Makefile 
new/eventstat-0.04.04/Makefile
--- old/eventstat-0.04.03/Makefile      2018-02-01 11:09:48.000000000 +0100
+++ new/eventstat-0.04.04/Makefile      2018-06-13 17:33:43.000000000 +0200
@@ -16,7 +16,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.
 #
 
-VERSION=0.04.03
+VERSION=0.04.04
 
 CFLAGS += -Wall -Wextra -DVERSION='"$(VERSION)"' -O2
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/eventstat-0.04.03/eventstat.c 
new/eventstat-0.04.04/eventstat.c
--- old/eventstat-0.04.03/eventstat.c   2018-02-01 11:09:48.000000000 +0100
+++ new/eventstat-0.04.04/eventstat.c   2018-06-13 17:33:43.000000000 +0200
@@ -40,6 +40,7 @@
 #include <float.h>
 #include <ncurses.h>
 #include <ctype.h>
+#include <dirent.h>
 
 #define TABLE_SIZE             (1009)          /* Should be a prime */
 
@@ -121,10 +122,15 @@
        char            *func;          /* Kernel waiting func */
        char            *ident;         /* Unique identity */
        bool            kernel_thread;  /* True if task is a kernel thread */
+       uint16_t        cpu_rt_prio;    /* process priority level */
+       int16_t         cpu_nice;       /* process nice level */
        uint32_t        ref_count;      /* Timer stat reference count */
        uint64_t        timer;          /* Timer ID */
        uint64_t        total_events;   /* Total number of events */
        uint64_t        delta_events;   /* Events in one time period */
+       uint32_t        cpu_tasks;      /* Number of tasks sharing ticks */
+       uint64_t        cpu_ticks;      /* CPU utilization ticks */
+       double          cpu_ticks_time; /* CPU utilization ticks, last read */
        double          time_total;     /* Total time */
        double          last_used;      /* Last referenced */
        double          prev_used;      /* Previous time used */
@@ -195,6 +201,7 @@
 static bool g_curses_init;             /* curses initialised */
 static int g_rows = 25;                        /* tty size, rows */
 static int g_cols = 80;                        /* tty size, columns */
+static uint64_t clock_tick_rate;       /* system clock tick rate */
 
 /*
  *  Attempt to catch a range of signals so
@@ -484,6 +491,10 @@
        const char *ptr = pattern;
        bool ret = true;
 
+        /* Fast check */
+        if (access("/run/systemd/container", R_OK) == 0)
+               return false;
+
        fp = fopen("/proc/1/environ", "r");
        if (!fp)
                return false;
@@ -523,6 +534,135 @@
        set_tracing_enable("0\n", false);
 }
 
+static uint32_t get_proc_cpu_tasks(const pid_t pid)
+{
+       char path[PATH_MAX];
+       DIR *dir;
+       struct dirent *d;
+       uint32_t n = 0;
+
+       snprintf(path, sizeof(path), "/proc/%d/task", pid);
+       dir = opendir(path);
+
+       if (!dir)
+               return 1;
+
+       while ((d = readdir(dir)) != NULL) {
+               if (d->d_name[0] != '.')
+                       n++;
+       }
+
+       (void)closedir(dir);
+
+       /* We should always have at least 1 task! */
+       return (n < 1) ? 1 : n;
+}
+
+#define SKIP_FIELDS(n)                 \
+       skip = n;                       \
+       while (skip > 0 && *ptr) {      \
+               if (*ptr == ' ')        \
+                       skip--;         \
+               ptr++;                  \
+       }                               \
+       if (UNLIKELY(*ptr == '\0'))     \
+               return -1;              \
+
+/*
+ *  get_proc_cpu_ticks()
+ *     get cpu ticks for a given pid
+ *     unique tasks
+ */
+static int get_proc_cpu_ticks(
+       const pid_t pid,
+       uint64_t *ticks,
+       uint16_t *rt_prio,
+       int16_t *niceness)
+{
+       char buffer[4096], path[PATH_MAX], *ptr = buffer, *endptr;
+       int fd, skip;
+       uint64_t utime, stime;
+       ssize_t len;
+
+       snprintf(path, sizeof(path), "/proc/%d/stat", pid);
+
+       *ticks = 0;
+
+       if ((fd = open(path, O_RDONLY)) < 0)
+               return -1;
+
+       len = read(fd, buffer, sizeof(buffer) - 1);
+       (void)close(fd);
+       if (UNLIKELY(len <= 1))
+               return -1;
+
+       buffer[len] = '\0';
+
+       /* 3173 (a.out) R 3093 3173 3093 34818 3173 4202496 165 0 0 0 3194 0 */
+
+       /*
+        *  We used to use scanf but this is really expensive and it
+        *  is far faster to parse the data via a more tedious means
+        *  of scanning down the buffer manually..
+        */
+       if ((pid_t)strtoul(ptr, &endptr, 10) != pid)
+               return -1;
+
+       if (endptr == ptr)
+               return -1;
+
+       ptr = endptr;
+       if (UNLIKELY(*ptr != ' '))
+               return -1;
+       ptr++;
+       if (UNLIKELY((*ptr != '(')))
+               return -1;
+       ptr++;
+       /* parse comm field */
+       while ((*ptr != '\0') && (*ptr !=')'))
+               ptr++;
+       if (UNLIKELY(*ptr != ')'))
+               return -1;
+       ptr++;
+       if (UNLIKELY(*ptr != ' '))
+               return -1;
+       /* skip over state field */
+       ptr+=2 ;
+
+       /* Skip over fields to the 14th field (utime) */
+       SKIP_FIELDS(11)
+
+       /* Field 14, utime */
+       utime = strtoull(ptr, &endptr, 10);
+       if (UNLIKELY(endptr == ptr))
+               return -1;
+       ptr = endptr;
+       if (UNLIKELY(*ptr != ' '))
+               return -1;
+       ptr++;
+       /* Field 15, stime */
+       stime = strtoull(ptr, &endptr, 10);
+       if (UNLIKELY(endptr == ptr))
+               return -1;
+
+       /* Skip over fields to the 19th field (utime) */
+       SKIP_FIELDS(4)
+
+       /* Field 19, niceness */
+       *niceness = strtoul(ptr, &endptr, 10);
+       if (UNLIKELY(endptr == ptr))
+               return -1;
+
+       SKIP_FIELDS(21)
+       /* Field 40, rt_priority */
+       *rt_prio = strtol(ptr, &endptr, 10);
+       if (UNLIKELY(endptr == ptr))
+               return -1;
+
+       *ticks = utime + stime;
+       return 0;
+}
+
 /*
  *  samples_free()
  *     free collected samples
@@ -958,6 +1098,8 @@
        info->last_used = time_now;
        info->total_events = 1;
        info->delta_events = 1;
+       get_proc_cpu_ticks(info->pid, &info->cpu_ticks, &info->cpu_rt_prio, 
&info->cpu_nice);
+       info->cpu_ticks_time = time_now;
 
        if (UNLIKELY(info->task == NULL ||
                     info->task_mangled == NULL ||
@@ -1230,17 +1372,22 @@
 static void es_printf(const char *fmt, ...)
 {
        va_list ap;
+       static int col = 0;
+       int n;
+       char buf[256], *eol;
 
        va_start(ap, fmt);
-       if (g_curses_init) {
-               char buf[256];
+       n = vsnprintf(buf, sizeof(buf), fmt, ap);
+       va_end(ap);
+       eol = strchr(buf, '\n');
 
-               (void)vsnprintf(buf, sizeof(buf), fmt, ap);
-               (void)printw("%s", buf);
-       } else {
-               (void)vprintf(fmt, ap);
+       if (n + col >= g_cols) {
+               n = g_cols - col;
+               buf[n > 0 ? n : 0] = '\0';
        }
-       va_end(ap);
+
+       (void)(g_curses_init ? printw : printf)("%s", buf);
+       col = eol ? 0 : col + n;
 }
 
 /*
@@ -1255,6 +1402,7 @@
 {
        size_t i;
        timer_stat_t *sorted = NULL;
+       double now = gettime_to_double();
 
        for (i = 0; i < TABLE_SIZE; i++) {
                timer_stat_t *ts;
@@ -1280,7 +1428,7 @@
                /* Minimum width w/o task or func info */
                min_width = EVENTS_WIDTH + 1 + \
                            1 + \
-                           pid_size + 1;
+                           pid_size + 1 + 6 + 4 + 4;
                if (!(g_opt_flags & OPT_BRIEF)) {
                        if (g_opt_flags & OPT_TIMER_ID)
                                min_width += TIMER_ID_WIDTH + 1;
@@ -1308,21 +1456,29 @@
                if (ta_size < TASK_WIDTH)
                        ta_size = TASK_WIDTH;
 
-               es_printf("%*.*s %-*.*s %-*.*s",
-                       EVENTS_WIDTH, EVENTS_WIDTH,
-                       (g_opt_flags & OPT_CUMULATIVE) ?
-                               "Events" : "Event/s",
-                       pid_size, pid_size, "PID",
-                       ta_size, ta_size, "Task");
-               if (!(g_opt_flags & OPT_BRIEF)) {
+               if (g_opt_flags & OPT_BRIEF) {
+                       es_printf("%*.*s %-*.*s %-*.*s",
+                               EVENTS_WIDTH, EVENTS_WIDTH,
+                               (g_opt_flags & OPT_CUMULATIVE) ?
+                                       "Events" : "Event/s",
+                               pid_size, pid_size, "PID",
+                               ta_size, ta_size, "Task");
+               } else {
+                       es_printf("%*.*s %-*.*s %5s %3.3s %3.3s %-*.*s",
+                               EVENTS_WIDTH, EVENTS_WIDTH,
+                               (g_opt_flags & OPT_CUMULATIVE) ?
+                                       "Events" : "Event/s",
+                               pid_size, pid_size, "PID",
+                               "%CPU", "PR", "NI",
+                               ta_size, ta_size, "Task");
+
                        if (g_opt_flags & OPT_TIMER_ID) {
-                               es_printf(" %-16.16s", "Timer ID");
+                               es_printf(" %16.16s", "Timer ID");
                        }
-                       es_printf("%-*.*s\n", fn_size, fn_size,
+                       es_printf("%-*.*s", fn_size, fn_size,
                                " Init Function");
-               } else {
-                       es_printf("\n");
                }
+               es_printf("\n");
 
                while (sorted) {
                        if (((n_lines == -1) || (j < n_lines)) &&
@@ -1344,13 +1500,35 @@
                                                
(double)sorted->info->delta_events / duration);
 
                                if (g_opt_flags & OPT_BRIEF) {
-
                                        es_printf("%*d %s\n",
                                                pid_size, sorted->info->pid,
                                                task);
                                } else {
-                                       es_printf("%*d %-*.*s",
+                                       double tick_time = now - 
sorted->info->cpu_ticks_time;
+                                       uint32_t tasks = 
get_proc_cpu_tasks(sorted->info->pid);
+                                       uint64_t cpu_ticks;
+                                       uint64_t ticks;
+                                       uint16_t cpu_rt_prio;
+                                       int16_t cpu_nice;
+                                       double cpu;
+
+                                       get_proc_cpu_ticks(sorted->info->pid, 
&cpu_ticks,
+                                                          &cpu_rt_prio, 
&cpu_nice);
+
+                                       if (cpu_ticks && 
sorted->info->cpu_ticks) {
+                                               ticks = cpu_ticks - 
sorted->info->cpu_ticks;
+                                               cpu = (100.0 * (double)ticks) / 
(tick_time * (double)clock_tick_rate);
+                                       } else {
+                                               cpu = 0.0;
+                                       }
+                                       sorted->info->cpu_ticks = cpu_ticks;
+                                       sorted->info->cpu_ticks_time = now;
+
+                                       es_printf("%*d %5.1f %3d %3d %-*.*s",
                                                pid_size, sorted->info->pid,
+                                               cpu / (double)tasks,
+                                               sorted->info->cpu_rt_prio,
+                                               sorted->info->cpu_nice,
                                                ta_size, ta_size, task);
                                        if (g_opt_flags & OPT_TIMER_ID) {
                                                es_printf(" %16" PRIx64,
@@ -1433,8 +1611,11 @@
 
                errno = 0;
                rc = select(fd + 1, &rfds, NULL, NULL, &tv);
-               if (UNLIKELY(rc <= 0))
+               if (UNLIKELY(rc <= 0)) {
+                       if (errno == EINTR)
+                               continue;
                        break;
+               }
                if (!FD_ISSET(fd, &rfds))
                        continue;
                ret = read(fd, buffer, sizeof(buffer));
@@ -1746,6 +1927,7 @@
        set_tracing_enable("1\n", true);
        set_tracing_event();
 
+       clock_tick_rate = (uint64_t)sysconf(_SC_CLK_TCK);
        time_now = time_start = gettime_to_double();
 
        if (g_opt_flags & OPT_TOP) {


Reply via email to