RDKEMW-7226: Add Logs to identify the delay in shutdown sequence#274
RDKEMW-7226: Add Logs to identify the delay in shutdown sequence#274yogeswaransky wants to merge 13 commits intodevelopfrom
Conversation
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds logging and timing measurements for the telemetry2_0 shutdown sequence to help diagnose shutdown performance issues. The changes instrument both the systemd service shutdown process and the internal C application termination to capture timing information.
Changes:
- Added shutdown timing logs in systemd service file (ExecStop/ExecStopPost) that measure the time from stop initiation to completion
- Added shutdown timing logs in C code (terminate function) that measure internal cleanup duration
- Introduced timestamp-based duration calculation using temporary file for systemd-level timing
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| telemetry2_0.service | Added ExecStop and ExecStopPost commands that log shutdown initiation and completion with elapsed time calculation |
| source/telemetry2_0.c | Added timing instrumentation in terminate() function to log shutdown start, end, and duration in milliseconds |
Comments suppressed due to low confidence (1)
source/telemetry2_0.c:112
- The variable name t2 is less descriptive than t_start. Consider renaming t2 to t_end for improved code readability and consistency.
struct timespec t2, t_start;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
| else if ( sig == SIGTERM || sig == SIGKILL ) | ||
| { | ||
| if ( sig == SIGTERM ) | ||
| { | ||
| T2Info(("SIGTERM received!\n")); |
There was a problem hiding this comment.
SIGKILL cannot be caught or handled (it will never reach this handler). Treating it like a catchable termination signal and logging "SIGKILL received" is misleading; remove SIGKILL from this condition/logging and handle only signals that can be delivered to sigaction (e.g., SIGTERM).
| else if ( sig == SIGTERM || sig == SIGKILL ) | ||
| { | ||
| if ( sig == SIGTERM ) | ||
| { | ||
| T2Info(("SIGTERM received!\n")); | ||
| } | ||
| else | ||
| { | ||
| T2Info(("SIGKILL received!\n")); | ||
| } |
There was a problem hiding this comment.
sig_handler() logs and branches on SIGKILL, but SIGKILL cannot be caught/handled and is never registered via sigaction() (only SIGTERM is). This makes the SIGKILL received log path effectively dead and may mislead anyone debugging shutdown. Consider removing SIGKILL from the condition/logs (or replace with a catchable signal such as SIGQUIT if that’s the intent).
| void sig_handler(int sig, siginfo_t* info, void* uc) | ||
| { | ||
| T2Info("%s ++in\n", __FUNCTION__); |
There was a problem hiding this comment.
The newly added T2Info("%s --out") at the end of sig_handler() won’t execute for the shutdown/crash paths because those branches call exit(0) before reaching the end. If the intent is to bracket the handler, move the --out log before each exit() (or only log --out on the non-exiting paths) to avoid misleading logs.
| clock_gettime(CLOCK_MONOTONIC, &t2); | ||
| T2Info("=== [SHUTDOWN] telemetry2_0 shutdown complete, total=%lldms ===\n", | ||
| (long long)(t2.tv_sec - t_start.tv_sec) * 1000 + (t2.tv_nsec - t_start.tv_nsec) / 1000000LL); |
There was a problem hiding this comment.
terminate() calls clock_gettime() again for the end timestamp without checking for errors. If clock_gettime fails here, the computed shutdown duration can be garbage/negative. Please check the return value and only emit the total=...ms log when both timestamps are valid.
| void uninitXConfClient() | ||
| { | ||
| T2Debug("%s ++in\n", __FUNCTION__); | ||
| T2Info("%s ++in\n", __FUNCTION__); |
There was a problem hiding this comment.
uninitXConfClient() now logs function entry at T2Info, but the matching exit log remains T2Debug later in the function. This makes shutdown tracing harder because the entry/exit pair won’t appear at the same log level. Consider using the same level for both (either keep both T2Debug or promote both to T2Info).
| T2Info("%s ++in\n", __FUNCTION__); | |
| T2Debug("%s ++in\n", __FUNCTION__); |
| void sig_handler(int sig, siginfo_t* info, void* uc) | ||
| { | ||
| T2Info("%s ++in\n", __FUNCTION__); | ||
| if(DAEMONPID == getpid()) |
There was a problem hiding this comment.
sig_handler() is a real signal handler (registered via sigaction with SA_SIGINFO), but the newly added T2Info() entry/exit logging is not async-signal-safe. This can deadlock/crash if the signal interrupts logging or holds internal locks (especially during shutdown). Prefer making the handler minimal (set a volatile sig_atomic_t flag / write to a self-pipe) and perform logging + terminate() from the main loop/thread context.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
source/xconf-client/xconfclient.c:1084
uninitXConfClient()now logs entry atT2Info, but the function still logs--outatT2Debuglater. For shutdown sequencing/timing logs, it would be clearer to keep entry/exit at the same level (either both Info or both Debug).
T2Info("%s ++in\n", __FUNCTION__);
pthread_mutex_lock(&xcThreadMutex);
if(!stopFetchRemoteConfiguration)
{
stopFetchRemoteConfiguration = true;
pthread_mutex_unlock(&xcThreadMutex);
T2Info("fetchRemoteConfigurationThread signalled to stop\n");
No description provided.