From 541beb18ae78112bc19710c3af6552d129f24219 Mon Sep 17 00:00:00 2001 From: guido Date: Fri, 11 Feb 2000 19:30:54 +0000 Subject: [PATCH] use gerusage git-svn-id: https://svn.dealii.org/trunk@2392 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/timer.h | 25 +++++--------- deal.II/base/source/timer.cc | 57 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/deal.II/base/include/base/timer.h b/deal.II/base/include/base/timer.h index 922743bb8b..cc02a0c63f 100644 --- a/deal.II/base/include/base/timer.h +++ b/deal.II/base/include/base/timer.h @@ -39,34 +39,35 @@ * * 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; }; diff --git a/deal.II/base/source/timer.cc b/deal.II/base/source/timer.cc index ef8604dd52..7163cc23b4 100644 --- a/deal.II/base/source/timer.cc +++ b/deal.II/base/source/timer.cc @@ -3,55 +3,50 @@ #include -#include - -// this include should probably be properly -// ./configure'd using the AC_HEADER_TIME macro: -#include - -// 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 +#include Timer::Timer() - : cumulative_time(0.) + : cumulative_time (0.) { start(); -}; +} -void Timer::start () { +void Timer::start () +{ running = true; - overflow = 0; - start_time = static_cast(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(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(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; }; -- 2.39.5