convert 'truss' timestamp

Maybe I reinvented the wheel. Here's quick&dirty perl to convert 'truss -df' output. Unfortunately, this doesn't work if only "-d" is given. Here's how this works:

$ truss -df cat
Base time stamp:  1238745134.0279  [ Fri Apr  3 16:52:14 JST 2009 ]
16881:   0.0000 execve("/usr/bin/cat", 0xFFBFFDC4, 0xFFBFFDCC)  argc = 1
16881:   0.0051 resolvepath("/usr/lib/ld.so.1", "/lib/ld.so.1", 1023) = 12
16881:   0.0055 resolvepath("/usr/bin/cat", "/usr/bin/cat", 1023) = 12
16881:   0.0058 stat("/usr/bin/cat", 0xFFBFFBA0)                = 0
[...]

$ truss -d -f cat 2>&1 | ~kinoue/trusstimestamp.pl
Base time stamp:  1238745453.9931  [ Fri Apr  3 16:57:33 JST 2009 ]
16895:   16:57:33.9931  execve("/usr/bin/cat", 0xFFBFFDC4, 0xFFBFFDCC)  argc = 1
16895:   16:57:33.9996  resolvepath("/usr/lib/ld.so.1", "/lib/ld.so.1", 1023) = 12
16895:   16:57:34.0018  resolvepath("/usr/bin/cat", "/usr/bin/cat", 1023) = 12
16895:   16:57:34.0024  stat("/usr/bin/cat", 0xFFBFFBA0)                = 0
[...]

I hope this isn't necessary with truss on OpenSolaris. Linux's strace can do this. So, I think this has been on enhancement list. Here's perl.
#!/usr/bin/env perl
line: while (<>) {
    if ($. == 1) {
        @Fld = split(' ', $_, -1);
        $base = $Fld[3];
        print $_;
        next line;
    }
    if (m/\^([0-9\\/]\*:[\\t ]{1,2})([0-9.]\*)([\\t ].\*)$/o) {
        unless ($2) {
            print $_;
            next line;
        }
        my $seconds = $base + $2;
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($seconds);
        $subsec = substr($seconds, index($seconds, '.'));
        printf ("%s%02d:%02d:%02d%s %s\\n",$1,$hour,$min,$sec,$subsec,$3);
        next line;
    }
    print $_;
}
Comments:

Very nice fix.. I like it. Thank you!

Posted by RowRodney on March 09, 2010 at 09:30 PM JST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today