[Sugar-devel] Best time format for logging?

James Cameron quozl at laptop.org
Fri Feb 28 18:30:57 EST 2014


On Fri, Feb 28, 2014 at 02:39:41PM -0300, Manuel Quiñones wrote:
> date +%s.%N
> 1393609027.074597846

Yes, this is adequate, though sometimes the fractional value can be
imprecise as it depends on many factors.

For response times, it is useful, but care should be taken to record
the value in the most primitive form and do the conversion to text
some other time, otherwise the measurement can affect the result.

For the case in olpc-utils you change in your patch, use the %s format
character.  You don't need higher resolution for that use case.

The epoch time is the most useful, as it is independent of time zone
configuration on the system.

In the case of your code, you can optimise it to avoid creating a
process to exec /bin/date, by using printf in bash:

    printf 'START_SUGAR %(%s)T\n' -1 >> $HOME/.olpc-launch-stats

If you use -2 instead of -1, you will get the time the olpc-session
process started, rather than the current time.

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list