[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: timevar: 1/3: expect that getrusage is available
From: |
Akim Demaille |
Subject: |
Re: timevar: 1/3: expect that getrusage is available |
Date: |
Fri, 12 Oct 2018 06:52:06 +0200 |
Waiting for approval before pushing.
commit 65b74a02c39450878ac1c41b870e1188c4a0429e
Author: Akim Demaille <address@hidden>
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 <address@hidden>
+
+ 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 <address@hidden>
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/time.h>
#include <sys/times.h>
@@ -33,50 +34,6 @@
#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;
@@ -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 (&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 @@ timevar_init ()
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 @@ timevar_get (timevar_id_t timevar,
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 @@ timevar_print (FILE *fp)
/* 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 --git a/lib/timevar.h b/lib/timevar.h
index 7c9258409..ff443fed6 100644
--- a/lib/timevar.h
+++ b/lib/timevar.h
@@ -124,7 +124,9 @@ void timevar_get (timevar_id_t timevar, struct
timevar_time_def *elapsed);
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 --git a/m4/timevar.m4 b/m4/timevar.m4
deleted file mode 100644
index c790ed0a9..000000000
--- a/m4/timevar.m4
+++ /dev/null
@@ -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 <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
-])
-])
diff --git a/modules/timevar b/modules/timevar
index f82b7e90a..8be1b8318 100644
--- a/modules/timevar
+++ b/modules/timevar
@@ -7,6 +7,7 @@ lib/timevar.c
m4/timevar.m4
Depends-on:
+getrusage
gettext-h
stdlib
sys_time
@@ -14,9 +15,6 @@ sys_times
times
xalloc
-configure.ac:
-gl_TIMEVAR
-
Makefile.am:
lib_SOURCES += timevar.c timevar.def
- Re: timevar: further work, (continued)
- Re: timevar: further work, Akim Demaille, 2018/10/10
- Re: timevar: further work, Akim Demaille, 2018/10/10
- Re: timevar: further work, Bruno Haible, 2018/10/10
- Re: timevar: further work, Bruno Haible, 2018/10/10
- Re: timevar: further work, Akim Demaille, 2018/10/10
- Re: timevar: further work, Bruno Haible, 2018/10/10
- Re: timevar: further work, Akim Demaille, 2018/10/11
- Re: timevar: further work, Bruno Haible, 2018/10/11
- Re: timevar: further work, Akim Demaille, 2018/10/11
- Re: timevar: further work, Akim Demaille, 2018/10/11
- Re: timevar: 1/3: expect that getrusage is available,
Akim Demaille <=
- Re: timevar: 1/3: expect that getrusage is available, Bruno Haible, 2018/10/12
- Re: timevar: 1/3: expect that getrusage is available, Akim Demaille, 2018/10/13
- Re: timevar: 1/3: expect that getrusage is available, Bruno Haible, 2018/10/13
- Re: timevar: 2/3: improve the output format, Akim Demaille, 2018/10/12
- Re: timevar: 2/3: improve the output format, Bruno Haible, 2018/10/12
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/12
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/12
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/13