Revision: 979 Author: tim.bunce Date: Fri Dec 18 13:58:11 2009 Log: Added $VERSION cross-check (I guess we really ought to use .PL files) Added --verbose option. Tweaked usage() usage and text. Added check for open() failing. Optimized the dispatcher a little.
http://code.google.com/p/perl-devel-nytprof/source/detail?r=979 Modified: /trunk/bin/nytprofmerge ======================================= --- /trunk/bin/nytprofmerge Fri Dec 18 09:04:41 2009 +++ /trunk/bin/nytprofmerge Fri Dec 18 13:58:11 2009 @@ -12,39 +12,45 @@ use warnings; use strict; + +use Devel::NYTProf::Core; require Devel::NYTProf::FileHandle; use Devel::NYTProf::ReadStream qw(for_chunks); + +our $VERSION = '2.11'; + +if ($VERSION != $Devel::NYTProf::Core::VERSION) { + die "$0 version '$VERSION' doesn't match version '$Devel::NYTProf::Core::VERSION' of $INC{'Devel/NYTProf/Core.pm'}\n"; +} use Getopt::Long; use Carp; -my %opt = ( - out => 'nytprof-merged.out', - ); - -GetOptions(\%opt, qw/out|o=s help|h/) - or do { - usage(); - exit 1; - }; - -if (defined($opt{help})) { - usage(); - exit; -} +my $opt_out = 'nytprof-merged.out'; + +GetOptions( + 'out|o=s' => \$opt_out, + 'help|h' => \&usage, + 'verbose|v' => \my $opt_verbose, +) or usage(); + sub usage { - print <<END -usage: [perl] nytprofmerge [opts] - --out <dir>, -o <dir> Place merged file [default: ./nytprof-merged.out] + print <<END; +usage: [perl] nytprofmerge [opts] nytprof-file [...] + --out <file>, -o <file> Name of output file [default: $opt_out] --help, -h Print this message + --verbose, -v Be more verbose This script of part of the Devel::NYTProf distribution. See http://search.cpan.org/dist/Devel-NYTProf/ for details and copyright. END + exit 1; } -my $out = Devel::NYTProf::FileHandle::open($opt{out}, "wb"); +print "Writing $opt_out\n" if $opt_verbose; +my $out = Devel::NYTProf::FileHandle::open($opt_out, "wb") + or die "Error opening $opt_out: $!\n"; my $next_fid = 1; my %file_to_fid; @@ -179,15 +185,15 @@ ); foreach $input (@ARGV) { + print "Reading $input...\n" if $opt_verbose; for_chunks { - my $tag = $_[0]; - - my $sub = $dispatcher{$tag}; - die "Unknown tag '$tag'" unless defined $sub; + my $sub = $dispatcher{$_[0]} + or die "Unknown tag '$_[0]' in $input\n"; &$sub(@_); } filename => $input; } +print "Finalizing...\n" if $opt_verbose; # Deterministic order is useful for testing. foreach my $fid_line (sort keys %callers) { my ($fid, $line) = split ',', $fid_line; @@ -204,3 +210,6 @@ } } } + +print "Done.\n" if $opt_verbose; +exit 0; -- You've received this message because you are subscribed to the Devel::NYTProf Development User group. Group hosted at: http://groups.google.com/group/develnytprof-dev Project hosted at: http://perl-devel-nytprof.googlecode.com CPAN distribution: http://search.cpan.org/dist/Devel-NYTProf To post, email: [email protected] To unsubscribe, email: [email protected]
