| 1 |
package Analizo::Command::metrics_batch; |
| 2 |
use Analizo -command; |
| 3 |
use parent qw(Analizo::Command); |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use Analizo::Batch::Directories; |
| 7 |
use Analizo::Batch::Output::CSV; |
| 8 |
use File::Basename; |
| 9 |
|
| 10 |
# ABSTRACT: processes several source code directories in batch |
| 11 |
|
| 12 |
=head1 NAME |
| 13 |
|
| 14 |
analizo-metrics-batch - processes several source code directories in batch |
| 15 |
|
| 16 |
=head1 USAGE |
| 17 |
|
| 18 |
analizo metrics-batch [OPTIONS] [<input> [<input> ...]] |
| 19 |
|
| 20 |
=cut |
| 21 |
|
| 22 |
sub usage_desc { "%c metrics-batch %o [<input> [<input> ...]]" } |
| 23 |
|
| 24 |
sub command_names { qw/metrics-batch/ } |
| 25 |
|
| 26 |
sub opt_spec { |
| 27 |
return ( |
| 28 |
[ 'output|o=s', 'output file name', { default => 'metrics.csv' } ], |
| 29 |
[ 'quiet|q', 'supresses messages to standard output' ], |
| 30 |
[ 'parallel|p=i', 'activates support for parallel processing' ], |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
sub validate { |
| 35 |
my ($self, $opt, $args) = @_; |
| 36 |
if ($opt->output && ! -w dirname($opt->output)) { |
| 37 |
$self->usage_error("Output is not writable!"); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
sub execute { |
| 42 |
my ($self, $opt, $args) = @_; |
| 43 |
my $runner = undef; |
| 44 |
if ($opt->parallel) { |
| 45 |
require Analizo::Batch::Runner::Parallel; |
| 46 |
$runner = Analizo::Batch::Runner::Parallel->new($opt->parallel); |
| 47 |
} else { |
| 48 |
require Analizo::Batch::Runner::Sequential; |
| 49 |
$runner = Analizo::Batch::Runner::Sequential->new; |
| 50 |
} |
| 51 |
unless ($opt->quiet) { |
| 52 |
$runner->progress( |
| 53 |
sub { |
| 54 |
my ($job, $done, $total) = @_; |
| 55 |
printf("I: Processed %s.\n", $job->id); |
| 56 |
} |
| 57 |
); |
| 58 |
} |
| 59 |
my $batch = Analizo::Batch::Directories->new(@$args); |
| 60 |
my $output = Analizo::Batch::Output::CSV->new; |
| 61 |
$output->file($opt->output); |
| 62 |
$runner->run($batch, $output); |
| 63 |
} |
| 64 |
|
| 65 |
=head1 DESCRIPTION |
| 66 |
|
| 67 |
Processes several source code directories in batch running B<analizo metrics> |
| 68 |
for each and optionally consolidating the results in a single data file. |
| 69 |
|
| 70 |
B<analizo metrics-batch> is useful when you want to analyze several projects at |
| 71 |
once, or several different versions of the same project. You pass a list of |
| 72 |
directories in the command line and each one will be analyzed as a separate |
| 73 |
project. If no directories are passed in the command line, all of the |
| 74 |
subdirectories of the current directory will be analized. |
| 75 |
|
| 76 |
For example, suppose you want to process 5 consecutive releases of |
| 77 |
I<myproject>, from version 0.1.0 to 0.5.0. |
| 78 |
|
| 79 |
=over |
| 80 |
|
| 81 |
=item |
| 82 |
|
| 83 |
First you unpack the release tarballs for those versions in a directory, say |
| 84 |
/tmp/analysis: |
| 85 |
|
| 86 |
$ ls -1 /tmp/analysis |
| 87 |
myproject-0.1.0 |
| 88 |
myproject-0.2.0 |
| 89 |
myproject-0.3.0 |
| 90 |
myproject-0.4.0 |
| 91 |
myproject-0.5.0 |
| 92 |
|
| 93 |
=item |
| 94 |
|
| 95 |
Then you change to that directory, and then run B<analizo metrics-batch>: |
| 96 |
|
| 97 |
$ cd /tmp/analysis |
| 98 |
$ analizo metrics-batch |
| 99 |
|
| 100 |
=item |
| 101 |
|
| 102 |
B<analizo metrics-batch> will collect the metrics |
| 103 |
data in a single .csv file, that you can import in spreadsheet software or |
| 104 |
statistical packages. |
| 105 |
|
| 106 |
=back |
| 107 |
|
| 108 |
analizo metrics-batch is part of the analizo suite. |
| 109 |
|
| 110 |
=head1 OPTIONS |
| 111 |
|
| 112 |
=over |
| 113 |
|
| 114 |
=item --parallel N, -p N |
| 115 |
|
| 116 |
Activates support for parallel processing, using I<N> concurrent worker |
| 117 |
processes. Usually you will want N to be less than or equal to the number of |
| 118 |
CPUs in your machine. |
| 119 |
|
| 120 |
Note that analizo metrics extraction is a CPU-intensive process, so setting N |
| 121 |
as the exactly number of CPUs you have may bring your machine to an unusable |
| 122 |
state. |
| 123 |
|
| 124 |
=item --output <file>, -o <file> |
| 125 |
|
| 126 |
Write output to <file>. Default is to write to I<metrics.csv>. That file can |
| 127 |
then be opened in data analysis programs. |
| 128 |
|
| 129 |
=item --quiet, -q |
| 130 |
|
| 131 |
Suppresses messages to standard output. |
| 132 |
|
| 133 |
=back |
| 134 |
|
| 135 |
=head1 COPYRIGHT AND AUTHORS |
| 136 |
|
| 137 |
See B<analizo(1)>. |
| 138 |
|
| 139 |
=cut |
| 140 |
|
| 141 |
1; |