From 0ec013057d2e3afbcf7efe8184fd7c981b18a040 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sat, 8 Aug 2009 13:03:00 +0000 Subject: [PATCH] Add a simple output option. git-svn-id: https://svn.dealii.org/trunk@19213 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/timer.h | 32 +++++++++++++++++++++++++++++- deal.II/base/source/timer.cc | 33 ++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/deal.II/base/include/base/timer.h b/deal.II/base/include/base/timer.h index 172ba51df4..6dd3f05bad 100644 --- a/deal.II/base/include/base/timer.h +++ b/deal.II/base/include/base/timer.h @@ -364,6 +364,30 @@ class TimerOutput */ void print_summary () const; + /** + * By calling this function, all output + * can be disabled. This function + * together with enable_output() can be + * useful if one wants to control the + * output in a flexible way without + * putting a lot of if clauses + * in the program. + */ + void disable_output (); + + /** + * This function re-enables output of + * this class if it was previously + * disabled with disable_output(). This + * function together with + * disable_output() can be useful if + * one wants to control the output in a + * flexible way without putting a lot + * of if clauses in the + * program. + */ + void enable_output (); + private: /** * A timer object for the overall @@ -398,6 +422,13 @@ class TimerOutput */ ConditionalOStream out_stream; + /** + * A boolean variable that sets whether + * output of this class is currently on + * or off. + */ + bool output_is_enabled; + /** * A list of the sections that * have been entered and not @@ -424,7 +455,6 @@ class TimerOutput * class gives reasonable results even * when used with several threads. */ - Threads::ThreadMutex mutex; }; diff --git a/deal.II/base/source/timer.cc b/deal.II/base/source/timer.cc index 281370c317..1fdef24ef0 100644 --- a/deal.II/base/source/timer.cc +++ b/deal.II/base/source/timer.cc @@ -206,7 +206,8 @@ TimerOutput::TimerOutput (std::ostream &stream, : output_frequency (output_frequency), output_type (output_type), - out_stream (stream, true) + out_stream (stream, true), + output_is_enabled (true) #ifdef DEAL_II_COMPILER_SUPPORTS_MPI , mpi_communicator (MPI_COMM_SELF) #endif @@ -220,7 +221,8 @@ TimerOutput::TimerOutput (ConditionalOStream &stream, : output_frequency (output_frequency), output_type (output_type), - out_stream (stream) + out_stream (stream), + output_is_enabled (true) #ifdef DEAL_II_COMPILER_SUPPORTS_MPI , mpi_communicator (MPI_COMM_SELF) #endif @@ -236,7 +238,8 @@ TimerOutput::TimerOutput (MPI_Comm mpi_communicator, : output_frequency (output_frequency), output_type (output_type), - out_stream (stream, true), + out_stream (stream, true), + output_is_enabled (true), mpi_communicator (mpi_communicator) {} @@ -250,6 +253,7 @@ TimerOutput::TimerOutput (MPI_Comm mpi_communicator, output_frequency (output_frequency), output_type (output_type), out_stream (stream), + output_is_enabled (true), mpi_communicator (mpi_communicator) {} @@ -261,7 +265,7 @@ TimerOutput::~TimerOutput() while (active_sections.size() > 0) exit_section(); - if (output_frequency != every_call) + if (output_frequency != every_call && output_is_enabled == true) print_summary(); } @@ -298,6 +302,9 @@ TimerOutput::enter_section (const std::string §ion_name) void TimerOutput::exit_section (const std::string §ion_name) { + Assert (active_sections.size() > 0, + ExcMessage("Cannot exit any section because none has been entered!")); + Threads::ThreadMutex::ScopedLock lock (mutex); if (section_name != "") @@ -347,7 +354,7 @@ TimerOutput::exit_section (const std::string §ion_name) // in case we have to print out // something, do that here... - if (output_frequency != summary) + if (output_frequency != summary && output_is_enabled == true) { std::string output_time; std::ostringstream cpu; @@ -532,4 +539,20 @@ TimerOutput::print_summary () const } + +void +TimerOutput::disable_output () +{ + output_is_enabled = false; +} + + + +void +TimerOutput::enable_output () +{ + output_is_enabled = true; +} + + DEAL_II_NAMESPACE_CLOSE -- 2.39.5