Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any better method of displaying wall clock time except using walltimestamp variable?

Tags:

dtrace

I want to print the time when a probe is fired. After checking the Dtrace documents, I find the built-in variable: walltimestamp. And the Dtrace script likes this:

pid$1::func:entry
{
    trace(walltimestamp);
}  

But the walltimestamp is "The current number of nanoseconds since 00:00 Universal Coordinated Time, January 1, 1970.", so the output likes "1389583988106535481". I think this isn't easy for user to understand and want the output likes "Mon Jan 13 00:00:00 2014". I have searched whether Dtrace provide functions like ctime in C programming language, but nothing found.

Does anyone need to implement a function like ctime by himself? Or Is there any better method to display the time?

like image 887
Nan Xiao Avatar asked Feb 14 '23 03:02

Nan Xiao


1 Answers

Use printf():

# dtrace -qn 'BEGIN {printf("%Y\n", walltimestamp); exit(0)}'
2014 Jan 13 08:37:56

#
like image 140
Robert Harris Avatar answered May 16 '23 07:05

Robert Harris