]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Timer class can now also return the wall time.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 7 Jan 2009 08:06:20 +0000 (08:06 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 7 Jan 2009 08:06:20 +0000 (08:06 +0000)
git-svn-id: https://svn.dealii.org/trunk@18110 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/timer.h
deal.II/base/source/timer.cc

index 654f31066ae4ab69d91c4499b0d338c8da0afe9e..140e0d13b9dced314a7d677ddc03de5af2da1fa3 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -52,7 +52,7 @@ DEAL_II_NAMESPACE_OPEN
  * @note Implementation of this class is system
  * dependent. Unfortunately, it does not work with multithreading
  * right now. In this case, we would like to sum up the time needed by
- * all children. Furthermore, a wall clock option would be nice.
+ * all children.
  *
  * @ingroup utilities
  * @author G. Kanschat, W. Bangerth
@@ -95,6 +95,14 @@ class Timer
                                      */
     double operator() () const;
 
+                                    /**
+                                     * Access to the current wall time
+                                     * without disturbing time
+                                     * measurement. The elapsed time is
+                                     * returned in units of seconds.
+                                     */
+    double wall_time () const;
+
   private:
 
                                     /**
@@ -128,6 +136,14 @@ class Timer
                                      */
     double              start_time_children;
 
+                                    /**
+                                     * Value of the wall time when start()
+                                     * was called the last time or when the
+                                     * object was created and no stop() was
+                                     * issued in between.
+                                     */
+    double              start_wall_time;
+
                                     /**
                                      * Accumulated time for all previous
                                      * start()/stop() cycles. The time for
@@ -136,6 +152,15 @@ class Timer
     double              cumulative_time;
 
 
+                                    /**
+                                     * Accumulated waoo time for all
+                                     * previous start()/stop() cycles. The
+                                     * wall time for the present cycle is
+                                     * not included.
+                                     */
+    double              cumulative_wall_time;
+
+
                                     /**
                                      * Store whether the timer is presently
                                      * running.
index 9f5208ea5aabf2ae23a9f3a5978fa0f119e31b48..eda66492835dd622890de805b80e84d674f52e7d 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2009 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -35,7 +35,8 @@ DEAL_II_NAMESPACE_OPEN
 
 Timer::Timer()
                 :
-                cumulative_time (0.)
+                cumulative_time (0.),
+               cumulative_wall_time (0.)
 {
   start();
 }
@@ -45,6 +46,11 @@ Timer::Timer()
 void Timer::start ()
 {
   running    = true;
+
+  struct timeval wall_timer;
+  gettimeofday(&wall_timer, NULL);
+  start_wall_time = wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec;
+
   rusage usage;
   getrusage (RUSAGE_SELF, &usage);
   start_time = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
@@ -71,6 +77,11 @@ double Timer::stop ()
       const double dtime_children =
        usage_children.ru_utime.tv_sec + 1.e-6 * usage_children.ru_utime.tv_usec;
       cumulative_time += dtime_children - start_time_children;
+
+      struct timeval wall_timer;
+      gettimeofday(&wall_timer, NULL);
+      cumulative_wall_time += wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec 
+       - start_wall_time;
     }
   return cumulative_time;
 }
@@ -98,9 +109,25 @@ double Timer::operator() () const
 
 
 
+double Timer::wall_time () const
+{
+  if (running)
+    {
+      struct timeval wall_timer;
+      gettimeofday(&wall_timer, NULL);
+      return wall_timer.tv_sec + 1.e-6 * wall_timer.tv_usec - start_wall_time + 
+       cumulative_wall_time;
+    }
+  else
+    return cumulative_wall_time;
+}
+
+
+
 void Timer::reset ()
 {
   cumulative_time = 0.;
+  cumulative_wall_time = 0.;
   running         = false;
 }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.