From: Martin Kronbichler Date: Mon, 9 Nov 2009 15:29:24 +0000 (+0000) Subject: Use similar names for entering/leaving sectios in TimerOutput as ParameterHandler... X-Git-Tag: v8.0.0~6831 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f48ed9ab2c1fd51de4eed58bd6687e031633d29;p=dealii.git Use similar names for entering/leaving sectios in TimerOutput as ParameterHandler does. Fix output issue. git-svn-id: https://svn.dealii.org/trunk@20074 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/timer.h b/deal.II/base/include/base/timer.h index 6dd3f05bad..b80691fc18 100644 --- a/deal.II/base/include/base/timer.h +++ b/deal.II/base/include/base/timer.h @@ -86,7 +86,7 @@ class Timer * CPU times over all processors in the * MPI network when requested by the * operator (). - * + * * Starts the timer at 0 sec. * * This constructor is only available @@ -219,30 +219,30 @@ class Timer * * Use of this class could be as follows: * @code - * TimerOuput timer (std::cout, TimerOutput::summary, + * TimerOuput timer (std::cout, TimerOutput::summary, * TimerOutput::wall_times); * - * timer.enter_section ("Setup dof system"); + * timer.enter_subsection ("Setup dof system"); * setup_dofs(); - * timer.exit_section(); + * timer.leave_subsection(); * - * timer.enter_section ("Assemble"); + * timer.enter_subsection ("Assemble"); * assemble_system_1(); - * timer.exit_section(); + * timer.leave_subsection(); * - * timer.enter_section ("Solve"); + * timer.enter_subsection ("Solve"); * solve_system_1(); - * timer.exit_section(); + * timer.leave_subsection(); * - * timer.enter_section ("Assemble"); + * timer.enter_subsection ("Assemble"); * assemble_system_2(); - * timer.exit_section(); + * timer.leave_subsection(); * - * timer.enter_section ("Solve"); + * timer.enter_subsection ("Solve"); * solve_system_2(); - * timer.exit_section(); + * timer.leave_subsection(); * - * // do something else... + * // do something else... * @endcode * When run, this program will return an output like this: * @code @@ -257,12 +257,12 @@ class Timer * +---------------------------------+-----------+------------+------------+ * @endcode * The output will see that we entered the assembly and solve section - * twice, and reports how much time we spent there. Moreover, the class + * twice, and reports how much time we spent there. Moreover, the class * measures the total time spent from start to termination of the TimerOutput * object. In this case, we did a lot of other stuff, so that the time * proportions of the functions we measured are far away from 100 precent. * - * See the @ref step_32 "step-32" tutorial program for usage of this class. + * See the @ref step_32 "step-32" tutorial program for usage of this class. * * @ingroup utilities * @author M. Kronbichler, 2009. @@ -282,14 +282,14 @@ class TimerOutput * Sets whether to show CPU times, wall * times, or both CPU and wall times. */ - enum OutputType {cpu_times, wall_times, cpu_and_wall_times} + enum OutputType {cpu_times, wall_times, cpu_and_wall_times} output_type; - + /** * Constructor that takes std::cout as * output stream. */ - TimerOutput (std::ostream &stream, + TimerOutput (std::ostream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type); @@ -297,10 +297,10 @@ class TimerOutput * Constructor that takes a * ConditionalOStream to write output to. */ - TimerOutput (ConditionalOStream &stream, + TimerOutput (ConditionalOStream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type); - + #ifdef DEAL_II_COMPILER_SUPPORTS_MPI /** * Constructor that takes an MPI @@ -314,7 +314,7 @@ class TimerOutput * stream. */ TimerOutput (MPI_Comm mpi_comm, - std::ostream &stream, + std::ostream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type); @@ -330,7 +330,7 @@ class TimerOutput * ConditionalOStream to write output to. */ TimerOutput (MPI_Comm mpi_comm, - ConditionalOStream &stream, + ConditionalOStream &stream, const enum OutputFrequency output_frequency, const enum OutputType output_type); #endif @@ -348,13 +348,23 @@ class TimerOutput * exists, that section is done once * again. */ + void enter_subsection (const std::string §ion_name); + + /** + * Same as @p enter_subsection. + */ void enter_section (const std::string §ion_name); - /** + /** * Leave a section. If no name is given, * the last section that was entered is * left. */ + void leave_subsection (const std::string §ion_name = std::string()); + + /** + * Same as @p leave_subsection. + */ void exit_section (const std::string §ion_name = std::string()); /** @@ -458,6 +468,27 @@ class TimerOutput Threads::ThreadMutex mutex; }; + + +/* ---------------- inline functions ----------------- */ + +inline +void +TimerOutput::enter_section (const std::string §ion_name) +{ + enter_subsection(section_name); +} + + + +inline +void +TimerOutput::exit_section (const std::string §ion_name) +{ + leave_subsection(section_name); +} + + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/deal.II/base/source/timer.cc b/deal.II/base/source/timer.cc index 1fdef24ef0..5ca9c85aab 100644 --- a/deal.II/base/source/timer.cc +++ b/deal.II/base/source/timer.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include // these includes should probably be properly @@ -263,7 +264,7 @@ TimerOutput::TimerOutput (MPI_Comm mpi_communicator, TimerOutput::~TimerOutput() { while (active_sections.size() > 0) - exit_section(); + leave_subsection(); if (output_frequency != every_call && output_is_enabled == true) print_summary(); @@ -272,7 +273,7 @@ TimerOutput::~TimerOutput() void -TimerOutput::enter_section (const std::string §ion_name) +TimerOutput::enter_subsection (const std::string §ion_name) { Threads::ThreadMutex::ScopedLock lock (mutex); @@ -300,7 +301,7 @@ TimerOutput::enter_section (const std::string §ion_name) void -TimerOutput::exit_section (const std::string §ion_name) +TimerOutput::leave_subsection (const std::string §ion_name) { Assert (active_sections.size() > 0, ExcMessage("Cannot exit any section because none has been entered!")); @@ -424,14 +425,14 @@ TimerOutput::print_summary () const << "+---------------------------------------------+------------" << "+------------+\n" << "| Total CPU time elapsed since start |"; - std::cout.width(10); - std::cout.precision(3); + out_stream << std::setw(10); + out_stream << std::setprecision(3); out_stream << total_cpu_time << "s | |\n"; out_stream << "| | " << "| |\n"; out_stream << "| Section | no. calls |"; - std::cout.width(10); - std::cout.precision(3); + out_stream << std::setw(10); + out_stream << std::setprecision(3); out_stream << " CPU time " << " | % of total |\n"; out_stream << "+---------------------------------+-----------+------------" << "+------------+"; @@ -448,13 +449,13 @@ TimerOutput::print_summary () const out_stream << std::endl; out_stream << "| " << name_out; out_stream << "| "; - std::cout.width(9); + out_stream << std::setw(9); out_stream << i->second.n_calls << " |"; - std::cout.width(10); - std::cout.precision(3); + out_stream << std::setw(10); + out_stream << std::setprecision(3); out_stream << i->second.total_cpu_time << "s |"; - std::cout.width(10); - std::cout.precision(2); + out_stream << std::setw(10); + out_stream << std::setprecision(2); out_stream << i->second.total_cpu_time/total_cpu_time * 100 << "% |"; } out_stream << std::endl @@ -492,14 +493,14 @@ TimerOutput::print_summary () const << "+---------------------------------------------+------------" << "+------------+\n" << "| Total wallclock time elapsed since start |"; - std::cout.width(10); - std::cout.precision(3); + out_stream << std::setw(10); + out_stream << std::setprecision(3); out_stream << total_wall_time << "s | |\n"; out_stream << "| | " << "| |\n"; out_stream << "| Section | no. calls |"; - std::cout.width(10); - std::cout.precision(3); + out_stream << std::setw(10); + out_stream << std::setprecision(3); out_stream << " wall time | % of total |\n"; out_stream << "+---------------------------------+-----------+------------" << "+------------+"; @@ -516,13 +517,13 @@ TimerOutput::print_summary () const out_stream << std::endl; out_stream << "| " << name_out; out_stream << "| "; - std::cout.width(9); + out_stream << std::setw(9); out_stream << i->second.n_calls << " |"; - std::cout.width(10); - std::cout.precision(3); + out_stream << std::setw(10); + out_stream << std::setprecision(3); out_stream << i->second.total_wall_time << "s |"; - std::cout.width(10); - std::cout.precision(2); + out_stream << std::setw(10); + out_stream << std::setprecision(2); out_stream << i->second.total_wall_time/total_wall_time * 100 << "% |"; } out_stream << std::endl