]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
use gerusage
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 11 Feb 2000 19:30:54 +0000 (19:30 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 11 Feb 2000 19:30:54 +0000 (19:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@2392 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 922743bb8b4c07d1f072acb2b41fd97f433664c0..cc02a0c63f0e34a91be5aebc8dadb6170ba2a583 100644 (file)
  *
  * Note: the implementation of this class is system dependant.
  *
- * @author R. Becker, G. Kanschat, F.-T. Suttmeier, revised by W. Bangerth
+ * @author G. Kanschat, W. Bangerth
  */
-class Timer {
-public:
+class Timer
+{
+  public:
                                     /**
                                      * Constructor. Starts the timer at 0 sec.
                                      */
-    Timer();
+    Timer ();
 
                                     /**
                                      * Re-start the timer at the point where
                                      * it was stopped. This way a cumulative
                                      * measurement of time is possible.
                                      */
-    void start();
+    void start ();
 
                                     /**
                                      * Sets the current time as next
                                      * starting time and return the
                                      * elapsed time in seconds.
                                      */
-    double stop();
+    double stop ();
 
                                     /**
                                      * Stop the timer if neccessary and reset
                                      * the elapsed time to zero.
                                      */
-    void reset();
+    void reset ();
 
                                     /**
                                      * Access to the current time
@@ -101,14 +102,6 @@ public:
                                      */
     double              cumulative_time;
 
-                                    /**
-                                     * Number of times that the counter
-                                     * had an overflow. We need to adjust the
-                                     * total time by this number times the
-                                     * number of seconds after which an
-                                     * overflow occurs.
-                                     */
-    mutable unsigned int overflow;
 
                                     /**
                                      * Store whether the timer is presently
@@ -123,7 +116,7 @@ public:
                                      * the time since the last overflow
                                      * occured.
                                      */
-    double full_time() const;
+    double full_time () const;
 };
 
 
index ef8604dd52f363df4aaf23766b25055e5c04f204..7163cc23b46bdcadd9031eaec02a648abac55b0d 100644 (file)
@@ -3,55 +3,50 @@
 
 
 #include <base/timer.h>
-#include <ctime>
-
-// this include should probably be properly
-// ./configure'd using the AC_HEADER_TIME macro:
-#include <sys/time.h>
-
-// maybe use times() instead of clock()?
 
 
-const double overtime = 4294967296./CLOCKS_PER_SEC;
-
 
+// these includes should probably be properly
+// ./configure'd using the AC_HEADER_TIME macro:
+#include <sys/resource.h>
+#include <sys/time.h>
 
 Timer::Timer()
-  : cumulative_time(0.)
+  : cumulative_time (0.)
 {
   start();
-};
+}
 
 
-void Timer::start () {
+void Timer::start ()
+{
   running    = true;
-  overflow   = 0;
-  start_time = static_cast<double>(clock()) /
-              CLOCKS_PER_SEC;
-};
+  rusage usage;
+  getrusage (RUSAGE_SELF, &usage);
+  start_time = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
+}
 
 
 
-double Timer::stop () {
+double Timer::stop ()
+{
   running = false;
-  double dtime =  (static_cast<double>(clock()) / CLOCKS_PER_SEC -
-                  start_time);
-  if (dtime < 0) {
-    overflow++;
-  };
-  
+  rusage usage;
+  getrusage (RUSAGE_SELF, &usage);
+  const double dtime = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
   cumulative_time += dtime;
   return full_time ();
 };
 
 
 
-double Timer::operator() () const {
+double Timer::operator() () const
+{
   if (running)
     {
-      const double dtime =  static_cast<double>(clock()) / CLOCKS_PER_SEC - start_time;
-      if (dtime < 0)
-       overflow++;
+      rusage usage;
+      getrusage (RUSAGE_SELF, &usage);
+      const double dtime =  usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
 
       return dtime + full_time();
     }
@@ -61,15 +56,17 @@ double Timer::operator() () const {
 
 
 
-void Timer::reset () {
+void Timer::reset ()
+{
   cumulative_time = 0.;
   running         = false;
 };
 
 
 
-double Timer::full_time () const {
-  return cumulative_time + overflow*overtime;
+double Timer::full_time () const
+{
+  return cumulative_time;
 };
 
 

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.