]> granicus.if.org Git - strace/blobdiff - strace-graph
travis: add x86 musl
[strace] / strace-graph
index d57e76863e585b3a0fdf61ad6b7e8032e99476a4..5435e864b859eaffea4ec0f273179ba28ccf50f3 100755 (executable)
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+use strict;
+use warnings;
+
 my %unfinished;
+my $floatform;
 
 # Scales for strace slowdown.  Make configurable!
 my $scale_factor = 3.5;
 
 while (<>) {
-    my ($pid, $call, $args, $result, $time);
+    my ($pid, $call, $args, $result, $time, $time_spent);
     chop;
+    $floatform = 0;
 
     s/^(\d+)\s+//;
     $pid = $1;
@@ -70,7 +75,7 @@ while (<>) {
        delete $unfinished{$pid};
     }
 
-    if (/^--- SIG(\S+) \(.*\) ---$/) {
+    if (/^--- SIG(\S+) (.*) ---$/) {
        # $pid received signal $1
        # currently we don't do anything with this
        next;
@@ -82,7 +87,16 @@ while (<>) {
        next;
     }
 
+    if (/^\+\+\+ exited with (\d+) \+\+\+$/) {
+       # $pid exited $1
+       # currently we don't do anything with this
+       next;
+    }
+
     ($call, $args, $result) = /(\S+)\((.*)\)\s+= (.*)$/;
+    if ($result =~ /^(.*) <([0-9.]*)>$/) {
+       ($result, $time_spent) = ($1, $2);
+    }
     unless (defined $result) {
        print STDERR "$0: $ARGV: $.: cannot parse line.\n";
        next;
@@ -119,13 +133,14 @@ sub parse_one {
     my ($in) = @_;
 
     if ($in =~ s/^\"//) {
+       my $tmp;
        ($tmp, $in) = parse_str($in);
        if (not defined $tmp) {
            print STDERR "$0: $ARGV: $.: cannot parse string.\n";
            return (undef, $in);
        }
        return ($tmp, $in);
-    } elsif ($in =~ s/^0x(\x+)//) {
+    } elsif ($in =~ s/^0x([[:xdigit:]]+)//) {
        return (hex $1, $in);
     } elsif ($in =~ s/^(\d+)//) {
        return (int $1, $in);
@@ -197,7 +212,7 @@ my $depth = "";
 # process info, indexed by pid.
 # fields:
 #    parent         pid number
-#    seq            forks and execs for this pid, in sequence  (array)
+#    seq            clones, forks and execs for this pid, in sequence  (array)
 
 #  filename and argv (from latest exec)
 #  basename (derived from filename)
@@ -214,10 +229,10 @@ sub handle_trace {
     }
 
     if ($call eq 'execve') {
-       return if $result != 0;
+       return if $result ne '0';
 
        my ($filename, $argv) = parseargs($args);
-       ($basename) = $filename =~ m/([^\/]*)$/;
+       my ($basename) = $filename =~ m/([^\/]*)$/;
        if ($basename ne $$argv[0]) {
            $$argv[0] = "$basename($$argv[0])";
         }
@@ -235,7 +250,8 @@ sub handle_trace {
        push @$seq, ['FORK', $result];
        $pr{$pid}{seq} = $seq;
        $pr{$result}{parent} = $pid;
-    } elsif ($call eq '_exit') {
+       $pr{$result}{seq} = [];
+    } elsif ($call eq '_exit' || $call eq 'exit_group') {
        $pr{$pid}{end} = $time if defined $time;
     }
 }
@@ -249,7 +265,7 @@ sub straight_seq {
     my ($pid) = @_;
     my $seq = $pr{$pid}{seq};
 
-    for $elem (@$seq) {
+    for my $elem (@$seq) {
        if ($$elem[0] eq 'EXEC') {
            my $argv = $$elem[2];
            print "$$elem[0] $$elem[1] @$argv\n";
@@ -265,7 +281,7 @@ sub first_exec {
     my ($pid) = @_;
     my $seq = $pr{$pid}{seq};
 
-    for $elem (@$seq) {
+    for my $elem (@$seq) {
        if ($$elem[0] eq 'EXEC') {
            return $elem;
        }
@@ -293,15 +309,15 @@ sub display_pid_trace {
        }
     }
 
-    for $elem (@seq) {
+    for my $elem (@seq) {
        $i++;
        if ($$elem[0] eq 'EXEC') {
            my $argv = $$elem[2];
            if (defined $elapsed) {
-               print "$lead [$elapsed] @$argv\n";
+               print "$lead [$elapsed] $pid @$argv\n";
                undef $elapsed;
            } else {
-               print "$lead @$argv\n";
+               print "$lead $pid @$argv\n";
            }
        } elsif ($$elem[0] eq 'FORK') {
            if ($i == 1) {