Skip to content

Commit

Permalink
Print all the timers when a deadline miss is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRomualdi committed Aug 24, 2022
1 parent 395ded1 commit 09a87b9
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions devices/wholeBodyDynamics/TimeProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,26 @@

#include <cassert>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <numeric>
#include <iomanip>

#include <yarp/os/LogStream.h>

#include "TimeProfiler.h"

using namespace WholeBodyDynamics;



std::string printTimerDescription(const std::string& name, const TimerHandler::TimerDescription& description)
std::string
printTimerDescription(const std::string& name, const TimerHandler::TimerDescription& description)
{
std::stringstream ss;
ss << "|" << std::setw(30) << name
<< "|" << 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;
ss << "|" << std::setw(30) << name << "|" << 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 @@ -104,7 +102,6 @@ bool TimerHandler::toc(const std::string& key)
return false;
}


it->second.timer.toc();
return true;
}
Expand All @@ -116,10 +113,13 @@ void TimerHandler::setVerbosity(bool verbosity)

void TimerHandler::profiling()
{
bool deadlineMissDetected = false;
for (auto& [name, timerDescription] : m_timers)
{
const auto& duration = timerDescription.timer.getInfo().duration;

deadlineMissDetected = deadlineMissDetected || timerDescription.timer.getInfo().dealineMissDetected;

// this automatically create the element if does bot exist
auto& queue = m_durations[name];
queue.push_back(duration);
Expand All @@ -134,36 +134,52 @@ void TimerHandler::profiling()
assert(queue.size() <= m_horizon);

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

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

ss << "|" << std::setw(30) << "name |" << std::setw(15) << "tavarg (s) |"
<< std::setw(10) << "dm |" << 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();
output = ss.str();

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

yDebug() << output;
yDebug() << output;
}

if (deadlineMissDetected)
{
std::stringstream ss;
std::string output;

ss << "---------------------------------- Deadline miss detected ----------------------------------" << std::endl;
ss << "|" << std::setw(30) << "name |" << std::setw(15) << "t (s) |" << std::endl
<< " " << std::setfill('-') << "|" << std::setw(30) << "|" << std::setw(15) << std::endl;

for (const auto& [name, timerDescription] : m_timers)
{
ss << "|" << std::setw(30) << name << "|" << std::setw(15) << std::setprecision(13)
<< timerDescription.timer.getInfo().duration.count() << std::endl;
}

yDebug() << ss.str();
}

m_verbosityCounter++ ;
if(m_verbosityCounter == m_horizon)
m_verbosityCounter++;
if (m_verbosityCounter == m_horizon)
m_verbosityCounter = 0;
}
}

0 comments on commit 09a87b9

Please sign in to comment.