Skip to content

Commit

Permalink
Merge pull request brendangregg#152 from milianw/master
Browse files Browse the repository at this point in the history
Add --xdev capability to files.pl
  • Loading branch information
brendangregg authored Oct 24, 2019
2 parents 56dff76 + d5021ab commit 1a0dc69
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions files.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,44 @@
use File::Find;

sub usage {
print STDERR "USAGE: $0 directory\n";
print STDERR "USAGE: $0 [--xdev] [DIRECTORY]...\n";
print STDERR " eg, $0 /Users\n";
print STDERR " To not descend directories on other filesystems:";
print STDERR " eg, $0 --xdev /\n";
print STDERR "Intended to be piped to flamegraph.pl. Full example:\n";
print STDERR " $0 /Users | flamegraph.pl " .
"--hash --countname=bytes > files.svg\n";
print STDERR " $0 /usr /home /root /etc | flamegraph.pl " .
"--hash --countname=bytes > files.svg\n";
print STDERR " $0 --xdev / | flamegraph.pl " .
"--hash --countname=bytes > files.svg\n";
exit 1;
}

usage() if @ARGV == 0 or $ARGV[0] eq "--help" or $ARGV[0] eq "-h";

my $filter_xdev = 0;
my $xdev_id;

foreach my $dir (@ARGV) {
find(\&wanted, $dir);
if ($dir eq "--xdev") {
$filter_xdev = 1;
} else {
find(\&wanted, $dir);
}
}

sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = lstat($_);
return unless defined $size;
if ($filter_xdev) {
if (!$xdev_id) {
$xdev_id = $dev;
} elsif ($xdev_id ne $dev) {
$File::Find::prune = 1;
return;
}
}
my $path = $File::Find::name;
$path =~ tr/\//;/; # delimiter
$path =~ tr/;.a-zA-Z0-9-/_/c; # ditch whitespace and other chars
Expand Down

0 comments on commit 1a0dc69

Please sign in to comment.