1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | # inspired by treescan by Jamie Lokier <jamie@imbolc.ucc.ie> |
3 | # inspired by treescan by Jamie Lokier <jamie@imbolc.ucc.ie> |
4 | # about 40% faster than the original version (on my fs and raid :) |
4 | # about 40% faster than the original version (on my fs and raid :) |
5 | |
5 | |
6 | use strict; |
6 | use common::sense; |
7 | use Getopt::Long; |
7 | use Getopt::Long; |
8 | use Time::HiRes (); |
8 | use Time::HiRes (); |
9 | use IO::AIO; |
9 | use IO::AIO; |
10 | |
10 | |
11 | our $VERSION = $IO::AIO::VERSION; |
11 | our $VERSION = $IO::AIO::VERSION; |
… | |
… | |
28 | @ARGV = "." unless @ARGV; |
28 | @ARGV = "." unless @ARGV; |
29 | |
29 | |
30 | $opt_grep &&= qr{$opt_grep}s; |
30 | $opt_grep &&= qr{$opt_grep}s; |
31 | |
31 | |
32 | my ($n_dirs, $n_files, $n_stats) = (0, 0, 0); |
32 | my ($n_dirs, $n_files, $n_stats) = (0, 0, 0); |
33 | my $n_last; |
|
|
34 | my $n_start = Time::HiRes::time; |
33 | my ($n_last, $n_start) = (Time::HiRes::time) x 2; |
35 | |
34 | |
36 | sub printfn { |
35 | sub printfn { |
37 | my ($prefix, $files, $suffix) = @_; |
36 | my ($prefix, $files, $suffix) = @_; |
38 | |
37 | |
39 | if ($opt_grep) { |
38 | if ($opt_grep) { |
… | |
… | |
54 | |
53 | |
55 | IO::AIO::poll_cb; |
54 | IO::AIO::poll_cb; |
56 | |
55 | |
57 | if ($opt_progress and $n_last + 1 < Time::HiRes::time) { |
56 | if ($opt_progress and $n_last + 1 < Time::HiRes::time) { |
58 | $n_last = Time::HiRes::time; |
57 | $n_last = Time::HiRes::time; |
59 | printf STDERR "%d dirs %d files %d stats %g stats/s \r", $n_dirs, $n_files, $n_stats, $n_stats / ($n_last - $n_start) |
58 | my $d = $n_last - $n_start; |
|
|
59 | printf STDERR "\r%d dirs (%g/s) %d files (%g/s) %d stats (%g/s) ", |
|
|
60 | $n_dirs, $n_dirs / $d, |
|
|
61 | $n_files, $n_files / $d, |
|
|
62 | $n_stats, $n_stats / $d |
60 | if $opt_progress; |
63 | if $opt_progress; |
61 | } |
64 | } |
62 | |
65 | |
63 | aioreq_pri -1; |
66 | aioreq_pri -1; |
64 | ++$n_dirs; |
67 | ++$n_dirs; |
… | |
… | |
87 | IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly |
90 | IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly |
88 | IO::AIO::min_parallel 20; |
91 | IO::AIO::min_parallel 20; |
89 | |
92 | |
90 | for my $seed (@ARGV) { |
93 | for my $seed (@ARGV) { |
91 | $seed =~ s/\/+$//; |
94 | $seed =~ s/\/+$//; |
92 | ++$n_stats; |
|
|
93 | aio_lstat "$seed/.", sub { |
95 | aio_lstat "$seed/.", sub { |
94 | if ($_[0]) { |
96 | if ($_[0]) { |
95 | print STDERR "$seed: $!\n"; |
97 | print STDERR "$seed: $!\n"; |
96 | } elsif (-d _) { |
98 | } elsif (-d _) { |
97 | scan $seed; |
99 | scan $seed; |