Hello community,

here is the log from the commit of package cpustat for openSUSE:Factory checked 
in at 2020-09-12 00:12:07
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/cpustat (Old)
 and      /work/SRC/openSUSE:Factory/.cpustat.new.4249 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "cpustat"

Sat Sep 12 00:12:07 2020 rev:8 rq:833738 version:0.02.12

Changes:
--------
--- /work/SRC/openSUSE:Factory/cpustat/cpustat.changes  2020-03-08 
22:24:23.276086737 +0100
+++ /work/SRC/openSUSE:Factory/.cpustat.new.4249/cpustat.changes        
2020-09-12 00:13:02.433244453 +0200
@@ -1,0 +2,8 @@
+Thu Sep 10 18:50:58 UTC 2020 - Martin Hauke <[email protected]>
+
+- Update to version 0.02.12
+  * cpustat: fix truncated output, allow CPU % stats > 100%
+- Update to version 0.02.11
+  * cpustat: zero ws struct to clear static analysis warnings
+
+-------------------------------------------------------------------

Old:
----
  cpustat-0.02.10.tar.xz

New:
----
  cpustat-0.02.12.tar.xz

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

Other differences:
------------------
++++++ cpustat.spec ++++++
--- /var/tmp/diff_new_pack.QGuLyI/_old  2020-09-12 00:13:04.221246164 +0200
+++ /var/tmp/diff_new_pack.QGuLyI/_new  2020-09-12 00:13:04.225246168 +0200
@@ -18,7 +18,7 @@
 
 
 Name:           cpustat
-Version:        0.02.10
+Version:        0.02.12
 Release:        0
 Summary:        Periodic cpu utilization statistics
 License:        GPL-2.0-or-later

++++++ cpustat-0.02.10.tar.xz -> cpustat-0.02.12.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cpustat-0.02.10/Makefile new/cpustat-0.02.12/Makefile
--- old/cpustat-0.02.10/Makefile        2020-02-24 00:30:57.000000000 +0100
+++ new/cpustat-0.02.12/Makefile        2020-09-10 14:15:01.000000000 +0200
@@ -18,7 +18,7 @@
 # Author: Colin Ian King <[email protected]>
 #
 
-VERSION=0.02.10
+VERSION=0.02.12
 
 CFLAGS += -Wall -Wextra -DVERSION='"$(VERSION)"' -O2
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cpustat-0.02.10/cpustat.c 
new/cpustat-0.02.12/cpustat.c
--- old/cpustat-0.02.10/cpustat.c       2020-02-24 00:30:57.000000000 +0100
+++ new/cpustat-0.02.12/cpustat.c       2020-09-10 14:15:01.000000000 +0200
@@ -315,6 +315,11 @@
        -1,
 };
 
+static inline int intmax(const int a, const int b)
+{
+       return (a > b) ? a : b;
+}
+
 /*
  *  get_pid_max_digits()
  *     determine (or guess) maximum digits of pids
@@ -428,23 +433,26 @@
 
 /*
  *  putdouble()
- *     put a double in %6.2 with trailing space
+ *     put a double in %n.2 with trailing space, where n = width
  */
 static int OPTIMIZE3 HOT putdouble(
        char *str,
        const double val,
-       const int base)
+       const int base,
+       const int width)
 {
        const double v = val + 0.005; /* Round up */
+       int n = width - 3;
+
+       if (n < 1)
+               n = 1;
 
-       (void)putint(str, 3, (int)v, false);
-       str[3] = '.';
-       (void)putint(str + 4, 2, v * (double)base - (double)((int)v * base), 
true);
-       str[2] = (str[2] == ' ') ? '0' : str[2];
-       str[6] = ' ';
-       str[7] = '\0';
+       (void)putint(str, n, (int)v, false);
+       str[n] = '.';
+       (void)putint(str + n + 1, 2, v * (double)base - (double)((int)v * 
base), true);
+       str[width + 1] = '\0';
 
-       return 6;
+       return width;
 }
 
 /*
@@ -515,6 +523,7 @@
        if (redo) {
                struct winsize ws;
 
+               (void)memset(&ws, 0, sizeof(ws));
                if (LIKELY(ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)) {
                        rows = ws.ws_row;
                        cols = ws.ws_col;
@@ -724,7 +733,7 @@
        }
        s /= second_scales[i].scale;
 
-       (void)putdouble(buf, s, second_scales[i].base);
+       (void)putdouble(buf, s, second_scales[i].base, 6);
        buf[6] = second_scales[i].ch;
 
        return buf;
@@ -1055,25 +1064,33 @@
  *  info_banner_dump()
  *     dump banner for per_info stats
  */
-static void info_banner_dump(const double time_now)
+static void info_banner_dump(
+       const double time_now,
+       int umax_w,
+       int smax_w,
+       int usmax_w)
 {
        static char str[256];
-       static char *hdrptr;
-       char *ptr;
-
-       if (!hdrptr) {
-               int i;
-
-               hdrptr = str;
-               (void)strncpy(hdrptr, "  %CPU   %USR   %SYS   ", sizeof(str));
-               hdrptr += 23;
-               for (i = 0; i < pid_max_digits - 5; i++, hdrptr++)
-                       *hdrptr = ' ';
-               (void)strncpy(hdrptr, "PID S  CPU    Time Task",
-                       sizeof(str) - (3 + pid_max_digits));
-               hdrptr += 23;
-       }
-       ptr = hdrptr;
+       char *ptr = str;
+       int i;
+       char tmp[256];
+       size_t n, sz = sizeof(str);
+
+       snprintf(tmp, sizeof(tmp), "%*s %*s %*s ",
+               usmax_w, "%CPU",
+               umax_w, "%USR",
+               smax_w, "%SYS");
+       n = strlen(tmp);
+
+       (void)strncpy(ptr, tmp, sizeof(str));
+       ptr += n;
+       sz -= n;
+       for (i = 0; i < pid_max_digits - 3; i++, ptr++)
+               *ptr = ' ';
+       sz -= i;
+       (void)strncpy(ptr, "PID S  CPU    Time Task", sz);
+       ptr += 23;
+       sz -= 23;
 
        if (UNLIKELY(opt_flags & OPT_TIMESTAMP)) {
                struct tm tm;
@@ -1105,7 +1122,10 @@
        const uint64_t total_ticks,
        const cpu_info_t *info,
        double *const u_total,
-       double *const s_total)
+       double *const s_total,
+       int umax_w,
+       int smax_w,
+       int usmax_w)
 {
        char buffer[512], *ptr = buffer;
 
@@ -1118,11 +1138,11 @@
        *u_total += cpu_u_usage;
        *s_total += cpu_s_usage;
 
-       ptr += putdouble(ptr, cpu_u_usage + cpu_s_usage, 100);
+       ptr += putdouble(ptr, cpu_u_usage + cpu_s_usage, 100, usmax_w);
        *(ptr++) = ' ';
-       ptr += putdouble(ptr, cpu_u_usage, 100);
+       ptr += putdouble(ptr, cpu_u_usage, 100, umax_w);
        *(ptr++) = ' ';
-       ptr += putdouble(ptr, cpu_s_usage, 100);
+       ptr += putdouble(ptr, cpu_s_usage, 100, smax_w);
        *(ptr++) = ' ';
        ptr += putint(ptr, pid_max_digits, info->pid, false);
        *(ptr++) = ' ';
@@ -1153,11 +1173,11 @@
        if (UNLIKELY(opt_flags & OPT_TOTAL)) {
                char buffer[256], *ptr = buffer;
 
-               ptr += putdouble(ptr, u_total + s_total, 100);
+               ptr += putdouble(ptr, u_total + s_total, 100, 6);
                *(ptr++) = ' ';
-               ptr += putdouble(ptr, u_total, 100);
+               ptr += putdouble(ptr, u_total, 100, 6);
                *(ptr++) = ' ';
-               ptr += putdouble(ptr, s_total, 100);
+               ptr += putdouble(ptr, s_total, 100, 6);
                *(ptr++) = ' ';
                ptr += putstr(ptr, 5, "Total");
                df.df_putstrnl(buffer, ptr - buffer);
@@ -1165,6 +1185,23 @@
 }
 
 /*
+ *  n_digits
+ *     compute width of a floating point value
+ *     that has 2 decimals of precision. Minimum is
+ *     with is 6 chars (e.g. "  0.00" to "100.00").
+ *     value is divided by ticks
+ */
+static int digits_w(double value, uint64_t ticks)
+{
+       int w;
+
+       value = (ticks == 0) ? 0.0 : value / ticks;
+       w = value < 1.0 ? 1 : (int)log10(value);
+       w += 4;
+       return w < 6 ? 6 : w;
+}
+
+/*
  *  samples_dump()
  *     dump out samples to file
  */
@@ -1182,6 +1219,8 @@
        size_t i = 0, n;
        FILE *fp;
        double first_time = -1.0;
+       double umax = 0.0, smax = 0.0, usmax = 0.0;
+       static int umax_w, smax_w, usmax_w;
 
        if (UNLIKELY((sorted_cpu_infos =
             calloc(cpu_info_list_length, sizeof(*sorted_cpu_infos))) == NULL)) 
{
@@ -1199,17 +1238,34 @@
 
        qsort(sorted_cpu_infos, n, sizeof(cpu_info_t *), info_compare_total);
 
+       for (i = 0; i < n; i++) {
+               const double utotal = (double)sorted_cpu_infos[i]->utotal;
+               const double stotal = (double)sorted_cpu_infos[i]->stotal;
+               const double ustotal = utotal + stotal;
+
+               if (utotal > umax)
+                       umax = utotal;
+               if (stotal > smax)
+                       umax = stotal;
+               if (ustotal > usmax)
+                       usmax = ustotal;
+       }
+       umax_w = intmax(digits_w(umax, total_ticks), umax_w);
+       smax_w = intmax(digits_w(smax, total_ticks), smax_w);
+       usmax_w = intmax(digits_w(usmax, total_ticks), usmax_w);
+
        if (opt_flags & OPT_GRAND_TOTAL) {
                double cpu_u_total = 0.0, cpu_s_total = 0.0;
 
                (void)printf("Grand Total (from %" PRIu32 " samples, %.1f 
seconds):\n",
                        samples, duration);
-               info_banner_dump(time_now);
+               info_banner_dump(time_now, umax_w, smax_w, usmax_w);
                for (i = 0; i < n; i++) {
                        info_dump(sorted_cpu_infos[i]->utotal,
                                sorted_cpu_infos[i]->stotal,
                                total_ticks, sorted_cpu_infos[i],
-                               &cpu_u_total, &cpu_s_total);
+                               &cpu_u_total, &cpu_s_total,
+                               umax_w, smax_w, usmax_w);
                }
                info_total_dump(cpu_u_total, cpu_s_total);
                (void)putchar('\n');
@@ -1663,8 +1719,27 @@
        if (!(opt_flags & OPT_QUIET)) {
                int32_t j = 0;
                double cpu_u_total = 0.0, cpu_s_total = 0.0;
+               cpu_stat_t *s;
+               double umax = 0.0, smax = 0.0, usmax = 0.0;
+               static int umax_w, smax_w, usmax_w;
+
+               for (s = sorted; s; s = s->next) {
+                       const double utotal = (double)s->udelta;
+                       const double stotal = (double)s->sdelta;
+                       const double ustotal = utotal + stotal;
+
+                       if (utotal > umax)
+                               umax = utotal;
+                       if (stotal > smax)
+                               smax = stotal;
+                       if (ustotal > usmax)
+                               usmax = ustotal;
+               }
+               umax_w = intmax(digits_w(100.0 * umax, nr_ticks), umax_w);
+               smax_w = intmax(digits_w(100.0 * smax, nr_ticks), smax_w);
+               usmax_w = intmax(digits_w(100.0 * usmax, nr_ticks), usmax_w);
 
-               info_banner_dump(time_now);
+               info_banner_dump(time_now, umax_w, smax_w, usmax_w);
                while (sorted) {
                        double cpu_u_usage =
                                100.0 * (double)sorted->udelta /
@@ -1679,7 +1754,8 @@
                                if (cpu_t_usage > 0.0)
                                        info_dump(sorted->udelta, 
sorted->sdelta,
                                                nr_ticks, sorted->info,
-                                               &cpu_u_total, &cpu_s_total);
+                                               &cpu_u_total, &cpu_s_total,
+                                               umax_w, smax_w, usmax_w);
                        }
                        sorted = sorted->sorted_usage_next;
                }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cpustat-0.02.10/snap/snapcraft.yaml 
new/cpustat-0.02.12/snap/snapcraft.yaml
--- old/cpustat-0.02.10/snap/snapcraft.yaml     2020-02-24 00:30:57.000000000 
+0100
+++ new/cpustat-0.02.12/snap/snapcraft.yaml     2020-09-10 14:15:01.000000000 
+0200
@@ -1,15 +1,30 @@
 name: cpustat
-version: git
-version-script: |
-    echo $(git describe --tags)
 summary: periodic cpu utilization statistics
 description: cpustat periodically reports the current CPU utilization of 
running tasks and can optionally report per CPU and per task utilization 
statistics at the end of a run.  cpustat has been designed and optimized to use 
a minimal amount of CPU cycles to monitor a system hence it is a light weight 
alternative to traditional process monitoring tools such as top.
 confinement: strict
+assumes: [snapd2.45]
+base: core18
+adopt-info: cpustat
 
 parts:
     cpustat:
         plugin: make
         source: git://kernel.ubuntu.com/cking/cpustat
+        override-pull: |
+            snapcraftctl pull
+            description="$(git describe HEAD --tags)"
+            sha=$(echo $description | tr '-' ' ' | awk '{print $NF}')
+            version=${description%$sha}
+            commits=$(git log --oneline | wc -l)
+            date=$(date +'%Y%m%d')
+            if test "$description" = "$sha"
+            then
+                version="$description"
+            else
+                version=$(echo $version$date-$commits-$sha | cut -c1-32)
+            fi
+            snapcraftctl set-version "$version"
+
         build-packages:
             - gcc
             - make


Reply via email to