]> Savannah Git Hosting - gnulib.git/commitdiff
timevar: improve the output format
authorAkim Demaille <akim.demaille@gmail.com>
Thu, 11 Oct 2018 20:15:36 +0000 (22:15 +0200)
committerAkim Demaille <akim.demaille@gmail.com>
Sat, 13 Oct 2018 04:49:23 +0000 (06:49 +0200)
From:

    Execution times (seconds)
     reader                :   0,01 ( 3%) usr   0,00 (16%) sys   0,00 ( 0%) wall
     outputting report     :   0,03 ( 6%) usr   0,00 (15%) sys   0,00 ( 0%) wall
     parser action tables  :   0,02 ( 4%) usr   0,00 ( 2%) sys   0,00 ( 0%) wall
     outputting parser     :   0,01 ( 2%) usr   0,00 (13%) sys   0,00 ( 0%) wall
     running m4            :   0,37 (84%) usr   0,00 (50%) sys   0,00 ( 0%) wall
     total time            :   0,44             0,01             0,00

To:

    Execution times (seconds)
                              CPU user      CPU system    wall clock
     reader                   0,020 ( 4%)   0,002 ( 9%)   0,000000 ( 0%)
     outputting report        0,029 ( 6%)   0,002 (11%)   0,000000 ( 0%)
     parser action tables     0,020 ( 4%)   0,001 ( 6%)   0,000000 ( 0%)
     outputting parser        0,014 ( 3%)   0,002 (10%)   0,000000 ( 0%)
     running m4               0,431 (83%)   0,012 (59%)   0,000000 ( 0%)
     total time               0,522         0,020         0,000000

Suggested by Bruno Haible.
See https://lists.gnu.org/archive/html/bug-gnulib/2018-10/msg00040.html.

* lib/timevar.c (timevar_print): Use %7.3f for usr/sys and %11.6f for
wall, since its resolution is much higher.

ChangeLog
lib/timevar.c

index 22695f8f44e36f9e6dde5ccee1417a7c19630702..97a521a7ecbcd3bd340caf1b955b5554fdf02ada 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-10-13  Akim Demaille  <akim@lrde.epita.fr>
+
+       timevar: improve the output format
+       Suggested by Bruno Haible.
+       See https://lists.gnu.org/archive/html/bug-gnulib/2018-10/msg00040.html.
+       * lib/timevar.c (timevar_print): Use %7.3f for usr/sys and %11.6f for
+       wall, since its resolution is much higher.
+
 2018-10-13  Akim Demaille  <akim@lrde.epita.fr>
 
        timevar: expect that getrusage is available.
index 469db9cb10babd96118545e3f8f5a543524accef..8b574e2777db2e45bb545c0d0413534dd865d971 100644 (file)
@@ -304,7 +304,10 @@ timevar_print (FILE *fp)
 
   struct timevar_time_def const* total = &timevars[tv_total].elapsed;
 
-  fputs (_("\nExecution times (seconds)\n"), fp);
+  fprintf (fp, "%-22s\n",
+           _("Execution times (seconds)"));
+  fprintf (fp, " %-22s   %-13s %-13s %-16s\n",
+           "", _("CPU user"), _("CPU system"), _("wall clock"));
   for (unsigned /* timevar_id_t */ id = 0; id < (unsigned) TIMEVAR_LAST; ++id)
     {
       struct timevar_def *tv = &timevars[(timevar_id_t) id];
@@ -327,20 +330,20 @@ timevar_print (FILE *fp)
         continue;
 
       /* The timing variable name.  */
-      fprintf (fp, " %-22s:", tv->name);
+      fprintf (fp, " %-22s", tv->name);
 
       /* Print user-mode time for this process.  */
-      fprintf (fp, "%7.2f (%2.0f%%) usr",
+      fprintf (fp, "%8.3f (%2.0f%%)",
                tv->elapsed.user,
                (total->user == 0 ? 0 : tv->elapsed.user / total->user) * 100);
 
       /* Print system-mode time for this process.  */
-      fprintf (fp, "%7.2f (%2.0f%%) sys",
+      fprintf (fp, "%8.3f (%2.0f%%)",
                tv->elapsed.sys,
                (total->sys == 0 ? 0 : tv->elapsed.sys / total->sys) * 100);
 
       /* Print wall clock time elapsed.  */
-      fprintf (fp, "%7.2f (%2.0f%%) wall",
+      fprintf (fp, "%11.6f (%2.0f%%)",
                tv->elapsed.wall,
                (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100);
 
@@ -348,8 +351,8 @@ timevar_print (FILE *fp)
     }
 
   /* Print total time.  */
-  fprintf (fp, " %-22s:", timevars[tv_total].name);
-  fprintf (fp, "%7.2f          ", total->user);
-  fprintf (fp, "%7.2f          ", total->sys);
-  fprintf (fp, "%7.2f\n", total->wall);
+  fprintf (fp, " %-22s", timevars[tv_total].name);
+  fprintf (fp, "%8.3f      ", total->user);
+  fprintf (fp, "%8.3f      ", total->sys);
+  fprintf (fp, "%11.6f\n", total->wall);
 }