Re: timevar: 3/3: use clock_gettime to get wall clock time

2018-10-11 Thread Akim Demaille
On macOS, I get an unexpected result for wall clock.

Execution times (seconds)
  CPU user  CPU systemwall clock  
 reader   0,017 ( 4%)   0,002 (13%)   0,00 ( 0%)
 LALR(1)  0,002 ( 0%)   0,000 ( 1%)   0,031250 ( 6%)
 outputting report0,027 ( 5%)   0,002 (13%)   0,031250 ( 6%)
 parser action tables 0,018 ( 4%)   0,001 ( 7%)   0,00 ( 0%)
 outputting parser0,012 ( 2%)   0,001 (10%)   0,062500 (12%)
 running m4   0,407 (84%)   0,008 (54%)   0,375000 (75%)
 total time   0,488 0,014 0,50

commit 48624ae07a9fa3c9d79a92b39e7ca31b4fb0c263
Author: Akim Demaille 
Date:   Fri Oct 12 06:46:09 2018 +0200

timevar: use clock_gettime to get wall clock time

* modules/timevar (Depends-on): We need time.h.
We no longer use times().
* lib/timevar.c (set_to_current_time): Use clock_gettime.

diff --git a/ChangeLog b/ChangeLog
index 369848b12..bb550a54b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-10-12  Akim Demaille  
+
+   timevar: use clock_gettime to get wall clock time
+   * modules/timevar (Depends-on): We need time.h.
+   We no longer use times().
+   * lib/timevar.c (set_to_current_time): Use clock_gettime.
+
 2018-10-12  Akim Demaille  
 
timevar: improve the output format
diff --git a/lib/timevar.c b/lib/timevar.c
index 8b574e277..13fa6bf75 100644
--- a/lib/timevar.c
+++ b/lib/timevar.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -108,6 +109,10 @@ set_to_current_time (struct timevar_time_def *now)
   getrusage (RUSAGE_CHILDREN, );
   now->user += rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
   now->sys  += rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
+
+  struct timespec timespec;
+  clock_gettime(CLOCK_MONOTONIC, );
+  now->wall = timespec.tv_sec + timespec.tv_nsec * 1e-9;
 }
 
 /* Return the current time.  */
diff --git a/modules/timevar b/modules/timevar
index 8be1b8318..d0712720b 100644
--- a/modules/timevar
+++ b/modules/timevar
@@ -12,7 +12,7 @@ gettext-h
 stdlib
 sys_time
 sys_times
-times
+time
 xalloc
 
 Makefile.am:




Re: timevar: 2/3: improve the output format

2018-10-11 Thread Akim Demaille
I have used the format you suggested to display the times.  I’m
not sure we should specify the resolution, it kinda of is displayed
by the figures themselves, but I’ll do whatever you suggest Bruno.
However, see 3/3 before.


commit 17bf1247ef4a64e6400df5206bbe570889ef252f
Author: Akim Demaille 
Date:   Thu Oct 11 22:15:36 2018 +0200

timevar: improve the output format

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 systemwall clock
 reader   0,020 ( 4%)   0,002 ( 9%)   0,00 ( 0%)
 outputting report0,029 ( 6%)   0,002 (11%)   0,00 ( 0%)
 parser action tables 0,020 ( 4%)   0,001 ( 6%)   0,00 ( 0%)
 outputting parser0,014 ( 3%)   0,002 (10%)   0,00 ( 0%)
 running m4   0,431 (83%)   0,012 (59%)   0,00 ( 0%)
 total time   0,522 0,020 0,00

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.

diff --git a/ChangeLog b/ChangeLog
index d93c7b6b0..369848b12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-10-12  Akim Demaille  
+
+   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-12  Akim Demaille  
 
timevar: expect that getrusage is available.
diff --git a/lib/timevar.c b/lib/timevar.c
index 469db9cb1..8b574e277 100644
--- a/lib/timevar.c
+++ b/lib/timevar.c
@@ -304,7 +304,10 @@ timevar_print (FILE *fp)
 
   struct timevar_time_def const* total = [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 = [(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);
 }




Re: timevar: 1/3: expect that getrusage is available

2018-10-11 Thread Akim Demaille
Waiting for approval before pushing.

commit 65b74a02c39450878ac1c41b870e1188c4a0429e
Author: Akim Demaille 
Date:   Thu Oct 11 17:54:35 2018 +0200

timevar: expect that getrusage is available

Don't keep both times and getrusage as backend: both are guaranteed by
gnulib, a single one suffices.  Using getrusage is open to possibly
tracking other types of resources in the future.

* modules/timevar (Depends-on): Add getrusage.
(configure.ac): Remove gl_TIMEVAR.
* m4/timevar.m4: Remove, rely on gnulib for getrusage.
* lib/timevar.h (timevar_enabled): Clarify documentation.
* lib/timevar.c: Remove all the code about times.
Remove all the CPP guards about getrusage: expect it to be present
(courtesy of gnulib).

diff --git a/ChangeLog b/ChangeLog
index cc617fa3f..d93c7b6b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2018-10-12  Akim Demaille  
+
+   timevar: expect that getrusage is available.
+   Don't keep both times and getrusage as backend: both are guaranteed by
+   gnulib, a single one suffices.  Using getrusage is open to possibly
+   tracking other types of resources in the future.
+   * modules/timevar (Depends-on): Add getrusage.
+   (configure.ac): Remove gl_TIMEVAR.
+   * m4/timevar.m4: Remove, rely on gnulib for getrusage.
+   * lib/timevar.h (timevar_enabled): Clarify documentation.
+   * lib/timevar.c: Remove all the code about times.
+   Remove all the CPP guards about getrusage: expect it to be present
+   (courtesy of gnulib).
+
 2018-10-11  Bruno Haible  
 
mountlist: Modernize platform lists.
diff --git a/lib/timevar.c b/lib/timevar.c
index 391802838..469db9cb1 100644
--- a/lib/timevar.c
+++ b/lib/timevar.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -33,50 +34,6 @@
 #define _(msgid) gettext (msgid)
 #include "xalloc.h"
 
-#ifdef HAVE_SYS_RESOURCE_H
-# include 
-#endif
-
-/* Calculation of scale factor to convert ticks to microseconds.
-   We mustn't use CLOCKS_PER_SEC except with clock().  */
-#if HAVE_SYSCONF && defined _SC_CLK_TCK
-# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */
-#elif defined CLK_TCK
-# define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */
-#elif defined HZ
-# define TICKS_PER_SECOND HZ  /* traditional UNIX */
-#else
-# define TICKS_PER_SECOND 100 /* often the correct value */
-#endif
-
-/* Prefer times to getrusage to clock (each gives successively less
-   information).  */
-#if defined HAVE_TIMES
-# define USE_TIMES
-# define HAVE_USER_TIME
-# define HAVE_SYS_TIME
-# define HAVE_WALL_TIME
-#elif defined HAVE_GETRUSAGE
-# define USE_GETRUSAGE
-# define HAVE_USER_TIME
-# define HAVE_SYS_TIME
-#endif
-
-#if defined USE_TIMES && !defined HAVE_DECL_TIMES
-clock_t times (struct tms *);
-#elif defined USE_GETRUSAGE && !defined HAVE_DECL_GETRUSAGE
-int getrusage (int, struct rusage *);
-#endif
-
-/* libc is very likely to have snuck a call to sysconf() into one of
-   the underlying constants, and that can be very slow, so we have to
-   precompute them.  Whose wonderful idea was it to make all those
-   _constants_ variable at run time, anyway?  */
-#ifdef USE_TIMES
-static float ticks_to_msec;
-# define TICKS_TO_MSEC (1.0 / TICKS_PER_SECOND)
-#endif
-
 /* See timevar.h for an explanation of timing variables.  */
 
 int timevar_enabled = 0;
@@ -132,9 +89,7 @@ static struct timevar_stack_def *unused_stack_instances;
element.  */
 static struct timevar_time_def start_time;
 
-/* Fill the current times into TIME.  The definition of this function
-   also defines any or all of the HAVE_USER_TIME, HAVE_SYS_TIME, and
-   HAVE_WALL_TIME macros.  */
+/* Fill the current times into TIME.  */
 
 static void
 set_to_current_time (struct timevar_time_def *now)
@@ -146,19 +101,13 @@ set_to_current_time (struct timevar_time_def *now)
   if (!timevar_enabled)
 return;
 
-  {
-#ifdef USE_TIMES
-struct tms tms;
-now->wall = times () * ticks_to_msec;
-now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec;
-now->sys  = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec;
-#elif defined USE_GETRUSAGE
-struct rusage rusage;
-getrusage (RUSAGE_CHILDREN, );
-now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
-now->sys  = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
-#endif
-  }
+  struct rusage rusage;
+  getrusage (RUSAGE_SELF, );
+  now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
+  now->sys  = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
+  getrusage (RUSAGE_CHILDREN, );
+  now->user += rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
+  now->sys  += rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
 }
 
 /* Return the current time.  */
@@ -197,10 +146,6 @@ timevar_init ()
   timevars[identifier__].name = name__;
 #include "timevar.def"
 #undef DEFTIMEVAR
-
-#if defined 

[bug #33724] Find command is changing the access time of directory

2018-10-11 Thread Bernhard Voelker
Update of bug #33724 (project findutils):

  Status:None => Wont Fix   
 Assigned to: jay => berny  
 Open/Closed:Open => Closed 

___

Follow-up Comment #4:

As discussed in [1] and [2], we can't properly ensure that O_NOATIME
works without surprises or side-effects on all systems and environments.

Consequently, we've removed the FTS_NOATIME option (which has never
been used) from gnulib.

Therefore, I'm hereby closing this issue as WONTFIX.

[1] https://lists.gnu.org/r/bug-findutils/2018-09/msg00052.html
[2] https://lists.gnu.org/r/bug-findutils/2018-10/msg0.html

___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




Re: windows platform test

2018-10-11 Thread Bruno Haible
Hi Assaf,

> Is there an agreed-upon #define for mingw/windows which is not cygwin?
> 
> I've seen
>#ifdef _WIN32 && ! defined CYGWIN

This is syntactically malformed and also tests the wrong symbols.
The correct test is
 #if defined _WIN32 && ! defined __CYGWIN__

> But it seems clumsy and error-prone.

https://lists.gnu.org/archive/html/bug-gnulib/2018-08/msg00147.html

> Basically, I'm looking for a way to know that one should '#include 
> ' and use windows api functions.

It depends on whether, for the specific feature/API, on Cygwin, you
prefer the "Cygwin way"
  - then use '#if defined _WIN32 && ! defined __CYGWIN__'
or the "native Windows way"
  - then use '#if defined _WIN32 || defined __CYGWIN__'

Bruno




Re: mountlist: platform comments

2018-10-11 Thread Assaf Gordon

Hello Bruno,

On 11/10/18 03:31 PM, Bruno Haible wrote:

The platform comments in mountlist.c and ls-mntd-fs.m4 are not very informative
any more. E.g. What is "BSD4.4" nowadays? Why is "Solaris" not mentioned?

Here's what I found by compiling a testdir on today's platforms and looking
for MOUNTED_ in config.h.

Linux MOUNTED_GETMNTENT1
GNU/kFreeBSD  MOUNTED_GETMNTENT1
Hurd  MOUNTED_GETMNTENT1
Mac OS X  MOUNTED_GETMNTINFO
FreeBSD 11MOUNTED_GETMNTINFO
NetBSD 7  MOUNTED_GETMNTINFO2
OpenBSD 6 MOUNTED_GETMNTINFO
Minix 3.3 None found!
AIX 7 MOUNTED_VMOUNT
HP-UX 11.31   MOUNTED_GETMNTENT1
IRIX 6.5  MOUNTED_GETMNTENT1
OSF/1 5.1 MOUNTED_GETFSSTAT   (inferred, not tested)
Solaris 10MOUNTED_GETMNTENT2
CygwinMOUNTED_GETMNTENT1
mingw None found!
Interix 3.5   MOUNTED_INTERIX_STATVFS (inferred, not tested)
Haiku MOUNTED_FS_STAT_DEV
Android   MOUNTED_GETMNTENT1  (inferred, not tested)



I'm going to send few more patches for mingw in the future (e.g. for 
fsusage.c).


Is there an agreed-upon #define for mingw/windows which is not cygwin?

I've seen
  #ifdef _WIN32 && ! defined CYGWIN
But it seems clumsy and error-prone.

Basically, I'm looking for a way to know that one should '#include 
' and use windows api functions.


Thanks!
 - assaf

PS.
Thanks for the careful review of mountlist.c, I'll send updates soon.











mountlist: platform comments

2018-10-11 Thread Bruno Haible
Hi,

The platform comments in mountlist.c and ls-mntd-fs.m4 are not very informative
any more. E.g. What is "BSD4.4" nowadays? Why is "Solaris" not mentioned?

Here's what I found by compiling a testdir on today's platforms and looking
for MOUNTED_ in config.h.

Linux MOUNTED_GETMNTENT1
GNU/kFreeBSD  MOUNTED_GETMNTENT1
Hurd  MOUNTED_GETMNTENT1
Mac OS X  MOUNTED_GETMNTINFO
FreeBSD 11MOUNTED_GETMNTINFO
NetBSD 7  MOUNTED_GETMNTINFO2
OpenBSD 6 MOUNTED_GETMNTINFO
Minix 3.3 None found!
AIX 7 MOUNTED_VMOUNT
HP-UX 11.31   MOUNTED_GETMNTENT1
IRIX 6.5  MOUNTED_GETMNTENT1
OSF/1 5.1 MOUNTED_GETFSSTAT   (inferred, not tested)
Solaris 10MOUNTED_GETMNTENT2
CygwinMOUNTED_GETMNTENT1
mingw None found!
Interix 3.5   MOUNTED_INTERIX_STATVFS (inferred, not tested)
Haiku MOUNTED_FS_STAT_DEV
Android   MOUNTED_GETMNTENT1  (inferred, not tested)


2018-10-11  Bruno Haible  

mountlist: Modernize platform lists.
* m4/ls-mntd-fs.m4: Clarify which MOUNTED_* symbol applies to which
platforms, deemphasizing the obsolete ones.
* lib/mountlist.c: Likewise.

diff --git a/lib/mountlist.c b/lib/mountlist.c
index b691f38..79a584e 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -43,7 +43,7 @@
 # include 
 #endif
 
-#if defined MOUNTED_GETFSSTAT   /* OSF_1 and Darwin1.3.x */
+#if defined MOUNTED_GETFSSTAT   /* OSF/1, also (obsolete) Apple Darwin 1.3 */
 # if HAVE_SYS_UCRED_H
 #  include  /* needed on OSF V4.0 for definition of NGROUPS,
   NGROUPS is used as an array dimension in ucred.h */
@@ -62,7 +62,8 @@
 # endif
 #endif /* MOUNTED_GETFSSTAT */
 
-#ifdef MOUNTED_GETMNTENT1   /* 4.3BSD, SunOS, HP-UX, Dynix, Irix.  */
+#ifdef MOUNTED_GETMNTENT1   /* glibc, HP-UX, IRIX, Cygwin, Android,
+   also (obsolete) 4.3BSD, SunOS, Dynix */
 # include 
 # include 
 # if !defined MOUNTED
@@ -78,48 +79,48 @@
 # endif
 #endif
 
-#ifdef MOUNTED_GETMNTINFO   /* 4.4BSD.  */
+#ifdef MOUNTED_GETMNTINFO   /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 
4.4BSD */
 # include 
 #endif
 
-#ifdef MOUNTED_GETMNTINFO2  /* NetBSD 3.0.  */
+#ifdef MOUNTED_GETMNTINFO2  /* NetBSD */
 # include 
 #endif
 
-#ifdef MOUNTED_GETMNT   /* Ultrix.  */
+#ifdef MOUNTED_GETMNT   /* (obsolete) Ultrix */
 # include 
 # include 
 #endif
 
-#ifdef MOUNTED_FS_STAT_DEV  /* BeOS.  */
+#ifdef MOUNTED_FS_STAT_DEV  /* Haiku, also (obsolete) BeOS */
 # include 
 # include 
 #endif
 
-#ifdef MOUNTED_FREAD/* SVR2.  */
+#ifdef MOUNTED_FREAD/* (obsolete) SVR2 */
 # include 
 #endif
 
-#ifdef MOUNTED_FREAD_FSTYP  /* SVR3.  */
+#ifdef MOUNTED_FREAD_FSTYP  /* (obsolete) SVR3 */
 # include 
 # include 
 # include 
 #endif
 
-#ifdef MOUNTED_LISTMNTENT
+#ifdef MOUNTED_LISTMNTENT   /* (obsolete) Cray UNICOS 9 */
 # include 
 #endif
 
-#ifdef MOUNTED_GETMNTENT2   /* SVR4.  */
+#ifdef MOUNTED_GETMNTENT2   /* Solaris, also (obsolete) SVR4 */
 # include 
 #endif
 
-#ifdef MOUNTED_VMOUNT   /* AIX.  */
+#ifdef MOUNTED_VMOUNT   /* AIX */
 # include 
 # include 
 #endif
 
-#ifdef MOUNTED_INTERIX_STATVFS  /* Interix. */
+#ifdef MOUNTED_INTERIX_STATVFS  /* Interix */
 # include 
 # include 
 #endif
@@ -234,7 +235,7 @@ me_remote (char const *fs_name, char const *fs_type 
_GL_UNUSED)
  || (strcmp("-hosts", Fs_name) == 0))
 #endif
 
-#if MOUNTED_GETMNTINFO
+#if MOUNTED_GETMNTINFO  /* Mac OS X, FreeBSD, OpenBSD, also (obsolete) 
4.4BSD */
 
 # if ! HAVE_STRUCT_STATFS_F_FSTYPENAME
 static char *
@@ -344,7 +345,7 @@ fsp_to_string (const struct statfs *fsp)
 
 #endif /* MOUNTED_GETMNTINFO */
 
-#ifdef MOUNTED_VMOUNT   /* AIX.  */
+#ifdef MOUNTED_VMOUNT   /* AIX */
 static char *
 fstype_to_string (int t)
 {
@@ -395,7 +396,7 @@ dev_from_mount_options (char const *mount_options)
 
 #endif
 
-#if defined MOUNTED_GETMNTENT1 && defined __linux__
+#if defined MOUNTED_GETMNTENT1 && defined __linux__ /* GNU/Linux, Android */
 
 /* Unescape the paths in mount tables.
STR is updated in place.  */
@@ -436,7 +437,7 @@ read_file_system_list (bool need_fs_type)
   struct mount_entry **mtail = _list;
   (void) need_fs_type;
 
-#ifdef MOUNTED_LISTMNTENT
+#ifdef MOUNTED_LISTMNTENT   /* (obsolete) Cray UNICOS 9 */
   {
 struct tabmntent *mntlist, *p;
 struct mntent *mnt;
@@ -467,11 +468,12 @@ read_file_system_list (bool need_fs_type)
   }
 #endif
 
-#ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix.  */
+#ifdef MOUNTED_GETMNTENT1   /* glibc, HP-UX, IRIX, Cygwin, Android,
+   also (obsolete) 4.3BSD, SunOS, Dynix */
   {
 FILE *fp;
 
-#ifdef __linux__
+# ifdef __linux__
 /* Try parsing mountinfo first, as that make device IDs available.
Note we could use libmount routines to simplify this parsing a little
(and that code is in 

Re: timevar: further work

2018-10-11 Thread Akim Demaille
The results with getrusage are indeed much more precise.

This is with times.

$ ./_build/7s/tests/bison --trace=time ~/Downloads/Z280/asm1a.y
asm1a2.y: avertissement: 33 conflits par décalage/réduction [-Wconflicts-sr]

Execution times (seconds)
 reader: 0,0100 ( 2%) usr 0, ( 0%) sys 0, ( 0%) wall
 LR(0) : 0,0100 ( 2%) usr 0, ( 0%) sys 0, ( 0%) wall
 outputting report : 0,0300 ( 7%) usr 0, ( 0%) sys 0, ( 0%) wall
 parser action tables  : 0,0200 ( 4%) usr 0, ( 0%) sys 0, ( 0%) wall
 outputting parser : 0,0100 ( 2%) usr 0, ( 0%) sys 0, ( 0%) wall
 running m4: 0,3700 (82%) usr 0, ( 0%) sys 0, ( 0%) wall
 total time:   0,45 0,00 0,00


This is with getrusage.

$ ./_build/7s/tests/bison --trace=time ~/Downloads/Z280/asm1a.y
asm1a2.y: avertissement: 33 conflits par décalage/réduction [-Wconflicts-sr]

Execution times (seconds)
 reader: 0,0163 ( 4%) usr 0,0016 (19%) sys
 outputting report : 0,0273 ( 6%) usr 0,0013 (16%) sys
 parser action tables  : 0,0184 ( 4%) usr 0,0001 ( 1%) sys
 outputting parser : 0,0109 ( 2%) usr 0,0010 (12%) sys
 running m4: 0,3794 (83%) usr 0,0040 (47%) sys
 total time:   0,46 0,01

  


Weirdly enough though, some phases in Bison now completely
disappear. From the report.  For instance, LR(0) that we see
almost at each run with time never shows with getrusage.


Also, I wrote something completely wrong:

> - getrusage offers two choices:
>  - RUSAGE_SELF: the calling process and its threads.
>  - RUSAGE_CHILDREN: main and subprocesses that have been wait’ed.

No, RUSAGE_CHILDREN is _only_ about the children.  Two calls are needed
to get self + children.


Re: timevar: further work

2018-10-11 Thread Akim Demaille



> Le 11 oct. 2018 à 20:05, Bruno Haible  a écrit :
> 
> Hi Akim,
> 
>> Ok.  But since really, this tool is not for high quality profile,
>> but just to get cost estimates, I did not aim at that level of
>> precision. ...
>> Also, I don’t think it makes sense to have more than 2 digits
>> of precision: we are very likely to be within noise already
>> with 2.
> 
> Not all programs take more than 1 second of run time. If a program
> takes 0.03 seconds of run time, and the 'wall clock' column would
> give me a good understanding of what's going on if printed with
> 6 decimal places, why do you want to truncate it to 2 decimal places?
> (It's clear that the 'CPU user' and 'CPU system' columns will not be
> useful in this situation; I don't argue for 2 vs. 3 decimal places
> on these columns.)

At some point we agreed to use a dynamic scale: s or ms for instance.
I’m really referring to the number of significant digits.


getprogname: support for 32-bit programs on HP-UX

2018-10-11 Thread Bruno Haible
2018-10-11  Bruno Haible  

getprogname: Add support for 32-bit programs on HP-UX.
* lib/getprogname.c (getprogname) [HP-UX]: If pstat_getproc fails,
try the similar functions 32-bit programs on 64-bit HP-UX.

diff --git a/lib/getprogname.c b/lib/getprogname.c
index 4f97df4..2236d19 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -112,31 +112,71 @@ getprogname (void)
   struct pst_status status;
   if (pstat_getproc (, sizeof status, 0, pid) > 0)
 {
-  if (strlen (status.pst_ucomm) < PST_UCOMMLEN - 1)
-p = status.pst_ucomm;
+  char *ucomm = status.pst_ucomm;
+  char *cmd = status.pst_cmd;
+  if (strlen (ucomm) < PST_UCOMMLEN - 1)
+p = ucomm;
   else
 {
-  /* status.pst_ucomm is truncated to length PST_UCOMMLEN - 1.
- Look at status.pst_cmd instead.  */
-  char *space = strchr (status.pst_cmd, ' ');
+  /* ucomm is truncated to length PST_UCOMMLEN - 1.
+ Look at cmd instead.  */
+  char *space = strchr (cmd, ' ');
   if (space != NULL)
 *space = '\0';
-  p = strrchr (status.pst_cmd, '/');
+  p = strrchr (cmd, '/');
   if (p != NULL)
 p++;
   else
-p = status.pst_cmd;
+p = cmd;
   if (strlen (p) > PST_UCOMMLEN - 1
-  && memcmp (p, status.pst_ucomm, PST_UCOMMLEN - 1) == 0)
-/* p is less truncated than status.pst_ucomm.  */
+  && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
+/* p is less truncated than ucomm.  */
 ;
   else
-p = status.pst_ucomm;
+p = ucomm;
 }
   p = strdup (p);
 }
   else
-p = NULL;
+{
+#  if !defined __LP64__
+  /* Support for 32-bit programs running in 64-bit HP-UX.
+ The documented way to do this is to use the same source code
+ as above, but in a compilation unit where '#define _PSTAT64 1'
+ is in effect.  I prefer a single compilation unit; the struct
+ size and the offsets are not going to change.  */
+  char status64[1216];
+  if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0)
+{
+  char *ucomm = status64 + 288;
+  char *cmd = status64 + 168;
+  if (strlen (ucomm) < PST_UCOMMLEN - 1)
+p = ucomm;
+  else
+{
+  /* ucomm is truncated to length PST_UCOMMLEN - 1.
+ Look at cmd instead.  */
+  char *space = strchr (cmd, ' ');
+  if (space != NULL)
+*space = '\0';
+  p = strrchr (cmd, '/');
+  if (p != NULL)
+p++;
+  else
+p = cmd;
+  if (strlen (p) > PST_UCOMMLEN - 1
+  && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
+/* p is less truncated than ucomm.  */
+;
+  else
+p = ucomm;
+}
+  p = strdup (p);
+}
+  else
+#  endif
+p = NULL;
+}
   if (!p)
 p = "?";
 }




Re: timevar: further work

2018-10-11 Thread Bruno Haible
Hi Akim,

> Ok.  But since really, this tool is not for high quality profile,
> but just to get cost estimates, I did not aim at that level of
> precision. ...
> Also, I don’t think it makes sense to have more than 2 digits
> of precision: we are very likely to be within noise already
> with 2.

Not all programs take more than 1 second of run time. If a program
takes 0.03 seconds of run time, and the 'wall clock' column would
give me a good understanding of what's going on if printed with
6 decimal places, why do you want to truncate it to 2 decimal places?
(It's clear that the 'CPU user' and 'CPU system' columns will not be
useful in this situation; I don't argue for 2 vs. 3 decimal places
on these columns.)

Bruno





getprogname: improvement on HP-UX

2018-10-11 Thread Bruno Haible
On HP-UX (hppa 64-bit), the test-xalloc-die.sh test fails:

*** -   Thu Oct 11 15:47:41 2018
--- err2Thu Oct 11 15:55:06 2018
***
*** 1 
! test-xalloc-die: memory exhausted
--- 1 
! test-xalloc-di: memory exhausted
FAIL test-xalloc-die.sh (exit status: 1)

The reason is a truncation of the program name to 14 characters. This can
be avoided in some cases. The command can be up to 63 characters and may
contain the program name.


2018-10-11  Bruno Haible  

getprogname: Work around program name truncation when possible.
* lib/getprogname.c (getprogname) [HP-UX]: When pst_ucomm is truncated,
possibly use pst_cmd instead.

diff --git a/lib/getprogname.c b/lib/getprogname.c
index 58625de..4f97df4 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -110,9 +110,33 @@ getprogname (void)
   first = 0;
   pid_t pid = getpid ();
   struct pst_status status;
-  p = (0 < pstat_getproc (, sizeof status, 0, pid)
-   ? strdup (status.pst_ucomm)
-   : NULL);
+  if (pstat_getproc (, sizeof status, 0, pid) > 0)
+{
+  if (strlen (status.pst_ucomm) < PST_UCOMMLEN - 1)
+p = status.pst_ucomm;
+  else
+{
+  /* status.pst_ucomm is truncated to length PST_UCOMMLEN - 1.
+ Look at status.pst_cmd instead.  */
+  char *space = strchr (status.pst_cmd, ' ');
+  if (space != NULL)
+*space = '\0';
+  p = strrchr (status.pst_cmd, '/');
+  if (p != NULL)
+p++;
+  else
+p = status.pst_cmd;
+  if (strlen (p) > PST_UCOMMLEN - 1
+  && memcmp (p, status.pst_ucomm, PST_UCOMMLEN - 1) == 0)
+/* p is less truncated than status.pst_ucomm.  */
+;
+  else
+p = status.pst_ucomm;
+}
+  p = strdup (p);
+}
+  else
+p = NULL;
   if (!p)
 p = "?";
 }




Re: timevar: further work

2018-10-11 Thread Akim Demaille


> Le 10 oct. 2018 à 23:50, Bruno Haible  a écrit :
> 
> Just make sure that the user understands that the wall clock timings
> have microsecond resolution wheras the user+system time values have
> a lower resolutions. Since they are in the same line of output, it's
> not obvious to understand.

Ok.  But since really, this tool is not for high quality profile,
but just to get cost estimates, I did not aim at that level of
precision.

> What would be the best way to clarify this? By using an appropriate
> number of decimal digits?
> 
> Execution times (seconds)
> read  :   0.091 (19%) usr   0.080 (80%) sys   0.090242 (18%) 
> wall
> read: scan:   0.043 ( 9%) usr   0.080 (80%) sys   0.123492 (26%) 
> wall
> read: parse   :   0.056 (10%) usr   0.000 ( 0%) sys   0.052384 (10%) 
> wall
> work  :   0.333 (70%) usr   0.000 ( 0%) sys   0.353432 (71%) 
> wall
> work: phase 1 :   0.301 (64%) usr   0.000 ( 0%) sys   0.307234 (64%) 
> wall
> work: phase 2 :   0.139 (28%) usr   0.000 ( 0%) sys   0.144232 (29%) 
> wall
> output:   0.043 ( 9%) usr   0.020 (20%) sys   0.040233 ( 8%) 
> wall
> total time:   0.474 0.100 0.492343
> 
> Or by using column headers?
> 
> Execution times (seconds)
>  CPU user  CPU systemwall clock
>  (4 ms res.)   (4 ms res.)   (1 µs res.)
> read  :   0.091 (19%)   0.080 (80%)   0.090242 (18%)
> read: scan:   0.043 ( 9%)   0.080 (80%)   0.123492 (26%)
> read: parse   :   0.056 (10%)   0.000 ( 0%)   0.052384 (10%)
> work  :   0.333 (70%)   0.000 ( 0%)   0.353432 (71%)
> work: phase 1 :   0.301 (64%)   0.000 ( 0%)   0.307234 (64%)
> work: phase 2 :   0.139 (28%)   0.000 ( 0%)   0.144232 (29%)
> output:   0.043 ( 9%)   0.020 (20%)   0.040233 ( 8%)
> total time:   0.474 0.100 0.492343

I clearly prefer the second one, not because it specifies the
precision, but because it factors details.

Also, I don’t think it makes sense to have more than 2 digits
of precision: we are very likely to be within noise already
with 2.