Skip to content

Commit

Permalink
Refactored the TreeNode::executeTick() function to use a scoped timer…
Browse files Browse the repository at this point in the history
… for performance monitoring. (BehaviorTree#861)

Update src/tree_node.cpp

Co-authored-by: Davide Faconti <davide.faconti@gmail.com>
  • Loading branch information
wangzheng and facontidavide committed Sep 6, 2024
1 parent 4f66447 commit becc779
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/tree_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,19 @@ NodeStatus TreeNode::executeTick()
if(!substituted)
{
using namespace std::chrono;

auto t1 = steady_clock::now();
// trick to prevent the compile from reordering the order of execution. See #861
// This makes sure that the code is executed at the end of this scope
std::shared_ptr<void> execute_later(nullptr, [&](...) {
auto t2 = steady_clock::now();
if(monitor_tick)
{
monitor_tick(*this, new_status, duration_cast<microseconds>(t2 - t1));
}
});

new_status = tick();
auto t2 = steady_clock::now();
if(monitor_tick)
{
monitor_tick(*this, new_status, duration_cast<microseconds>(t2 - t1));
}
}
}

Expand Down

0 comments on commit becc779

Please sign in to comment.