[PATCH v9 5/5] eal: add option to put timestamp on console output
Morten Brørup
mb at smartsharesystems.com
Tue Mar 19 08:37:30 CET 2024
> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Monday, 18 March 2024 23.03
>
> When debugging driver or startup issues, it is useful to have
> a timestamp on each message printed. The messages in syslog
> already have a timestamp, but often syslog is not available
> during testing. The timestamp format is chosen to look
> like the default Linux dmesg timestamp.
>
> The first few lines are not timestamped because the flag is stored
> in internal configuration which is stored in shared memory
> which is not setup up until a little later in startup process.
>
> This logging skips the unnecessary step of going through stdio,
> which makes it more robust against being called in interrupt
> handlers etc.
>
> Example:
> $ dpdk-testpmd --log-timestamp -- -i
> EAL: Detected CPU lcores: 16
> EAL: Detected NUMA nodes: 1
> EAL: Detected static linkage of DPDK
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
> EAL: Selected IOVA mode 'VA'
> [ 0.112264] testpmd: No probed ethernet devices
> Interactive-mode selected
> [ 0.184573] testpmd: create a new mbuf pool <mb_pool_0>: n=163456,
> size=2176, socket=0
> [ 0.184612] testpmd: preferred mempool ops selected: ring_mp_mc
>
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
[...]
> static ssize_t
> console_log_write(__rte_unused void *c, const char *buf, size_t size)
> {
> + struct timespec ts;
> ssize_t ret;
>
> - /* write on stderr */
> - ret = fwrite(buf, 1, size, stderr);
> + if (timestamp_enabled) {
> + clock_gettime(CLOCK_MONOTONIC, &ts);
> + ts.tv_sec -= log_started.tv_sec;
> + ts.tv_nsec -= log_started.tv_nsec;
Please log the absolute CLOCK_MONOTONIC instead of subtracting log_started, so timestamps can be easily compared with timestamps from other processes.
> + if (ts.tv_nsec < 0) {
> + --ts.tv_sec;
> + ts.tv_nsec += 1000000000ul;
> + }
> +
> + ret = fprintf(stderr, "[%8lu.%06lu] %.*s",
> + ts.tv_sec, ts.tv_nsec / 1000u,
> + (int) size, buf);
With the above change,
For the series,
Acked-by: Morten Brørup <mb at smartsharesystems.com>
More information about the dev
mailing list