* 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
*
* 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
* +---------------------------------+-----------+------------+------------+
* @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.
* 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);
* 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
* stream.
*/
TimerOutput (MPI_Comm mpi_comm,
- std::ostream &stream,
+ std::ostream &stream,
const enum OutputFrequency output_frequency,
const enum OutputType output_type);
* 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
* 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());
/**
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
#include <base/timer.h>
#include <base/exceptions.h>
#include <iostream>
+#include <iomanip>
#include <algorithm>
// these includes should probably be properly
TimerOutput::~TimerOutput()
{
while (active_sections.size() > 0)
- exit_section();
+ leave_subsection();
if (output_frequency != every_call && output_is_enabled == true)
print_summary();
void
-TimerOutput::enter_section (const std::string §ion_name)
+TimerOutput::enter_subsection (const std::string §ion_name)
{
Threads::ThreadMutex::ScopedLock lock (mutex);
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!"));
<< "+---------------------------------------------+------------"
<< "+------------+\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 << "+---------------------------------+-----------+------------"
<< "+------------+";
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
<< "+---------------------------------------------+------------"
<< "+------------+\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 << "+---------------------------------+-----------+------------"
<< "+------------+";
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