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. (#861) (#863)

Update src/tree_node.cpp

Co-authored-by: wangzheng <[email protected]>
Co-authored-by: Davide Faconti <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2024
1 parent c9dea7b commit 1fcb624
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 1fcb624

Please sign in to comment.