--- IO-AIO/bin/treescan 2011/09/30 00:23:44 1.9 +++ IO-AIO/bin/treescan 2011/10/04 18:22:37 1.10 @@ -5,27 +5,34 @@ use strict; use Getopt::Long; +use Time::HiRes (); use IO::AIO; our $VERSION = $IO::AIO::VERSION; Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); -my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles, $opt_grep); +my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, + $opt_nofiles, $opt_grep, $opt_progress); GetOptions - "quiet|q" => \$opt_silent, - "print0|0" => \$opt_print0, - "stat|s" => \$opt_stat, - "dirs|d" => \$opt_nofiles, - "files|f" => \$opt_nodirs, - "grep|g=s" => \$opt_grep, + "quiet|q" => \$opt_silent, + "print0|0" => \$opt_print0, + "stat|s" => \$opt_stat, + "dirs|d" => \$opt_nofiles, + "files|f" => \$opt_nodirs, + "grep|g=s" => \$opt_grep, + "progress|p" => \$opt_progress, or die "Usage: try $0 --help"; @ARGV = "." unless @ARGV; $opt_grep &&= qr{$opt_grep}s; +my ($n_dirs, $n_files, $n_stats) = (0, 0, 0); +my $n_last; +my $n_start = Time::HiRes::time; + sub printfn { my ($prefix, $files, $suffix) = @_; @@ -47,7 +54,14 @@ IO::AIO::poll_cb; + if ($opt_progress and $n_last + 1 < Time::HiRes::time) { + $n_last = Time::HiRes::time; + printf STDERR "%7d dirs %7d files %7d stats %g stats/s \r", $n_dirs, $n_files, $n_stats, $n_stats / ($n_last - $n_start) + if $opt_progress; + } + aioreq_pri -1; + ++$n_dirs; aio_scandir $path, 8, sub { my ($dirs, $files) = @_ or warn "$path: $!\n"; @@ -55,11 +69,14 @@ printfn "", [$path] unless $opt_nodirs; printfn $path, $files unless $opt_nofiles; + $n_files += @$files; + if ($opt_stat) { aio_wd $path, sub { my $wd = shift; aio_lstat [$wd, $_] for @$files; + $n_stats += @$files; }; } @@ -72,6 +89,7 @@ for my $seed (@ARGV) { $seed =~ s/\/+$//; + ++$n_stats; aio_lstat "$seed/.", sub { if ($_[0]) { print STDERR "$seed: $!\n";