[PATCH v9 5/5] eal: add option to put timestamp on console output

Stephen Hemminger stephen at networkplumber.org
Wed Mar 20 04:33:52 CET 2024


On Tue, 19 Mar 2024 17:13:35 +0100
Morten Brørup <mb at smartsharesystems.com> wrote:

> > From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> > Sent: Tuesday, 19 March 2024 16.52
> > 
> > On Tue, 19 Mar 2024 08:37:30 +0100
> > Morten Brørup <mb at smartsharesystems.com> wrote:
> >   
> > > >  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.
> > 
> > 
> > No, was trying to do what kernel dmesg does.  
> 
> What do you mean? Doesn't the kernel output CLOCK_MONOTONIC timestamps (without offset)?
> 
> And by "timestamps from other processes" I also mean timestamps in log messages from the kernel itself.
> 

If you look at dmesg command that formats the messages, it has lots of timestamp options.
Next version will support more of these.

       --time-format format
           Print timestamps using the given format, which can be ctime,
           reltime, delta or iso. The first three formats are aliases of
           the time-format-specific options. The iso format is a dmesg
           implementation of the ISO-8601 timestamp format. The purpose
           of this format is to make the comparing of timestamps between
           two systems, and any other parsing, easy. The definition of
           the iso timestamp is:
           YYYY-MM-DD<T>HH:MM:SS,<microseconds>←+><timezone offset from
           UTC>.


More information about the dev mailing list