commit 1a0dc6985aad06e76857cf2a354bd5ba0c9ce96b
parent 56dff76695fd7e7b11eda2bd08e1da8e41072e13
Author: Brendan Gregg <brendan.d.gregg@gmail.com>
Date: Thu, 24 Oct 2019 15:53:06 -0700
Merge pull request #152 from milianw/master
Add --xdev capability to files.pl
Diffstat:
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/files.pl b/files.pl
@@ -16,25 +16,44 @@ use strict;
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