From 18834182f3a7dc666b20abc218cd8bb6cac87cf6 Mon Sep 17 00:00:00 2001 From: shivabhaskar Date: Thu, 13 Nov 2025 16:29:03 +0530 Subject: [PATCH 1/3] RDKEMW-10467: Fix Invalid time values caused by drift use CLOCK_MONOTONIC Reason for Change: Changing CLOCK_REALTIME to CLOCK_MONOTONIC to avoid clock drifts impact in the calculations Test Procedure: When Telemetry report generation is in progress change the time. The processing time should have a valid value Risks: Low Priority: P1 --- source/bulkdata/profile.c | 4 ++-- source/bulkdata/profilexconf.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/bulkdata/profile.c b/source/bulkdata/profile.c index f5d9bb17..faedbe37 100644 --- a/source/bulkdata/profile.c +++ b/source/bulkdata/profile.c @@ -374,7 +374,7 @@ static void* CollectAndReport(void* data) T2Info("%s ++in profileName : %s\n", __FUNCTION__, profile->name); - clock_gettime(CLOCK_REALTIME, &startTime); + clock_gettime(CLOCK_MONOTONIC, &startTime); if( !strcmp(profile->encodingType, "JSON") || !strcmp(profile->encodingType, "MessagePack")) { JSONEncoding *jsonEncoding = profile->jsonEncoding; @@ -749,7 +749,7 @@ static void* CollectAndReport(void* data) { T2Error("Unsupported encoding format : %s\n", profile->encodingType); } - clock_gettime(CLOCK_REALTIME, &endTime); + clock_gettime(CLOCK_MONOTONIC, &endTime); getLapsedTime(&elapsedTime, &endTime, &startTime); T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long )elapsedTime.tv_sec, elapsedTime.tv_nsec); if(ret == T2ERROR_SUCCESS && jsonReport) diff --git a/source/bulkdata/profilexconf.c b/source/bulkdata/profilexconf.c index 69c94d04..8d97c245 100644 --- a/source/bulkdata/profilexconf.c +++ b/source/bulkdata/profilexconf.c @@ -248,7 +248,7 @@ static void* CollectAndReportXconf(void* data) } - clock_gettime(CLOCK_REALTIME, &startTime); + clock_gettime(CLOCK_MONOTONIC, &startTime); if(profile->encodingType != NULL && !strcmp(profile->encodingType, "JSON")) { if(T2ERROR_SUCCESS != initJSONReportXconf(&profile->jsonReportObj, &valArray)) @@ -304,13 +304,13 @@ static void* CollectAndReportXconf(void* data) encodeEventMarkersInJSON(valArray, profile->eMarkerList); } profile->grepSeekProfile->execCounter += 1; - T2Info("Execution Count = %d\n", profile->grepSeekProfile->execCounter); + T2Info("Xconf Profile Execution Count = %d\n", profile->grepSeekProfile->execCounter); ret = prepareJSONReport(profile->jsonReportObj, &jsonReport); destroyJSONReport(profile->jsonReportObj); profile->jsonReportObj = NULL; - clock_gettime(CLOCK_REALTIME, &endTime); - T2Info("Processing time for profile %s is %ld seconds\n", profile->name, (long)(endTime.tv_sec - startTime.tv_sec)); + clock_gettime(CLOCK_MONOTONIC, &endTime); + T2Info("%s Xconf Profile Processing Time in seconds : %ld\n", profile->name, (long)(endTime.tv_sec - startTime.tv_sec)); if(ret != T2ERROR_SUCCESS) { T2Error("Unable to generate report for : %s\n", profile->name); @@ -451,7 +451,7 @@ static void* CollectAndReportXconf(void* data) T2Warning("Failed to save grep config to file for profile: %s\n", profile->name); } #endif - clock_gettime(CLOCK_REALTIME, &endTime); + clock_gettime(CLOCK_MONOTONIC, &endTime); getLapsedTime(&elapsedTime, &endTime, &startTime); T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long)elapsedTime.tv_sec, elapsedTime.tv_nsec); if(jsonReport) From ec64c379904f760b0121e4a84cf8bbf8aa9d60c1 Mon Sep 17 00:00:00 2001 From: shivabhaskar Date: Mon, 24 Nov 2025 16:33:59 +0530 Subject: [PATCH 2/3] Coverity Fix --- source/bulkdata/profilexconf.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/source/bulkdata/profilexconf.c b/source/bulkdata/profilexconf.c index 8d97c245..6b8efc07 100644 --- a/source/bulkdata/profilexconf.c +++ b/source/bulkdata/profilexconf.c @@ -247,8 +247,8 @@ static void* CollectAndReportXconf(void* data) T2Info("%s ++in profileName : %s\n", __FUNCTION__, profile->name); } - - clock_gettime(CLOCK_MONOTONIC, &startTime); + int clockReturn = 0; + clockReturn = clock_gettime(CLOCK_MONOTONIC, &startTime); if(profile->encodingType != NULL && !strcmp(profile->encodingType, "JSON")) { if(T2ERROR_SUCCESS != initJSONReportXconf(&profile->jsonReportObj, &valArray)) @@ -309,8 +309,16 @@ static void* CollectAndReportXconf(void* data) ret = prepareJSONReport(profile->jsonReportObj, &jsonReport); destroyJSONReport(profile->jsonReportObj); profile->jsonReportObj = NULL; - clock_gettime(CLOCK_MONOTONIC, &endTime); - T2Info("%s Xconf Profile Processing Time in seconds : %ld\n", profile->name, (long)(endTime.tv_sec - startTime.tv_sec)); + clockReturn |= clock_gettime(CLOCK_MONOTONIC, &endTime); + if(clockReturn) + { + T2Warning("Error in Fetching the time Elapsed"); + } + else + { + T2Info("%s Xconf Profile Processing Time in seconds : %ld\n", profile->name, (long)(endTime.tv_sec - startTime.tv_sec)); + } + if(ret != T2ERROR_SUCCESS) { T2Error("Unable to generate report for : %s\n", profile->name); @@ -451,9 +459,17 @@ static void* CollectAndReportXconf(void* data) T2Warning("Failed to save grep config to file for profile: %s\n", profile->name); } #endif - clock_gettime(CLOCK_MONOTONIC, &endTime); - getLapsedTime(&elapsedTime, &endTime, &startTime); - T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long)elapsedTime.tv_sec, elapsedTime.tv_nsec); + clockReturn |= clock_gettime(CLOCK_MONOTONIC, &endTime); + if (clockReturn) + { + T2Warning("Error in Fetching the time Elapsed"); + } + else + { + getLapsedTime(&elapsedTime, &endTime, &startTime); + T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long)elapsedTime.tv_sec, elapsedTime.tv_nsec); + } + if(jsonReport) { free(jsonReport); From d048d01c93957c13b5b8ff31ce9950364a645f54 Mon Sep 17 00:00:00 2001 From: shivabhaskar Date: Mon, 24 Nov 2025 18:14:17 +0530 Subject: [PATCH 3/3] Fix Formatting and Coverity --- source/bulkdata/profile.c | 18 ++++++++++++------ source/bulkdata/profilexconf.c | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/bulkdata/profile.c b/source/bulkdata/profile.c index faedbe37..27e2872b 100644 --- a/source/bulkdata/profile.c +++ b/source/bulkdata/profile.c @@ -349,8 +349,7 @@ static void* CollectAndReport(void* data) struct timespec endTime; struct timespec elapsedTime; char* customLogPath = NULL; - - + int clockReturn = 0; T2ERROR ret = T2ERROR_FAILURE; if( profile->name == NULL || profile->encodingType == NULL || profile->protocol == NULL ) @@ -374,7 +373,7 @@ static void* CollectAndReport(void* data) T2Info("%s ++in profileName : %s\n", __FUNCTION__, profile->name); - clock_gettime(CLOCK_MONOTONIC, &startTime); + clockReturn = clock_gettime(CLOCK_MONOTONIC, &startTime); if( !strcmp(profile->encodingType, "JSON") || !strcmp(profile->encodingType, "MessagePack")) { JSONEncoding *jsonEncoding = profile->jsonEncoding; @@ -749,9 +748,16 @@ static void* CollectAndReport(void* data) { T2Error("Unsupported encoding format : %s\n", profile->encodingType); } - clock_gettime(CLOCK_MONOTONIC, &endTime); - getLapsedTime(&elapsedTime, &endTime, &startTime); - T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long )elapsedTime.tv_sec, elapsedTime.tv_nsec); + clockReturn |= clock_gettime(CLOCK_MONOTONIC, &endTime); + if(clockReturn) + { + T2Warning("Error in Fetching the time Elapsed"); + } + else + { + getLapsedTime(&elapsedTime, &endTime, &startTime); + T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long )elapsedTime.tv_sec, elapsedTime.tv_nsec); + } if(ret == T2ERROR_SUCCESS && jsonReport) { free(jsonReport); diff --git a/source/bulkdata/profilexconf.c b/source/bulkdata/profilexconf.c index 6b8efc07..09e00ce8 100644 --- a/source/bulkdata/profilexconf.c +++ b/source/bulkdata/profilexconf.c @@ -318,7 +318,7 @@ static void* CollectAndReportXconf(void* data) { T2Info("%s Xconf Profile Processing Time in seconds : %ld\n", profile->name, (long)(endTime.tv_sec - startTime.tv_sec)); } - + if(ret != T2ERROR_SUCCESS) { T2Error("Unable to generate report for : %s\n", profile->name); @@ -469,7 +469,7 @@ static void* CollectAndReportXconf(void* data) getLapsedTime(&elapsedTime, &endTime, &startTime); T2Info("Elapsed Time for : %s = %lu.%lu (Sec.NanoSec)\n", profile->name, (unsigned long)elapsedTime.tv_sec, elapsedTime.tv_nsec); } - + if(jsonReport) { free(jsonReport);