From f386d53b448792d2b202d0db5a1b6fda75dffa63 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Thu, 18 Apr 2013 19:08:01 +0000 Subject: [PATCH] New: TimerOutput::Scope for scope based timing. git-svn-id: https://svn.dealii.org/trunk@29334 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 20 ++++++---- deal.II/include/deal.II/base/timer.h | 59 ++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 99f39f441c..7fcd24d2e4 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -64,13 +64,6 @@ this function.
    -
  1. Fixed: TimerOutput constructed with an MPI_COMM in wall_time - mode now constructs synchronized Timer objects. This gives reliable - parallel benchmark timings. -
    - (Timo Heister, 2013/04/18) -
  2. -
  3. New: The step-49 tutorial program now also has a discussion on what to do once you have a coarse mesh and want to refine it.
    @@ -118,6 +111,19 @@ this function.
      +
    1. New: class TimerOutput::Scope does automatic scope based enter/ +exit_section of a TimerOutput object. +
      +(Timo Heister, 2013/04/18) +
    2. + +
    3. Fixed: TimerOutput constructed with an MPI_COMM in wall_time +mode now constructs synchronized Timer objects. This gives reliable +parallel benchmark timings. +
      +(Timo Heister, 2013/04/18) +
    4. +
    5. Improved and Fixed: LogStream (and deallog) now respect std::flush in addition to std::endl to write out content to the console/file. Furthermore, LogStream::push(...) and LogStream::pop() now work in a thread diff --git a/deal.II/include/deal.II/base/timer.h b/deal.II/include/deal.II/base/timer.h index d9f36d9b7e..bb031c3ce5 100644 --- a/deal.II/include/deal.II/base/timer.h +++ b/deal.II/include/deal.II/base/timer.h @@ -320,6 +320,41 @@ private: class TimerOutput { public: + /** + * Helper class to enter/exit sections in TimerOutput be constructing + * a simple scope-based object. + */ + class Scope + { + public: + /** + * Enter the given section in the timer. Exit automatically when calling + * stop() or destructor runs. + */ + Scope(dealii::TimerOutput &timer_, const std::string §ion_name); + + /** + * Destructor calls stop() + */ + ~Scope(); + + /** + * In case you want to exit the scope before the destructor is executed, + * call this function. + */ + void stop(); + + private: + /** + * Reference to the TimerOutput object + */ + dealii::TimerOutput & timer; + /** + * Do we still need to exit the section we are in? + */ + bool in; + }; + /** * Sets whether to generate output every * time we exit a section, just in the @@ -585,6 +620,30 @@ TimerOutput::exit_section (const std::string §ion_name) leave_subsection(section_name); } +inline +TimerOutput::Scope::Scope(dealii::TimerOutput &timer_, const std::string §ion_name) +: +timer(timer_), in(true) +{ + timer.enter_section(section_name); +} + +inline +TimerOutput::Scope::~Scope() +{ + stop(); +} + +inline +void +TimerOutput::Scope::stop() +{ + if (!in) return; + in=false; + + timer.exit_section(); +} + DEAL_II_NAMESPACE_CLOSE -- 2.39.5