From 16dbd21e9063b22f4dd66d6f5d945c6c055ed07e Mon Sep 17 00:00:00 2001 From: Christoph Rettinger <christoph.rettinger@fau.de> Date: Thu, 14 Jun 2018 16:41:35 +0200 Subject: [PATCH] Added functionality to timers and fixed docu typos --- src/core/timing/TimingNode.h | 27 ++++++++++++++++++++++++++- src/core/timing/TimingTree.h | 21 ++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/core/timing/TimingNode.h b/src/core/timing/TimingNode.h index 2f0597f7a..6f880d7e4 100644 --- a/src/core/timing/TimingNode.h +++ b/src/core/timing/TimingNode.h @@ -111,7 +111,7 @@ void TimingNode<TP>::swap(TimingNode<TP>& tt) } } -/// Finds the spezified timer in the timing hierarchy +/// Finds the specified timer in the timing hierarchy /// \param name timer name which may include more than one hierarchy separated by "." /// \code findTimer(tn, "firstLevel.secondLevel.thirdLevel.timerName"); \endcode /// \relates TimingNode @@ -130,6 +130,31 @@ const Timer<TP>& findTimer( const TimingNode<TP>& tn, const std::string& name) } } +/// Checks if the specified timer exists in the timing hierarchy +/// \param name timer name which may include more than one hierarchy separated by "." +/// \code timerExists(tn, "firstLevel.secondLevel.thirdLevel.timerName"); \endcode +/// \relates TimingNode +template< typename TP > // Timing policy +bool timerExists( const TimingNode<TP>& tn, const std::string& name ) +{ + auto pos = name.find_first_of("."); + if (pos != std::string::npos) + { + if( tn.tree_.find(name.substr(0, pos)) != tn.tree_.end() ) + { + return timerExists( tn.tree_.at(name.substr(0, pos)), name.substr(pos+1, std::string::npos)); + } + else + { + return false; + } + } + else + { + return tn.tree_.find(name) != tn.tree_.end(); + } +} + /// Resets the timer in the TimingNode structure and all sub timers /// \relates TimingNode template< typename TP > // Timing policy diff --git a/src/core/timing/TimingTree.h b/src/core/timing/TimingTree.h index f34fc7f88..7e1e59c5b 100644 --- a/src/core/timing/TimingTree.h +++ b/src/core/timing/TimingTree.h @@ -59,13 +59,13 @@ public: void swap(TimingTree<TP>& tt); - /// Starts a timer beneath the current hirarchy level + /// Starts a timer beneath the current hierarchy level void start(const std::string& name); - /// Stops the last started timer and jumps back one hirarchy level + /// Stops the last started timer and jumps back one hierarchy level void stop(const std::string& name); /// Checks if specified timer is currently running. bool isTimerRunning(const std::string& name) const; - /// Resets the the timing hirarchy + /// Resets the the timing hierarchy void reset(); //** Reduction ****************************************************************************************************** @@ -81,7 +81,9 @@ public: /// Returns the raw tree data structure const TimingNode<TP>& getRawData() const; + const Timer<TP>& operator[](const std::string& name) const; + inline bool timerExists ( const std::string & n ) const; /// Returns the name of the currently running timer /// Might be expensive due to value search. @@ -89,7 +91,7 @@ public: private: /// Tree data structure TimingNode<TP> root_; - /// Pointer to the current hirarchy level. + /// Pointer to the current hierarchy level. TimingNode<TP>* current_; }; @@ -204,7 +206,7 @@ const TimingNode<TP>& TimingTree<TP>::getRawData() const return root_; } -/// Finds the spezified timer in the timing hierarchy +/// Finds the specified timer in the timing hierarchy /// \param name timer name which may include more than one hierarchy separated by "." /// \code tt["firstLevel.secondLevel.thirdLevel.timerName"].total(); \endcode template< typename TP > // Timing policy @@ -213,6 +215,15 @@ const Timer<TP>& TimingTree<TP>::operator[](const std::string& name) const return findTimer(root_, name); } +/// Checks if the specified timer exists in the timing hierarchy +/// \param name timer name which may include more than one hierarchy separated by "." +/// \code tt.timerExists("firstLevel.secondLevel.thirdLevel.timerName"); \endcode +template< typename TP > // Timing policy +bool TimingTree<TP>::timerExists(const std::string& name) const +{ + return walberla::timing::timerExists(root_, name); +} + template< typename TP > // Timing policy std::string TimingTree<TP>::getCurrentTimerName() const { -- GitLab