Skip to content

Commit

Permalink
Merge pull request #1337 from jmirabel/devel
Browse files Browse the repository at this point in the history
Further improve profiler.
  • Loading branch information
cmastalli authored Jan 28, 2025
2 parents 9a1146f + 109a203 commit ddb555f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 11 additions & 3 deletions include/crocoddyl/core/utils/stop-watch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ class Stopwatch {

Watcher(Stopwatch &_w, std::string _n, PerformanceData *_p)
: w(_w), n(_n), p(_p) {}
void start();
void stop();
inline void start() {
if (w.profiler_active) _start();
}
inline void stop() {
if (w.profiler_active) _stop();
}

private:
void _start();
void _stop();
};

/** @brief Constructor */
Expand All @@ -180,7 +188,7 @@ class Stopwatch {
void disable_profiler();

/** @brief Return if the profiler is enable or disable **/
bool profiler_status();
inline bool profiler_status() { return profiler_active; }

/** @brief Tells if a performance with a certain ID exists */
bool performance_exists(std::string perf_name);
Expand Down
6 changes: 2 additions & 4 deletions src/core/utils/stop-watch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ void Stopwatch::enable_profiler() { profiler_active = true; }

void Stopwatch::disable_profiler() { profiler_active = false; }

bool Stopwatch::profiler_status() { return profiler_active; }

void Stopwatch::set_mode(StopwatchMode new_mode) { mode = new_mode; }

bool Stopwatch::performance_exists(string perf_name) {
Expand Down Expand Up @@ -347,7 +345,7 @@ Stopwatch::Watcher Stopwatch::watcher(const string& perf_name) {
return Watcher(*this, perf_name, perf_info);
}

void Stopwatch::Watcher::start() {
void Stopwatch::Watcher::_start() {
if (!w.profiler_active) return;

if (p == nullptr) {
Expand All @@ -358,7 +356,7 @@ void Stopwatch::Watcher::start() {
p->paused = false;
}

void Stopwatch::Watcher::stop() {
void Stopwatch::Watcher::_stop() {
if (!w.profiler_active || (p == nullptr)) return;

long double clock_end = w.take_time();
Expand Down

0 comments on commit ddb555f

Please sign in to comment.