Skip to content
Snippets Groups Projects
Commit ddd2c7b7 authored by Christoph Rettinger's avatar Christoph Rettinger
Browse files

Merge branch 'timing_utils' into 'master'

Added functionality to timers and fixed docu typos

See merge request walberla/walberla!115
parents 58c2c457 b0aac68c
No related merge requests found
......@@ -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
......
......@@ -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
{
......
......@@ -13,7 +13,7 @@
// You should have received a copy of the GNU General Public License along
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file TimingPoolTest.cpp
//! \file TimingTreeTest.cpp
//! \ingroup core
//! \author Martin Bauer <martin.bauer@fau.de>
//
......@@ -67,12 +67,36 @@ int main( int argc, char ** argv )
tt.stop("AC");
tt.stop("A");
WALBERLA_ASSERT(tt.timerExists("A"));
WALBERLA_ASSERT(tt.timerExists("A.AA"));
WALBERLA_ASSERT(tt.timerExists("A.AB.ABA"));
WALBERLA_ASSERT(tt.timerExists("A.AB.ABB"));
WALBERLA_ASSERT(tt.timerExists("A.AC.ACA"));
WALBERLA_ASSERT(!tt.timerExists("AAC"));
WALBERLA_ASSERT(!tt.timerExists("A.AA.C"));
// check copy constructor
timing::TimingTree<timing::StaticPolicy> tt2(tt);
// check assignment operator
timing::TimingTree<timing::StaticPolicy> tt3;
tt3 = tt;
WALBERLA_ASSERT(tt2.timerExists("A"));
WALBERLA_ASSERT(tt2.timerExists("A.AA"));
WALBERLA_ASSERT(tt2.timerExists("A.AB.ABA"));
WALBERLA_ASSERT(tt2.timerExists("A.AB.ABB"));
WALBERLA_ASSERT(tt2.timerExists("A.AC.ACA"));
WALBERLA_ASSERT(!tt2.timerExists("AAC"));
WALBERLA_ASSERT(!tt2.timerExists("A.AA.C"));
WALBERLA_ASSERT(tt3.timerExists("A"));
WALBERLA_ASSERT(tt3.timerExists("A.AA"));
WALBERLA_ASSERT(tt3.timerExists("A.AB.ABA"));
WALBERLA_ASSERT(tt3.timerExists("A.AB.ABB"));
WALBERLA_ASSERT(tt3.timerExists("A.AC.ACA"));
WALBERLA_ASSERT(!tt3.timerExists("AAC"));
WALBERLA_ASSERT(!tt3.timerExists("A.AA.C"));
tt2 = tt.getReduced( timing::REDUCE_TOTAL, 0 );
tt2 = tt.getReduced( timing::REDUCE_TOTAL, 1 );
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment