From 32f51741bdef7e455b2b2d0dd62dda4c1ce2422c Mon Sep 17 00:00:00 2001 From: wujianlin Date: Tue, 13 May 2025 15:00:44 +0800 Subject: [PATCH] Add the maintenance and measurement information of the TimeOut exception scenario of TimerEventHandler Issue:https://gitee.com/openharmony/commonlibrary_c_utils/issues/IC7FBD?from=project-issue Signed-off-by: wujianlin --- base/src/timer_event_handler.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/base/src/timer_event_handler.cpp b/base/src/timer_event_handler.cpp index 75e7d41..be6c1ab 100644 --- a/base/src/timer_event_handler.cpp +++ b/base/src/timer_event_handler.cpp @@ -98,8 +98,17 @@ void TimerEventHandler::TimeOut() uint64_t expirations = 0; ssize_t n = ::read(GetHandle(), &expirations, sizeof(expirations)); if (n != sizeof(expirations)) { - UTILS_LOGE("epoll_loop::on_timer() reads %{public}d bytes instead of 8, errno=%{public}d", static_cast(n), - errno); + int erronRead = errno; + struct itimerspec current = { + .it_interval = {.tv_sec = -1, .tv_nsec = -1}, + .it_value = {.tv_sec = -1, .tv_nsec = -1} + }; + if (timerfd_gettime(GetHandle(), ¤t) == -1) { + UTILS_LOGE("timerfd_gettime failed, errno=%{public}d", errno); + } + UTILS_LOGE("epoll_loop::on_timer() reads %{public}d bytes instead of 8, timerFd=%{public}d, errno=%{public}d, " + "Current timer value: %{public}lld sec, %{public}ld nsec", static_cast(n), GetHandle(), + erronRead, current.it_value.tv_sec, current.it_value.tv_nsec); } if (callback_) { callback_(GetHandle()); -- Gitee