ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/bin/treescan
(Generate patch)

Comparing IO-AIO/bin/treescan (file contents):
Revision 1.12 by root, Tue Oct 4 18:25:02 2011 UTC vs.
Revision 1.16 by root, Sat Jan 25 00:15:52 2014 UTC

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
6use strict; 6use common::sense;
7use Getopt::Long; 7use Getopt::Long;
8use Time::HiRes (); 8use Time::HiRes ();
9use IO::AIO; 9use IO::AIO;
10 10
11our $VERSION = $IO::AIO::VERSION; 11our $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
32my ($n_dirs, $n_files, $n_stats) = (0, 0, 0); 32my ($n_dirs, $n_files, $n_stats) = (0, 0, 0);
33my $n_last;
34my $n_start = Time::HiRes::time; 33my ($n_last, $n_start) = (Time::HiRes::time) x 2;
35 34
36sub printfn { 35sub 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 "\r%d dirs %d files %d stats %g stats/s ", $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;
65 aio_scandir $path, 8, sub { 68 aio_scandir $path, 8, sub {
66 my ($dirs, $files) = @_ 69 my ($dirs, $files) = @_
67 or warn "$path: $!\n"; 70 or return warn "$path: $!\n";
68 71
69 printfn "", [$path] unless $opt_nodirs; 72 printfn "", [$path] unless $opt_nodirs;
70 printfn $path, $files unless $opt_nofiles; 73 printfn $path, $files unless $opt_nofiles;
71 74
72 $n_files += @$files; 75 $n_files += @$files;
87IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly 90IO::AIO::max_outstanding 100; # two fds per directory, so limit accordingly
88IO::AIO::min_parallel 20; 91IO::AIO::min_parallel 20;
89 92
90for my $seed (@ARGV) { 93for 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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines