+2018-10-13 Akim Demaille <akim@lrde.epita.fr>
+
+ 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 <bruno@clisp.org>
mountlist: Improve support for Solaris in 64-bit mode.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/time.h>
#include <sys/times.h>
#define _(msgid) gettext (msgid)
#include "xalloc.h"
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#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;
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)
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. */
timevars[identifier__].name = name__;
#include "timevar.def"
#undef DEFTIMEVAR
-
-#if defined USE_TIMES
- ticks_to_msec = TICKS_TO_MSEC;
-#endif
}
void
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;
/* 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 */
}
+++ /dev/null
-# -*- 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 <http://www.gnu.org/licenses/>.
-
-# 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 <sys/time.h>
-#endif
-#ifdef HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
-])
-AC_CHECK_FUNCS([times])
-
-AC_CHECK_DECLS([getrusage, times, clock, sysconf], [], [],
-[$ac_includes_default
-#if HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-#if HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
-#if HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
-])
-])