loop: metrics

This commit is contained in:
Michele Caini 2023-05-19 14:57:15 +02:00
parent f86c810aea
commit 426988b000
3 changed files with 22 additions and 0 deletions

View File

@ -87,6 +87,12 @@ UVW_INLINE loop::time loop::idle_time() const noexcept {
return time{uv_metrics_idle_time(uv_loop.get())};
}
UVW_INLINE metrics_type loop::metrics() const noexcept {
metrics_type res{};
uv_metrics_info(uv_loop.get(), &res);
return res;
}
UVW_INLINE loop::time loop::now() const noexcept {
return time{uv_now(uv_loop.get())};
}

View File

@ -47,6 +47,8 @@ enum class uvw_run_mode : std::underlying_type_t<uv_run_mode> {
} // namespace details
using metrics_type = uv_metrics_t; /*!< Library equivalent for uv_metrics_t. */
/**
* @brief The loop class.
*
@ -236,6 +238,12 @@ public:
*/
time idle_time() const noexcept;
/**
* @brief Tracks various internal operations of the event loop.
* @return Event loop metrics.
*/
metrics_type metrics() const noexcept;
/**
* @brief Returns the current timestamp in milliseconds.
*

View File

@ -124,6 +124,14 @@ TEST(Loop, IdleTime) {
ASSERT_EQ(0, loop->close());
}
TEST(Loop, Metrics) {
auto loop = uvw::loop::create();
uvw::metrics_type metrics = loop->metrics();
ASSERT_EQ(0, metrics.loop_count);
ASSERT_EQ(0, metrics.events);
ASSERT_EQ(0, metrics.events_waiting);
}
TEST(Loop, Raw) {
auto loop = uvw::loop::get_default();
const auto &cloop = uvw::loop::get_default();