From: Martin Kronbichler Date: Wed, 7 Jan 2009 08:06:20 +0000 (+0000) Subject: Timer class can now also return the wall time. X-Git-Tag: v8.0.0~8182 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec5eab7ee80e745570763d3915132ef8cdd49c6d;p=dealii.git Timer class can now also return the wall time. git-svn-id: https://svn.dealii.org/trunk@18110 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/timer.h b/deal.II/base/include/base/timer.h index 654f31066a..140e0d13b9 100644 --- a/deal.II/base/include/base/timer.h +++ b/deal.II/base/include/base/timer.h @@ -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. diff --git a/deal.II/base/source/timer.cc b/deal.II/base/source/timer.cc index 9f5208ea5a..eda6649283 100644 --- a/deal.II/base/source/timer.cc +++ b/deal.II/base/source/timer.cc @@ -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; }