Re: [PATCH 2/3] delaytop: add timestamp of delay max
From: Andrew Morton
Date: Thu Jul 02 2026 - 19:01:20 EST
On Thu, 2 Jul 2026 20:58:54 +0800 (CST) <wang.yaxin@xxxxxxxxxx> wrote:
> From: Wang Yaxin <wang.yaxin@xxxxxxxxxx>
>
> Record the wall-clock timestamp when each maximum delay occurred for
> all delay types. The timestamp is displayed in the MAX_TIMESTAMP column
> when using -t/--type option.
>
> This enables:
> - Identifying the time when a process experienced an abnormal delay spike
> - Correlating delay peaks across multiple processes at the same timestamp
> - Cross-referencing with system logs, traces, or other metrics at that time
> - Pinpointing the root cause of latency issues by finding concurrent events
>
> ...
>
> +/*
> + * Format __kernel_timespec to human readable string (YYYY-MM-DDTHH:MM:SS)
> + * Returns formatted string or "N/A" if timestamp is zero
> + */
> +static const char *format_timespec64(struct __kernel_timespec *ts)
> +{
> + static char buffer[32];
> + time_t time_sec;
> + struct tm tm_info;
> +
> + /* Check if timestamp is zero (not set) */
> + if (ts->tv_sec == 0 && ts->tv_nsec == 0)
> + return "N/A";
> +
> + /* Avoid Y2038 truncation: check if timestamp fits in time_t on 32-bit platforms */
> + if (sizeof(time_t) < sizeof(ts->tv_sec) &&
> + ts->tv_sec > (__u64)((1ULL << (sizeof(time_t) * 8 - 1)) - 1))
> + return "N/A";
> +
> + time_sec = (time_t)ts->tv_sec;
> +
> + if (localtime_r(&time_sec, &tm_info) == NULL)
> + return "N/A";
> +
> + snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d",
> + tm_info.tm_year + 1900,
> + tm_info.tm_mon + 1,
> + tm_info.tm_mday,
> + tm_info.tm_hour,
> + tm_info.tm_min,
> + tm_info.tm_sec);
> +
> + return buffer;
> +}
This appears to be a copy-paste-edit from format_timespec() in
tools/accounting/getdelays.c. Why do the two differ? Is it possible
to use a common implementation? tools/accounting/format_tiomespec.o?
Does the getdelays.c version have the possible issue which AI review
identified?