PTP: Improve logging output for timing chain data

This is to enhance the logging in ptp-notification to trigger
an INFO level log when the system timing chain changes, which
determines overall sync state. This prevents the need for enabling
debug logs to observe the timing chain report.

TEST PLAN:
  PASS: run unit tests and see info logs with
        "Overall sync state chaining info:".
  PASS: Deploy ptp-notification app and trigger different events
        and check info logs with "Overall sync state chaining info:".

Story: 2011370
Task: 52046

Change-Id: Id368f9babcdd9b64a33b824ada3a363d21754a83
Signed-off-by: Tara Nath Subedi <tara.subedi@windriver.com>
This commit is contained in:
Tara Subedi 2025-04-23 10:47:01 -04:00
parent b145d42c15
commit c320d28eec

View File

@ -529,6 +529,10 @@ class PtpWatcherDefault:
# Need to figure out which gnss/ptp is disciplining the PHC that syncs os_clock
os_clock_state = self.os_clock_monitor.get_os_clock_state()
sync_state = OverallClockState.Freerun
chaining_info = (
f"Overall sync state chaining info:\n"
f"os-clock-state = {os_clock_state}"
)
if os_clock_state is not OsClockState.Freerun:
# PTP device that is disciplining the OS clock,
# valid even for HA source devices
@ -536,6 +540,9 @@ class PtpWatcherDefault:
if ptp_device is None:
# This may happen in virtualized environments
LOG.warning("No PTP device. Defaulting overall state Freerun")
chaining_info += (
f"\nos-clock's source ptp-device = None"
)
else:
# What source (gnss or ptp) disciplining the PTP device at the
# moment (A PTP device could have both TS2PHC/gnss source and
@ -565,12 +572,11 @@ class PtpWatcherDefault:
if primary_gnss is None
else (primary_gnss.ts2phc_service_name, gnss_state)
)
LOG.debug(
f"Overall sync state chaining info:\n"
f"os-clock's source ptp-device = {ptp_device}\n"
chaining_info += (
f"\nos-clock's source ptp-device = {ptp_device}\n"
f"ptp-device's sync-source = {sync_source}\n"
f"ptp4l-instance-and-state = {ptp4l_instance_and_state}\n"
f"ts2phc-instance-and-state = {ts2phc_instance_and_state}"
f"(PTP source) ptp4l-instance-and-state = {ptp4l_instance_and_state}\n"
f"(GNSS source) ts2phc-instance-and-state = {ts2phc_instance_and_state}"
)
# Based on sync_source that is used to discipline the ptp device,
@ -613,9 +619,16 @@ class PtpWatcherDefault:
else:
sync_state = OverallClockState.Freerun
chaining_info += (
f"\nOverall sync: previous-state = {previous_sync_state}, new-state = {sync_state}"
)
if sync_state != previous_sync_state:
new_event = True
new_event_time = datetime.datetime.utcnow().timestamp()
LOG.info(chaining_info)
else:
LOG.debug(chaining_info)
return new_event, sync_state, new_event_time
def __get_ptp_status(self, holdover_time, freq, sync_state,