# HG changeset patch # User Akim Demaille # Date 1539273275 -7200 # Node ID 24499928832b16f288d120ac771ce4c8e535e388 # Parent f2b5499e6ee23e4dae8d6b46e418e10576483b03 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. (Files): Remove m4/timevar.m4. * 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 -r f2b5499e6ee2 -r 24499928832b ChangeLog --- a/ChangeLog Fri Oct 12 11:12:53 2018 +0200 +++ b/ChangeLog Thu Oct 11 17:54:35 2018 +0200 @@ -1,3 +1,18 @@ +2018-10-13 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. + (Files): Remove m4/timevar.m4. + * 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-12 Bruno Haible mountlist: Improve support for Solaris in 64-bit mode. diff -r f2b5499e6ee2 -r 24499928832b lib/timevar.c --- a/lib/timevar.c Fri Oct 12 11:12:53 2018 +0200 +++ b/lib/timevar.c Thu Oct 11 17:54:35 2018 +0200 @@ -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 @@ 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 @@ if (!timevar_enabled) return; - { -#ifdef USE_TIMES - struct tms tms; - now->wall = times (&tms) * 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, &rusage); - 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, &rusage); + 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, &rusage); + 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 @@ timevars[identifier__].name = name__; #include "timevar.def" #undef DEFTIMEVAR - -#if defined USE_TIMES - ticks_to_msec = TICKS_TO_MSEC; -#endif } void @@ -337,8 +282,6 @@ void timevar_print (FILE *fp) { - /* Only print stuff if we have some sort of time information. */ -#if defined HAVE_USER_TIME || defined HAVE_SYS_TIME || defined HAVE_WALL_TIME if (!timevar_enabled) return; @@ -386,41 +329,27 @@ /* The timing variable name. */ fprintf (fp, " %-22s:", tv->name); -# ifdef HAVE_USER_TIME /* Print user-mode time for this process. */ fprintf (fp, "%7.2f (%2.0f%%) usr", tv->elapsed.user, (total->user == 0 ? 0 : tv->elapsed.user / total->user) * 100); -# endif -# ifdef HAVE_SYS_TIME /* Print system-mode time for this process. */ fprintf (fp, "%7.2f (%2.0f%%) sys", tv->elapsed.sys, (total->sys == 0 ? 0 : tv->elapsed.sys / total->sys) * 100); -# endif -# ifdef HAVE_WALL_TIME /* Print wall clock time elapsed. */ fprintf (fp, "%7.2f (%2.0f%%) wall", tv->elapsed.wall, (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100); -# endif putc ('\n', fp); } /* Print total time. */ fprintf (fp, " %-22s:", timevars[tv_total].name); -#ifdef HAVE_USER_TIME fprintf (fp, "%7.2f ", total->user); -#endif -#ifdef HAVE_SYS_TIME fprintf (fp, "%7.2f ", total->sys); -#endif -#ifdef HAVE_WALL_TIME fprintf (fp, "%7.2f\n", total->wall); -#endif - -#endif /* defined HAVE_USER_TIME || defined HAVE_SYS_TIME || defined HAVE_WALL_TIME */ } diff -r f2b5499e6ee2 -r 24499928832b lib/timevar.h --- a/lib/timevar.h Fri Oct 12 11:12:53 2018 +0200 +++ b/lib/timevar.h Thu Oct 11 17:54:35 2018 +0200 @@ -124,7 +124,9 @@ void timevar_print (FILE *fp); -/* Set to to nonzero to enable timing variables. */ +/* Set to to nonzero to enable timing variables. All the timevar + functions make an early exit if timevar is disabled. */ + extern int timevar_enabled; # ifdef __cplusplus diff -r f2b5499e6ee2 -r 24499928832b m4/timevar.m4 --- a/m4/timevar.m4 Fri Oct 12 11:12:53 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -# -*- Autoconf -*- -# Checks required to run `timevar', a time tracker. -# -# Copyright (C) 2002-2003, 2009-2015, 2018 Free Software Foundation, -# Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# serial 3 - -AC_DEFUN([gl_TIMEVAR], -[AC_CHECK_HEADERS([sys/time.h sys/times.h]) - AC_CHECK_HEADERS([sys/resource.h], [], [], - [$ac_includes_default -#if HAVE_SYS_TIME_H -# include -#endif -#ifdef HAVE_SYS_TIMES_H -# include -#endif -]) -AC_CHECK_FUNCS([times]) - -AC_CHECK_DECLS([getrusage, times, clock, sysconf], [], [], -[$ac_includes_default -#if HAVE_SYS_TIME_H -# include -#endif -#if HAVE_SYS_TIMES_H -# include -#endif -#if HAVE_SYS_RESOURCE_H -# include -#endif -]) -]) diff -r f2b5499e6ee2 -r 24499928832b modules/timevar --- a/modules/timevar Fri Oct 12 11:12:53 2018 +0200 +++ b/modules/timevar Thu Oct 11 17:54:35 2018 +0200 @@ -4,9 +4,9 @@ Files: lib/timevar.h lib/timevar.c -m4/timevar.m4 Depends-on: +getrusage gettext-h stdlib sys_time @@ -14,9 +14,6 @@ times xalloc -configure.ac: -gl_TIMEVAR - Makefile.am: lib_SOURCES += timevar.c timevar.def