From 00bfaf54c3ec0d8e5a0356cfc3b1978298c525d9 Mon Sep 17 00:00:00 2001 From: Eivind Fonn Date: Tue, 21 Sep 2021 15:48:15 +0200 Subject: [PATCH] Changed: allow profiler to optionally be silent --- src/Utility/Profiler.C | 5 +++-- src/Utility/Profiler.h | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Utility/Profiler.C b/src/Utility/Profiler.C index c9df2653..408fac0b 100644 --- a/src/Utility/Profiler.C +++ b/src/Utility/Profiler.C @@ -26,7 +26,7 @@ Profiler* utl::profiler = nullptr; -Profiler::Profiler (const std::string& name) : myName(name), nRunners(0) +Profiler::Profiler (const std::string& name, bool autoReport) : myName(name), autoReport(autoReport), nRunners(0) { #ifdef USE_OPENMP myMTimers.resize(omp_get_max_threads()); @@ -45,7 +45,8 @@ Profiler::Profiler (const std::string& name) : myName(name), nRunners(0) Profiler::~Profiler () { this->stop("Total"); - this->report(std::cout); + if (autoReport) + this->report(std::cout); IFEM::Close(); } diff --git a/src/Utility/Profiler.h b/src/Utility/Profiler.h index b3025478..2a7fc597 100644 --- a/src/Utility/Profiler.h +++ b/src/Utility/Profiler.h @@ -38,12 +38,13 @@ class Profiler public: //! \brief The constructor initializes the profiler object. //! \param[in] name Program name to be printed in the profiling report header. + //! \param[in] autoReport Automatically report results on program exit. //! //! \details The constructor also updates the global static pointer //! utl::profiler to point to \a *this, deleting any already pointed-to //! object first. This means, only one Profiler object can exist at any time. - explicit Profiler(const std::string& name); - //! \brief The destructor prints the profiling report to the console. + explicit Profiler(const std::string& name, bool autoReport = true); + //! \brief The destructor prints the profiling report to the console if requested. ~Profiler(); //! \brief Starts profiling of task \a funcName and increments \a nRunners. @@ -78,6 +79,7 @@ private: friend std::ostream& operator<<(std::ostream& os, const Profile& p); std::string myName; //!< Name of this profiler + bool autoReport; //!< Whether to report results on program exit typedef std::map ProfileMap; //!< Map of profilers