Conversation
Change the MonitorAV log line to single log line by combining beginning of issue started log Reason for Change: combine two log lines to one to reduce the flooding Test Guidance: updated in ticket Risk: Low
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce MonitorAV log flooding by collapsing the previous “state ended” + “state started” pair of log lines into a single combined log line, adding a human-readable UTC timestamp.
Changes:
- Added a UTC timestamp formatter (
MS_TO_UTC_STRING) and related includes inInterfacePlayerRDK.cpp. - Modified
MonitorAV()logging to emit a single combined log line on AV state transitions, and added tracking variables for timestamp/positions. - Added a
NOW_SYSTEM_TS_MSmacro (system clock milliseconds) toInterfacePlayerPriv.h.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| middleware/InterfacePlayerRDK.cpp | Introduces timestamp formatting and changes MonitorAV transition logging into a single line. |
| middleware/InterfacePlayerPriv.h | Adds a system-clock timestamp macro used by the new MonitorAV logging. |
| std::string humanReadbletime = MS_TO_UTC_STRING(time_now_ms); | ||
|
|
||
| MW_LOG_MIL( "MonitorAV_%s: (%s - %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0) %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,%" G_GINT64_FORMAT "", | ||
| description, | ||
| humanReadbletime.c_str(), |
There was a problem hiding this comment.
Minor: variable name humanReadbletime appears misspelled (likely humanReadableTime). Consider correcting for readability/maintainability.
| std::string humanReadbletime = MS_TO_UTC_STRING(time_now_ms); | |
| MW_LOG_MIL( "MonitorAV_%s: (%s - %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0) %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,%" G_GINT64_FORMAT "", | |
| description, | |
| humanReadbletime.c_str(), | |
| std::string humanReadableTime = MS_TO_UTC_STRING(time_now_ms); | |
| MW_LOG_MIL( "MonitorAV_%s: (%s - %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0) %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,%" G_GINT64_FORMAT "", | |
| description, | |
| humanReadableTime.c_str(), |
| static long long time_now_ms = 0; | ||
| static gint64 videoPos = 0; | ||
| static gint64 audioPos = 0; |
There was a problem hiding this comment.
The new static locals (time_now_ms, videoPos, audioPos) are shared across all MonitorAV() calls, so multiple InterfacePlayerRDK instances will overwrite each other’s values and produce incorrect/merged logs. Please store this per-player (e.g., in MonitorAVState or the player’s private context) instead of function-level statics.
| static long long time_now_ms = 0; | |
| static gint64 videoPos = 0; | |
| static gint64 audioPos = 0; | |
| long long time_now_ms = 0; | |
| gint64 videoPos = 0; | |
| gint64 audioPos = 0; |
| MW_LOG_MIL( "MonitorAV_%s: (%s - %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0) %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,%" G_GINT64_FORMAT "", | ||
| description, | ||
| humanReadbletime.c_str(), | ||
| videoPos, | ||
| audioPos, | ||
| (int)(videoPos - audioPos), | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_VIDEO], | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_AUDIO], | ||
| (int)(monitorAVState->av_position[eGST_MEDIATYPE_VIDEO] - monitorAVState->av_position[eGST_MEDIATYPE_AUDIO]), |
There was a problem hiding this comment.
The combined log line labels the message with description (the new AV state), but the “previous state” section no longer includes the old state name (monitorAVState->description). This loses information compared to the previous two-line logging and makes transitions ambiguous. Include both old and new state descriptions in the single line (e.g., old -> new).
| { // log only when interpretation of AV state has changed | ||
| if( monitorAVState->description ) | ||
| { // avoid logging for initial NULL description | ||
| MW_LOG_MIL( "MonitorAV_%s: %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d, %" G_GINT64_FORMAT "", | ||
| monitorAVState->description, | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_VIDEO], | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_AUDIO], | ||
| (int)(monitorAVState->av_position[eGST_MEDIATYPE_VIDEO] - monitorAVState->av_position[eGST_MEDIATYPE_AUDIO]), | ||
| (gint64)monitorAVState->tLastSampled - monitorAVState->tLastReported ); | ||
|
|
||
| std::string humanReadbletime = MS_TO_UTC_STRING(time_now_ms); | ||
|
|
||
| MW_LOG_MIL( "MonitorAV_%s: (%s - %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0) %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,%" G_GINT64_FORMAT "", | ||
| description, | ||
| humanReadbletime.c_str(), | ||
| videoPos, | ||
| audioPos, | ||
| (int)(videoPos - audioPos), | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_VIDEO], | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_AUDIO], | ||
| (int)(monitorAVState->av_position[eGST_MEDIATYPE_VIDEO] - monitorAVState->av_position[eGST_MEDIATYPE_AUDIO]), | ||
| (gint64)monitorAVState->tLastSampled - monitorAVState->tLastReported ); | ||
| } |
There was a problem hiding this comment.
This change suppresses logging for the first transition from nullptr to the initial state because logging now only happens inside if (monitorAVState->description). Previously, the code always emitted the “new state started” line on every transition. If the intent is to combine two lines into one (not drop the initial one), consider emitting a single line even when monitorAVState->description is null (with an explicit marker for "initial").
| std::string humanReadbletime = MS_TO_UTC_STRING(time_now_ms); | ||
|
|
||
| MW_LOG_MIL( "MonitorAV_%s: (%s - %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0) %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,%" G_GINT64_FORMAT "", | ||
| description, | ||
| humanReadbletime.c_str(), | ||
| videoPos, | ||
| audioPos, | ||
| (int)(videoPos - audioPos), | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_VIDEO], | ||
| (gint64)monitorAVState->av_position[eGST_MEDIATYPE_AUDIO], | ||
| (int)(monitorAVState->av_position[eGST_MEDIATYPE_VIDEO] - monitorAVState->av_position[eGST_MEDIATYPE_AUDIO]), | ||
| (gint64)monitorAVState->tLastSampled - monitorAVState->tLastReported ); | ||
| } | ||
| MW_LOG_MIL( "MonitorAV_%s: %" G_GINT64_FORMAT ",%" G_GINT64_FORMAT ",%d,0", | ||
| description, | ||
| av_position[eGST_MEDIATYPE_VIDEO], | ||
| av_position[eGST_MEDIATYPE_AUDIO], | ||
| (int)(av_position[eGST_MEDIATYPE_VIDEO] - av_position[eGST_MEDIATYPE_AUDIO]) ); | ||
| time_now_ms = NOW_SYSTEM_TS_MS; | ||
| videoPos = av_position[eGST_MEDIATYPE_VIDEO]; | ||
| audioPos = av_position[eGST_MEDIATYPE_AUDIO]; |
There was a problem hiding this comment.
humanReadbletime is derived from time_now_ms, but time_now_ms is only updated after the log line. As a result the timestamp shown corresponds to the previous transition (or 0/epoch until the first update), not the current event being logged. If the timestamp is meant to represent when the new issue/state started, set it before logging (or log both previous and current timestamps explicitly).
| #define MS_TO_UTC_STRING(ms) ([&](){ \ | ||
| std::time_t t = (ms) / 1000; \ | ||
| std::tm tm = *std::gmtime(&t); /* UTC instead of localtime */ \ | ||
| std::ostringstream oss; \ | ||
| oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") \ | ||
| << '.' << std::setw(3) << std::setfill('0') << ((ms) % 1000); \ | ||
| return oss.str(); \ | ||
| }()) | ||
|
|
There was a problem hiding this comment.
MS_TO_UTC_STRING uses std::gmtime(), which returns a pointer to a shared static tm and is not thread-safe; dereferencing it also assumes it never returns null. Since MonitorAV can be invoked from different threads/contexts, consider using gmtime_r (POSIX) or an equivalent thread-safe conversion, and prefer an inline helper function over a macro to avoid multiple evaluations of the ms argument.
| #define MS_TO_UTC_STRING(ms) ([&](){ \ | |
| std::time_t t = (ms) / 1000; \ | |
| std::tm tm = *std::gmtime(&t); /* UTC instead of localtime */ \ | |
| std::ostringstream oss; \ | |
| oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") \ | |
| << '.' << std::setw(3) << std::setfill('0') << ((ms) % 1000); \ | |
| return oss.str(); \ | |
| }()) | |
| static inline std::string msToUtcString(int64_t ms) | |
| { | |
| std::time_t t = static_cast<std::time_t>(ms / 1000); | |
| std::tm tm{}; | |
| #if defined(_POSIX_VERSION) | |
| if (gmtime_r(&t, &tm) == nullptr) | |
| { | |
| return std::string(); | |
| } | |
| #else | |
| std::tm *tmp = std::gmtime(&t); /* UTC instead of localtime */ | |
| if (tmp == nullptr) | |
| { | |
| return std::string(); | |
| } | |
| tm = *tmp; | |
| #endif | |
| std::ostringstream oss; | |
| oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") | |
| << '.' << std::setw(3) << std::setfill('0') << (ms % 1000); | |
| return oss.str(); | |
| } | |
| #define MS_TO_UTC_STRING(ms) msToUtcString(ms) |
Change the MonitorAV log line to single log line by combining beginning of issue started log
Reason for Change: combine two log lines to one to reduce the flooding
Test Guidance: updated in ticket
Risk: Low