]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New: TimerOutput::Scope for scope based timing.
authorTimo Heister <timo.heister@gmail.com>
Thu, 18 Apr 2013 19:08:01 +0000 (19:08 +0000)
committerTimo Heister <timo.heister@gmail.com>
Thu, 18 Apr 2013 19:08:01 +0000 (19:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@29334 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/timer.h

index 99f39f441c4c66c71071d5c9cdc99cd3c40163a9..7fcd24d2e4e91b11af82d649ef6a74e4529871bb 100644 (file)
@@ -64,13 +64,6 @@ this function.
 
 
 <ol>
-  <li> Fixed: TimerOutput constructed with an MPI_COMM in wall_time
-  mode now constructs synchronized Timer objects. This gives reliable
-  parallel benchmark timings.
-  <br>
-  (Timo Heister, 2013/04/18)
-  </li>
-
   <li> 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.
   <br>
@@ -118,6 +111,19 @@ this function.
 
 <ol>
 
+<li> New: class TimerOutput::Scope does automatic scope based enter/
+exit_section of a TimerOutput object.
+<br>
+(Timo Heister, 2013/04/18)
+</li>
+
+<li> Fixed: TimerOutput constructed with an MPI_COMM in wall_time
+mode now constructs synchronized Timer objects. This gives reliable
+parallel benchmark timings.
+<br>
+(Timo Heister, 2013/04/18)
+</li>
+
 <li> 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
index d9f36d9b7ef413a216849ebacd4bf11490fcba5a..bb031c3ce52a27a64b6e83d8d35d4a1da1dfbebf 100644 (file)
@@ -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 &section_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 &section_name)
   leave_subsection(section_name);
 }
 
+inline
+TimerOutput::Scope::Scope(dealii::TimerOutput &timer_, const std::string &section_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
 

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.