by mrfusion · 12y ago · 0 comments
We've got a fairly complicated bioinformatics pipeline that calls about 100 other programs, and creates or reads about 100 different files. I'd love a way to create a picture of what's going on. Which files each program uses, etc.
If such a program doesn't exist, would that be worth building? Could it be something I could potentially sell?
#!/usr/bin/perl -w
$|=1;
use strict;
my (%pidmap, @order);
while ( <> ) {
chomp;
if ( /^(\d+)\s+(\w+)(.*)$/ ) {
my ($pid, $syscall, $args) = ($1, $2, $3);
if ( $syscall =~ /(^clone$|fork$)/ and $args =~ / = (\d+)$/ and $1 > 0 ) {
my $clonepid = $1;
$pidmap{$clonepid} = { -parent => $pid };
push(@order, $clonepid);
}
elsif ( $syscall =~ /^exec/ and $args =~ / = (\d+)$/ and $1 == 0 ) {
my $exec = $args;
@order = ($pid) if !@order;
$exec =~ s/^\("([^"]+?)",.*$/$1/g;
push( @{ $pidmap{$pid}->{-exec} } , $exec );
}
}
}
foreach my $pid ( @order ) {
my $spaces = walkpid($pid);
print " " x $spaces . join("\n" . (" " x $spaces), map { $_ . " ($pid)" } @{ $pidmap{$pid}->{-exec} } ) . "\n";
}
sub walkpid {
my $pid = shift;
my $c = shift || 0;
if ( exists $pidmap{$pid}->{-parent} ) {
return walkpid($pidmap{$pid}->{-parent}, $c+1);
}
return($pid, $c);
}