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.9 by root, Fri Sep 30 00:23:44 2011 UTC vs.
Revision 1.15 by root, Thu Dec 13 07:34:14 2012 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 IO::AIO; 9use IO::AIO;
9 10
10our $VERSION = $IO::AIO::VERSION; 11our $VERSION = $IO::AIO::VERSION;
11 12
12Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); 13Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version");
13 14
14my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles, $opt_grep); 15my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs,
16 $opt_nofiles, $opt_grep, $opt_progress);
15 17
16GetOptions 18GetOptions
17 "quiet|q" => \$opt_silent, 19 "quiet|q" => \$opt_silent,
18 "print0|0" => \$opt_print0, 20 "print0|0" => \$opt_print0,
19 "stat|s" => \$opt_stat, 21 "stat|s" => \$opt_stat,
20 "dirs|d" => \$opt_nofiles, 22 "dirs|d" => \$opt_nofiles,
21 "files|f" => \$opt_nodirs, 23 "files|f" => \$opt_nodirs,
22 "grep|g=s" => \$opt_grep, 24 "grep|g=s" => \$opt_grep,
25 "progress|p" => \$opt_progress,
23 or die "Usage: try $0 --help"; 26 or die "Usage: try $0 --help";
24 27
25@ARGV = "." unless @ARGV; 28@ARGV = "." unless @ARGV;
26 29
27$opt_grep &&= qr{$opt_grep}s; 30$opt_grep &&= qr{$opt_grep}s;
31
32my ($n_dirs, $n_files, $n_stats) = (0, 0, 0);
33my ($n_last, $n_start) = (Time::HiRes::time) x 2;
28 34
29sub printfn { 35sub printfn {
30 my ($prefix, $files, $suffix) = @_; 36 my ($prefix, $files, $suffix) = @_;
31 37
32 if ($opt_grep) { 38 if ($opt_grep) {
45 51
46 $path .= "/"; 52 $path .= "/";
47 53
48 IO::AIO::poll_cb; 54 IO::AIO::poll_cb;
49 55
56 if ($opt_progress and $n_last + 1 < Time::HiRes::time) {
57 $n_last = Time::HiRes::time;
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
63 if $opt_progress;
64 }
65
50 aioreq_pri -1; 66 aioreq_pri -1;
67 ++$n_dirs;
51 aio_scandir $path, 8, sub { 68 aio_scandir $path, 8, sub {
52 my ($dirs, $files) = @_ 69 my ($dirs, $files) = @_
53 or warn "$path: $!\n"; 70 or warn "$path: $!\n";
54 71
55 printfn "", [$path] unless $opt_nodirs; 72 printfn "", [$path] unless $opt_nodirs;
56 printfn $path, $files unless $opt_nofiles; 73 printfn $path, $files unless $opt_nofiles;
57 74
75 $n_files += @$files;
76
58 if ($opt_stat) { 77 if ($opt_stat) {
59 aio_wd $path, sub { 78 aio_wd $path, sub {
60 my $wd = shift; 79 my $wd = shift;
61 80
62 aio_lstat [$wd, $_] for @$files; 81 aio_lstat [$wd, $_] for @$files;
82 $n_stats += @$files;
63 }; 83 };
64 } 84 }
65 85
66 &scan ("$path$_") for @$dirs; 86 &scan ("$path$_") for @$dirs;
67 }; 87 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines