Sometimes the timestamps delivered by %Y
are not precise enough for debugging purposes.
# dtrace \
-n 'syscall::read:entry {printf("%Y", walltimestamp);}'
dtrace: description 'syscall::read:entry ' matched 1 probe
CPU ID FUNCTION:NAME
0 6978 read:entry 2021 Mar 9 15:07:37
0 6978 read:entry 2021 Mar 9 15:07:37
0 6978 read:entry 2021 Mar 9 15:07:37
While this is still the default for compatibility reasons, you can now have much more precise timestamps with nanosecond resolution by using the -x timedecimals
option. If you use this new option without an value it will give you the full precision
# dtrace -x timedecimals \
-n 'syscall::read:entry {printf("%Y", walltimestamp);}'
dtrace: description 'syscall::read:entry ' matched 1 probe
CPU ID FUNCTION:NAME
0 6978 read:entry 2021 Mar 9 15:13:46.140002400
0 6978 read:entry 2021 Mar 9 15:13:46.140002400
0 6978 read:entry 2021 Mar 9 15:13:46.140002400
If you need less precise timestamps, you can control it by an optional value to -x timedecimals
# dtrace -x timedecimals=4 \
-n 'syscall::read:entry {printf("%Y", walltimestamp);}'
dtrace: description 'syscall::read:entry ' matched 1 probe
CPU ID FUNCTION:NAME
0 6978 read:entry 2021 Mar 9 15:18:04.3700
0 6978 read:entry 2021 Mar 9 15:18:04.3700
0 6978 read:entry 2021 Mar 9 15:18:04.3700
If you use -x timedecimals=0
if will use 9 digits, not zero. If you chose a value higher than 9, it will revert to 9 as well.
If you only need higher precision in select outputs of you dtrace script there is a second way to get more digits by specifying it in the format string:
# dtrace \
-n 'syscall::read:entry {printf("%.6Y", walltimestamp);}'
dtrace: description 'syscall::read:entry ' matched 1 probe
CPU ID FUNCTION:NAME
0 6978 read:entry 2021 Mar 9 15:19:52.440769
0 6978 read:entry 2021 Mar 9 15:19:52.440769
0 6978 read:entry 2021 Mar 9 15:19:52.440769
If you specify both, the precision specified in the format string has priority.
# dtrace -x timedecimals=4 \
-n 'syscall::read:entry {printf("%.6Y", walltimestamp);}'
dtrace: description 'syscall::read:entry ' matched 1 probe
^C
CPU ID FUNCTION:NAME
0 6978 read:entry 2021 Mar 9 15:21:39.510012
0 6978 read:entry 2021 Mar 9 15:21:39.510012
0 6978 read:entry 2021 Mar 9 15:21:39.510012
Despite having specified 4 decimals with -x timedecimals=4
it will use the number specified with "%.6Y"
.