bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Would timevar be accepted in gnulib?


From: Akim Demaille
Subject: Re: Would timevar be accepted in gnulib?
Date: Thu, 27 Sep 2018 18:20:29 +0200

Hi!

Here is my initial proposal for timevar in gnulib.

Cheers!

commit 2e50fd35c46f6ffa1079f6939223cd36ba2fb71a
Author: Akim Demaille <address@hidden>
Date:   Thu Sep 27 07:00:42 2018 +0200

    timevar: import from Bison
    
    * m4/timevar.m4, modules/timevar, lib/timevar.h, lib/timevar.c,
    * doc/timevar.texi: New.

diff --git a/ChangeLog b/ChangeLog
index 45d85f0dc..0436b0b47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-27  Akim Demaille  <address@hidden>
+
+       timevar: import from Bison.
+       * m4/timevar.m4, modules/timevar, lib/timevar.h, lib/timevar.c:
+       New.
+
 2018-09-26  Bruno Haible  <address@hidden>
 
        javacomp-script, javacomp: Add preliminary support for Java 12..17.
diff --git a/doc/timevar.texi b/doc/timevar.texi
new file mode 100644
index 000000000..86ef8115e
--- /dev/null
+++ b/doc/timevar.texi
@@ -0,0 +1,91 @@
address@hidden timevar
address@hidden timevar
+
+A simple self-profiling module based on timers.
+
address@hidden
+Execution times (seconds)
+read                  :   0.09 (19%) usr   0.08 (80%) sys   0.09 (18%) wall
+read: scan            :   0.04 ( 9%) usr   0.08 (80%) sys   0.12 (26%) wall
+read: parse           :   0.05 (10%) usr   0.00 ( 0%) sys   0.05 (10%) wall
+work                  :   0.33 (70%) usr   0.00 ( 0%) sys   0.35 (71%) wall
+work: phase 1         :   0.30 (64%) usr   0.00 ( 0%) sys   0.30 (64%) wall
+work: phase 2         :   0.13 (28%) usr   0.00 ( 0%) sys   0.14 (29%) wall
+output                :   0.04 ( 9%) usr   0.02 (20%) sys   0.04 ( 8%) wall
+total time            :   0.47             0.10             0.49
address@hidden smallexample
+
+To set up @code{timevar}, copy the stub file
address@hidden/lib/timevar.def} next to where @file{timevar.h} and
address@hidden were imported in your project, and define your timers
+there.  For instance:
+
address@hidden
+/* The total execution time.  Mandatory.  */
+DEFTIMEVAR (tv_total,      "total time")
+
+/* Examples.  */
+DEFTIMEVAR (tv_read,       "read")
+DEFTIMEVAR (tv_work,       "work")
+DEFTIMEVAR (tv_work_1,     "work: phase 1")
+DEFTIMEVAR (tv_work_2,     "work: phase 2")
+DEFTIMEVAR (tv_output,     "output")
address@hidden smallexample
+
+Do not remove @code{tv_total}, it is mandatory.  You may change its
+associated string.
+
address@hidden 1
+
+Use @code{timevar_push}/@code{timevar_pop} to start/stop timers, as in
+the following example.
+
address@hidden
+#include <config.h>
+#include "timevar.h"
+
+#include "read.h"
+#include "work.h"
+#include "output.h"
+
+int main (void)
address@hidden
+  timevar_enabled = true;
+  timevar_init ();
+  timevar_start (tv_total);
+
+  timevar_push (tv_read);
+  reader ();
+  timevar_pop (tv_read);
+
+  timevar_push (tv_work);
+  work ();
+  timevar_pop (tv_work);
+
+  timevar_push (tv_output);
+  output ();
+  timevar_pop (tv_output);
+
+  timevar_stop (tv_total);
+  timevar_print (stderr);
address@hidden
address@hidden smallexample
+
address@hidden
+with, for instance, in @file{work.c}
+
address@hidden
+#include <config.h>
+#include <work.h>
+
+void work (void)
address@hidden
+  timevar_push (tv_work_phase1);
+  work1 ();
+  timevar_pop (tv_work_phase1);
+
+  timevar_push (tv_work_phase2);
+  work2 ();
+  timevar_pop (tv_work_phase2);
address@hidden
address@hidden smallexample
diff --git a/lib/timevar.c b/lib/timevar.c
new file mode 100644
index 000000000..0578816a3
--- /dev/null
+++ b/lib/timevar.c
@@ -0,0 +1,456 @@
+/* Timing variables for measuring compiler performance.
+
+   Copyright (C) 2000, 2002, 2004, 2006, 2009-2015, 2018 Free Software
+   Foundation, Inc.
+
+   Contributed by Alex Samuel <address@hidden>
+
+   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/>.  */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#include "xalloc.h"
+
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
+#ifdef HAVE_SYS_TIMES_H
+# include <sys/times.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
+#ifndef HAVE_CLOCK_T
+typedef int clock_t;
+#endif
+
+#ifndef HAVE_STRUCT_TMS
+struct tms
+{
+  clock_t tms_utime;
+  clock_t tms_stime;
+  clock_t tms_cutime;
+  clock_t tms_cstime;
+};
+#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
+#elif defined HAVE_CLOCK
+# define USE_CLOCK
+# define HAVE_USER_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 *);
+#elif defined USE_CLOCK && !defined HAVE_DECL_CLOCK
+clock_t clock (void);
+#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)
+#elif defined USE_CLOCK
+static float clocks_to_msec;
+# define CLOCKS_TO_MSEC (1.0 / CLOCKS_PER_SEC)
+#endif
+
+#include "timevar.h"
+
+/* See timevar.h for an explanation of timing variables.  */
+
+int timevar_enabled = 0;
+
+/* A timing variable.  */
+
+struct timevar_def
+{
+  /* Elapsed time for this variable.  */
+  struct timevar_time_def elapsed;
+
+  /* If this variable is timed independently of the timing stack,
+     using timevar_start, this contains the start time.  */
+  struct timevar_time_def start_time;
+
+  /* The name of this timing variable.  */
+  const char *name;
+
+  /* Non-zero if this timing variable is running as a standalone
+     timer.  */
+  unsigned standalone : 1;
+
+  /* Non-zero if this timing variable was ever started or pushed onto
+     the timing stack.  */
+  unsigned used : 1;
+};
+
+/* An element on the timing stack.  Elapsed time is attributed to the
+   topmost timing variable on the stack.  */
+
+struct timevar_stack_def
+{
+  /* The timing variable at this stack level.  */
+  struct timevar_def *timevar;
+
+  /* The next lower timing variable context in the stack.  */
+  struct timevar_stack_def *next;
+};
+
+/* Declared timing variables.  Constructed from the contents of
+   timevar.def.  */
+static struct timevar_def timevars[TIMEVAR_LAST];
+
+/* The top of the timing stack.  */
+static struct timevar_stack_def *stack;
+
+/* A list of unused (i.e. allocated and subsequently popped)
+   timevar_stack_def instances.  */
+static struct timevar_stack_def *unused_stack_instances;
+
+/* The time at which the topmost element on the timing stack was
+   pushed.  Time elapsed since then is attributed to the topmost
+   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.  */
+
+static void
+set_to_current_time (struct timevar_time_def *now)
+{
+  now->user = 0;
+  now->sys  = 0;
+  now->wall = 0;
+
+  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;
+#elif defined USE_CLOCK
+    now->user = clock () * clocks_to_msec;
+#endif
+  }
+}
+
+/* Return the current time.  */
+
+static struct timevar_time_def
+get_current_time (void)
+{
+  struct timevar_time_def now;
+  set_to_current_time (&now);
+  return now;
+}
+
+/* Add the difference between STOP and START to TIMER.  */
+
+static void
+timevar_accumulate (struct timevar_time_def *timer,
+                    const struct timevar_time_def *start,
+                    const struct timevar_time_def *stop)
+{
+  timer->user += stop->user - start->user;
+  timer->sys += stop->sys - start->sys;
+  timer->wall += stop->wall - start->wall;
+}
+
+void
+timevar_init ()
+{
+  if (!timevar_enabled)
+    return;
+
+  /* Zero all elapsed times.  */
+  memset ((void *) timevars, 0, sizeof (timevars));
+
+  /* Initialize the names of timing variables.  */
+#define DEFTIMEVAR(identifier__, name__) \
+  timevars[identifier__].name = name__;
+#include "timevar.def"
+#undef DEFTIMEVAR
+
+#if defined USE_TIMES
+  ticks_to_msec = TICKS_TO_MSEC;
+#elif defined USE_CLOCK
+  clocks_to_msec = CLOCKS_TO_MSEC;
+#endif
+}
+
+void
+timevar_push (timevar_id_t timevar)
+{
+  if (!timevar_enabled)
+    return;
+
+  struct timevar_def *tv = &timevars[timevar];
+
+  /* Mark this timing variable as used.  */
+  tv->used = 1;
+
+  /* Can't push a standalone timer.  */
+  if (tv->standalone)
+    abort ();
+
+  /* What time is it?  */
+  struct timevar_time_def const now = get_current_time ();
+
+  /* If the stack isn't empty, attribute the current elapsed time to
+     the old topmost element.  */
+  if (stack)
+    timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
+
+  /* Reset the start time; from now on, time is attributed to
+     TIMEVAR.  */
+  start_time = now;
+
+  /* See if we have a previously-allocated stack instance.  If so,
+     take it off the list.  If not, malloc a new one.  */
+  struct timevar_stack_def *context = NULL;
+  if (unused_stack_instances != NULL)
+    {
+      context = unused_stack_instances;
+      unused_stack_instances = unused_stack_instances->next;
+    }
+  else
+    context = (struct timevar_stack_def *)
+      xmalloc (sizeof (struct timevar_stack_def));
+
+  /* Fill it in and put it on the stack.  */
+  context->timevar = tv;
+  context->next = stack;
+  stack = context;
+}
+
+void
+timevar_pop (timevar_id_t timevar)
+{
+  if (!timevar_enabled)
+    return;
+
+  if (&timevars[timevar] != stack->timevar)
+    abort ();
+
+  /* What time is it?  */
+  struct timevar_time_def const now = get_current_time ();
+
+  /* Attribute the elapsed time to the element we're popping.  */
+  struct timevar_stack_def *popped = stack;
+  timevar_accumulate (&popped->timevar->elapsed, &start_time, &now);
+
+  /* Reset the start time; from now on, time is attributed to the
+     element just exposed on the stack.  */
+  start_time = now;
+
+  /* Take the item off the stack.  */
+  stack = stack->next;
+
+  /* Don't delete the stack element; instead, add it to the list of
+     unused elements for later use.  */
+  popped->next = unused_stack_instances;
+  unused_stack_instances = popped;
+}
+
+void
+timevar_start (timevar_id_t timevar)
+{
+  if (!timevar_enabled)
+    return;
+
+  struct timevar_def *tv = &timevars[timevar];
+
+  /* Mark this timing variable as used.  */
+  tv->used = 1;
+
+  /* Don't allow the same timing variable to be started more than
+     once.  */
+  if (tv->standalone)
+    abort ();
+  tv->standalone = 1;
+
+  set_to_current_time (&tv->start_time);
+}
+
+void
+timevar_stop (timevar_id_t timevar)
+{
+  if (!timevar_enabled)
+    return;
+
+  struct timevar_def *tv = &timevars[timevar];
+
+  /* TIMEVAR must have been started via timevar_start.  */
+  if (!tv->standalone)
+    abort ();
+
+  struct timevar_time_def const now = get_current_time ();
+  timevar_accumulate (&tv->elapsed, &tv->start_time, &now);
+}
+
+void
+timevar_get (timevar_id_t timevar,
+             struct timevar_time_def *elapsed)
+{
+  struct timevar_def *tv = &timevars[timevar];
+  *elapsed = tv->elapsed;
+
+  /* Is TIMEVAR currently running as a standalone timer?  */
+  if (tv->standalone)
+    {
+      struct timevar_time_def const now = get_current_time ();
+      timevar_accumulate (elapsed, &tv->start_time, &now);
+    }
+  /* Or is TIMEVAR at the top of the timer stack?  */
+  else if (stack->timevar == tv)
+    {
+      struct timevar_time_def const now = get_current_time ();
+      timevar_accumulate (elapsed, &start_time, &now);
+    }
+}
+
+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;
+
+  /* Update timing information in case we're calling this from GDB.  */
+
+  if (fp == 0)
+    fp = stderr;
+
+  /* What time is it?  */
+  struct timevar_time_def const now = get_current_time ();
+
+  /* If the stack isn't empty, attribute the current elapsed time to
+     the old topmost element.  */
+  if (stack)
+    timevar_accumulate (&stack->timevar->elapsed, &start_time, &now);
+
+  /* Reset the start time; from now on, time is attributed to
+     TIMEVAR.  */
+  start_time = now;
+
+  struct timevar_time_def const* total = &timevars[tv_total].elapsed;
+
+  fputs (_("\nExecution times (seconds)\n"), fp);
+  for (unsigned /* timevar_id_t */ id = 0; id < (unsigned) TIMEVAR_LAST; ++id)
+    {
+      struct timevar_def *tv = &timevars[(timevar_id_t) id];
+      const float tiny = 5e-3;
+
+      /* Don't print the total execution time here; that goes at the
+         end.  */
+      if ((timevar_id_t) id == tv_total)
+        continue;
+
+      /* Don't print timing variables that were never used.  */
+      if (!tv->used)
+        continue;
+
+      /* Don't print timing variables if we're going to get a row of
+         zeroes.  */
+      if (tv->elapsed.user < tiny
+          && tv->elapsed.sys < tiny
+          && tv->elapsed.wall < tiny)
+        continue;
+
+      /* 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.def b/lib/timevar.def
new file mode 100644
index 000000000..e5cc3ffa3
--- /dev/null
+++ b/lib/timevar.def
@@ -0,0 +1,52 @@
+/* This file contains the definitions for timing variables used to -*- C -*-
+   measure run-time performance of the compiler.
+
+   Copyright (C) 2002, 2007, 2009-2015, 2018 Free Software Foundation,
+   Inc.
+
+   Contributed by Akim Demaille <address@hidden>.
+
+   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/>.  */
+
+/* This file contains the list of timing variable definitions, used by
+   timevar.h and timevar.c.
+
+   Syntax:
+
+     DEFTIMEVAR (Id, Name);
+
+   where:
+
+   - Id is the value used to identify the timing variable.
+     It's an enum value, i.e., behaves like a positive integer.
+     It is used only the manipulate the timer: the user of the
+     program will never see this identifier.
+
+   - Name is a character string describing its purpose.  This string
+     will be presented to the user in the timing tables.  It does not
+     need to be a literal, you may for instance use gettext.
+
+   The order of this list matters: that is the order in which the
+   timing table is printed.
+  */
+
+/* The total execution time.  Mandatory.  */
+DEFTIMEVAR (tv_total,      "total time")
+
+/* Examples.  */
+DEFTIMEVAR (tv_read,       "read")
+DEFTIMEVAR (tv_work,       "work")
+DEFTIMEVAR (tv_work_1,     "work: phase 1")
+DEFTIMEVAR (tv_work_2,     "work: phase 2")
+DEFTIMEVAR (tv_output,     "output")
diff --git a/lib/timevar.h b/lib/timevar.h
new file mode 100644
index 000000000..a3c4e8642
--- /dev/null
+++ b/lib/timevar.h
@@ -0,0 +1,123 @@
+/* Timing variables for measuring compiler performance.
+
+   Copyright (C) 2000, 2002, 2004, 2009-2015, 2018 Free Software
+   Foundation, Inc.
+
+   Contributed by Alex Samuel <address@hidden>
+
+   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/>.  */
+
+#ifndef _TIMEVAR_H
+#define _TIMEVAR_H
+
+/* Timing variables are used to measure elapsed time in various
+   portions of the compiler.  Each measures elapsed user, system, and
+   wall-clock time, as appropriate to and supported by the host
+   system.
+
+   Timing variables are defined using the DEFTIMEVAR macro in
+   timevar.def.  Each has an enumeral identifier, used when referring
+   to the timing variable in code, and a character string name.
+
+   Timing variables can be used in two ways:
+
+     - On the timing stack, using timevar_push and timevar_pop.
+       Timing variables may be pushed onto the stack; elapsed time is
+       attributed to the topmost timing variable on the stack.  When
+       another variable is pushed on, the previous topmost variable is
+       'paused' until the pushed variable is popped back off.
+
+     - As a standalone timer, using timevar_start and timevar_stop.
+       All time elapsed between the two calls is attributed to the
+       variable.
+*/
+
+/* This structure stores the various varieties of time that can be
+   measured.  Times are stored in seconds.  The time may be an
+   absolute time or a time difference; in the former case, the time
+   base is undefined, except that the difference between two times
+   produces a valid time difference.  */
+
+struct timevar_time_def
+{
+  /* User time in this process.  */
+  float user;
+
+  /* System time (if applicable for this host platform) in this
+     process.  */
+  float sys;
+
+  /* Wall clock time.  */
+  float wall;
+};
+
+/* An enumeration of timing variable identifiers.  Constructed from
+   the contents of timevar.def.  */
+
+#define DEFTIMEVAR(identifier__, name__) \
+    identifier__,
+typedef enum
+{
+#include "timevar.def"
+  TIMEVAR_LAST
+}
+timevar_id_t;
+#undef DEFTIMEVAR
+
+/* Initialize timing variables.  */
+
+void timevar_init (void);
+
+/* Push TIMEVAR onto the timing stack.  No further elapsed time is
+   attributed to the previous topmost timing variable on the stack;
+   subsequent elapsed time is attributed to TIMEVAR, until it is
+   popped or another element is pushed on top.
+
+   TIMEVAR cannot be running as a standalone timer.  */
+
+void timevar_push (timevar_id_t);
+
+/* Pop the topmost timing variable element off the timing stack.  The
+   popped variable must be TIMEVAR.  Elapsed time since the that
+   element was pushed on, or since it was last exposed on top of the
+   stack when the element above it was popped off, is credited to that
+   timing variable.  */
+
+void timevar_pop (timevar_id_t);
+
+/* Start timing TIMEVAR independently of the timing stack.  Elapsed
+   time until timevar_stop is called for the same timing variable is
+   attributed to TIMEVAR.  */
+
+void timevar_start (timevar_id_t);
+
+/* Stop timing TIMEVAR.  Time elapsed since timevar_start was called
+   is attributed to it.  */
+
+void timevar_stop (timevar_id_t);
+/* Fill the elapsed time for TIMEVAR into ELAPSED.  Returns
+   update-to-date information even if TIMEVAR is currently running.  */
+
+void timevar_get (timevar_id_t, struct timevar_time_def *);
+
+/* Summarize timing variables to FP.  The timing variable TV_TOTAL has
+   a special meaning -- it's considered to be the total elapsed time,
+   for normalizing the others, and is displayed last.  */
+
+void timevar_print (FILE *);
+
+/* Set to to nonzero to enable timing variables.  */
+extern int timevar_enabled;
+
+#endif /* ! _TIMEVAR_H */
diff --git a/m4/timevar.m4 b/m4/timevar.m4
new file mode 100644
index 000000000..b41841342
--- /dev/null
+++ b/m4/timevar.m4
@@ -0,0 +1,60 @@
+# -*- 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 2
+
+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
+])
+
+AC_CHECK_TYPES([clock_t, struct tms], [], [],
+[$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
new file mode 100644
index 000000000..81a74b0d6
--- /dev/null
+++ b/modules/timevar
@@ -0,0 +1,24 @@
+Description:
+A simple self-profiling module based on timers.
+
+Files:
+lib/timevar.c
+lib/timevar.h
+m4/timevar.m4
+
+Depends-on:
+gettext-h
+xalloc
+stdlib
+
+configure.ac:
+gl_TIMEVAR
+
+Include:
+"timevar.h"
+
+License:
+GPLv3+
+
+Maintainer:
+all




reply via email to

[Prev in Thread] Current Thread [Next in Thread]