1 Star2 Stars3 Stars4 Stars5 Stars (还没有评分)
Loading...

DTrace tricks and tips (1) – 打印当前系统时间

在使用DTrace时,如果想打印当前系统时间,可以借助内置变量walltimestamp。walltimestamp表示的是自从1970年1月1日0时(UTC时间)以来经过的纳秒数,那么如何把它表示成让人一目了然的形式呢?答案是借助printf。脚本如下:

dtrace -qn 'BEGIN {printf("%Y\n", walltimestamp); exit(0)}'

输出如下:

2014 May 11 19:33:01

关于这个技巧,可参考stackoveflow的帖子:http://stackoverflow.com/questions/21084922/is-there-any-better-method-of-displaying-wall-clock-time-except-using-walltimest

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.