Skip to content

Commit

Permalink
Enable the verbosity in the time profiler machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi committed Aug 24, 2022
1 parent d49bdd1 commit 395ded1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
30 changes: 18 additions & 12 deletions devices/wholeBodyDynamics/TimeProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <numeric>
#include <iomanip>

#include <yarp/os/LogStream.h>

#include "TimeProfiler.h"

Expand All @@ -28,7 +29,7 @@ std::string printTimerDescription(const std::string& name, const TimerHandler::T
<< "|" << std::setw(15) << std::setprecision(13) << description.averageDuration.count()
<< "|" << std::setw(10) << std::setprecision(8) << description.timer.getInfo().deadlineMiss
<< "|" << std::setw(15) << std::setprecision(13) << description.timer.getInfo().latestDeadlineMissDuration.count()
<< "|";
<< "|" << std::endl;

return ss.str();
};
Expand Down Expand Up @@ -66,6 +67,11 @@ void Timer::setExpectedDuration(const std::chrono::duration<double>& expectedDur
m_exprectedDuration = expectedDuration;
}

const Timer::Info& Timer::getInfo() const
{
return m_info;
}

void TimerHandler::setHorizon(unsigned int horizon)
{
m_horizon = horizon;
Expand Down Expand Up @@ -119,41 +125,41 @@ void TimerHandler::profiling()
queue.push_back(duration);

// keep the queue size equal to horizon
if (queue.size() >= m_horizon)
if (queue.size() > m_horizon)
{
queue.pop_front();
}

// this should never happen
assert(queue.size() == m_horizon);
assert(queue.size() <= m_horizon);

timerDescription.averageDuration
= std::accumulate(std::next(queue.begin()), queue.end(), queue.front());
= std::accumulate(std::next(queue.begin()), queue.end(), queue.front()) / double(queue.size());
}

if(m_verbosity)
{
std::stringstream ss;
std::string output;
if(m_verbosityCounter == 0)
{
std::cout << "|" << std::setw(30) << "name |"
ss << "|" << std::setw(30) << "name |"
<< std::setw(15) << "tavarg (s) |"
<< std::setw(10) << "dm |"
<< std::setw(15) << "tdm (s) |" << std::endl;
std::cout << std::setfill('-') << "|" << std::setw(15) << "|"
<< std::setw(15) << "tdm (s) |" << std::endl
<< " " << std::setfill('-') << "|" << std::setw(30) << "|"
<< std::setw(15) << "|"
<< std::setw(10) << "|"
<< std::setw(15) << "|" << std::endl;

output = ss.str();

for (const auto& [name, timerDescription] : m_timers)
{
std::cout << printTimerDescription(name, timerDescription) << std::endl;
output += " " + printTimerDescription(name, timerDescription);
}

std::cout << std::setfill('-') << "|" << std::setw(30) << "|"
<< std::setw(15) << "|"
<< std::setw(10) << "|"
<< std::setw(15) << "|" << std::endl;
yDebug() << output;
}

m_verbosityCounter++ ;
Expand Down
4 changes: 2 additions & 2 deletions devices/wholeBodyDynamics/TimeProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Timer
unsigned int deadlineMiss{0}; /**< Number of deadline miss */
std::string name{"Timer"}; /**< Name associated to the timer */
bool dealineMissDetected{false};
std::chrono::duration<double> latestDeadlineMissDuration; /**< Average duration. */
std::chrono::duration<double> duration; /**< Latest duration. */
std::chrono::duration<double> latestDeadlineMissDuration{0}; /**< Average duration. */
std::chrono::duration<double> duration{0}; /**< Latest duration. */
};

Timer(const std::string& name, const std::chrono::duration<double>& expectedDuration);
Expand Down
2 changes: 1 addition & 1 deletion devices/wholeBodyDynamics/WholeBodyDynamicsDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ bool WholeBodyDynamicsDevice::open(os::Searchable& config)
m_timerHandler.addTimer("all",
WholeBodyDynamics::Timer("all",
std::chrono::duration<double>(getPeriod())));

m_timerHandler.setVerbosity(true);
yDebug() << "wholeBodyDynamics Statistics: Configuration finished. Waiting attachAll to be called.";

return true;
Expand Down

0 comments on commit 395ded1

Please sign in to comment.