Skip to content

Commit

Permalink
return execution time in nanoseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Oct 31, 2024
1 parent a11e9cf commit ce67ac3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/realtime_tools/async_function_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class AsyncFunctionHandler
std::unique_lock<std::mutex> lock(async_mtx_);
stop_async_callback_ = false;
trigger_in_progress_ = false;
last_execution_time_ = 0.0;
last_execution_time_ = std::chrono::nanoseconds(0);
async_callback_return_ = T();
async_exception_ptr_ = nullptr;
}
Expand Down Expand Up @@ -247,9 +247,12 @@ class AsyncFunctionHandler

/// Get the last execution time of the async callback method
/**
* @return The last execution time of the async callback method in seconds
* @return The last execution time of the async callback method in nanoseconds
*/
double get_last_execution_time() const { return last_execution_time_; }
std::chrono::nanoseconds get_last_execution_time() const
{
return last_execution_time_.load(std::memory_order_relaxed);
}

/// Initializes and starts the callback thread
/**
Expand Down Expand Up @@ -289,7 +292,8 @@ class AsyncFunctionHandler
async_exception_ptr_ = std::current_exception();
}
const auto end_time = std::chrono::steady_clock::now();
last_execution_time_ = std::chrono::duration<double>(end_time - start_time).count();
last_execution_time_ =
std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
}
trigger_in_progress_ = false;
}
Expand All @@ -315,7 +319,7 @@ class AsyncFunctionHandler
std::condition_variable async_callback_condition_;
std::condition_variable cycle_end_condition_;
std::mutex async_mtx_;
std::atomic<double> last_execution_time_;
std::atomic<std::chrono::nanoseconds> last_execution_time_;
std::exception_ptr async_exception_ptr_;
};
} // namespace realtime_tools
Expand Down

0 comments on commit ce67ac3

Please sign in to comment.