Skip to content

RDKEMW-7226: Add Logs to identify the delay in shutdown sequence#274

Open
yogeswaransky wants to merge 13 commits intodevelopfrom
topic/RDKEMW-7226
Open

RDKEMW-7226: Add Logs to identify the delay in shutdown sequence#274
yogeswaransky wants to merge 13 commits intodevelopfrom
topic/RDKEMW-7226

Conversation

@yogeswaransky
Copy link
Copy Markdown
Contributor

No description provided.

Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
@yogeswaransky yogeswaransky requested a review from a team as a code owner February 27, 2026 09:22
Copilot AI review requested due to automatic review settings February 27, 2026 09:22
@yogeswaransky yogeswaransky changed the title RDKEMW-7226: Add Logs to caluculate time for shutdown sequence RDKEMW-7226: Add Logs to calculate time for shutdown sequence Feb 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread source/telemetry2_0.c Outdated
Comment thread telemetry2_0.service Outdated
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Comment thread source/telemetry2_0.c
Comment thread source/telemetry2_0.c
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
Copilot AI review requested due to automatic review settings March 4, 2026 08:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread source/telemetry2_0.c Outdated
Comment thread source/telemetry2_0.c
Copilot AI review requested due to automatic review settings April 9, 2026 09:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread source/telemetry2_0.c
Comment thread source/telemetry2_0.c
Copilot AI review requested due to automatic review settings April 9, 2026 10:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread source/telemetry2_0.c
Copilot AI review requested due to automatic review settings April 9, 2026 10:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Comment thread source/telemetry2_0.c
Comment thread source/telemetry2_0.c
Comment on lines 228 to +232
else if ( sig == SIGTERM || sig == SIGKILL )
{
if ( sig == SIGTERM )
{
T2Info(("SIGTERM received!\n"));
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread source/telemetry2_0.c
Comment thread source/telemetry2_0.c
Comment thread source/telemetry2_0.c
Copilot AI review requested due to automatic review settings April 9, 2026 10:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread source/telemetry2_0.c
Comment on lines 228 to +237
else if ( sig == SIGTERM || sig == SIGKILL )
{
if ( sig == SIGTERM )
{
T2Info(("SIGTERM received!\n"));
}
else
{
T2Info(("SIGKILL received!\n"));
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread source/telemetry2_0.c
Comment on lines 175 to +177
void sig_handler(int sig, siginfo_t* info, void* uc)
{
T2Info("%s ++in\n", __FUNCTION__);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread source/telemetry2_0.c
Comment on lines +139 to +141
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);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
void uninitXConfClient()
{
T2Debug("%s ++in\n", __FUNCTION__);
T2Info("%s ++in\n", __FUNCTION__);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
T2Info("%s ++in\n", __FUNCTION__);
T2Debug("%s ++in\n", __FUNCTION__);

Copilot uses AI. Check for mistakes.
Comment thread source/telemetry2_0.c
Comment on lines 175 to 178
void sig_handler(int sig, siginfo_t* info, void* uc)
{
T2Info("%s ++in\n", __FUNCTION__);
if(DAEMONPID == getpid())
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 9, 2026 11:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 at T2Info, but the function still logs --out at T2Debug later. 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");

@yogeswaransky yogeswaransky changed the title RDKEMW-7226: Add Logs to calculate time for shutdown sequence RDKEMW-7226: Add Logs to identify the delay in shutdown sequence Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants