| 1 |
package Analizo::Command::metrics_history; |
| 2 |
use Analizo -command; |
| 3 |
use parent qw(Analizo::Command); |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use Analizo::Batch::Git; |
| 7 |
|
| 8 |
#ABSTRACT: processes a Git repository collection metrics |
| 9 |
|
| 10 |
=head1 NAME |
| 11 |
|
| 12 |
analizo-metrics-history - processes a Git repository collection metrics |
| 13 |
|
| 14 |
=head1 USAGE |
| 15 |
|
| 16 |
analizo metrics-history [OPTIONS] [<input>] |
| 17 |
|
| 18 |
=cut |
| 19 |
|
| 20 |
sub usage_desc { "%c metrics-history %o [<input>]" } |
| 21 |
|
| 22 |
sub command_names { qw/metrics-history/ } |
| 23 |
|
| 24 |
sub opt_spec { |
| 25 |
return ( |
| 26 |
[ 'output|o=s', 'output file name' ], |
| 27 |
[ 'list|l', 'just print out the ids of the commits that would be processed '], |
| 28 |
[ 'language=s', 'process only filenames matching known extensions for the <lang> programming' ], |
| 29 |
[ 'exclude|x=s', 'exclude <dirs> (a colon-separated list of directories) from the analysis' ], |
| 30 |
[ 'parallel|p=i', 'activates support for parallel processing' ], |
| 31 |
[ 'format|f=s', 'specifies the output format', { default => 'csv' } ], |
| 32 |
[ 'progressbar|b', 'displays a progress bar during the execution' ], |
| 33 |
); |
| 34 |
} |
| 35 |
|
| 36 |
sub validate { |
| 37 |
my ($self, $opt, $args) = @_; |
| 38 |
unless ($self->output_driver($opt->format)) { |
| 39 |
$self->usage_error("Invalid output driver " . $opt->format); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
sub output_driver { |
| 44 |
my ($self, $format) = @_; |
| 45 |
my %available_outputs = ( |
| 46 |
csv => 'Analizo::Batch::Output::CSV', |
| 47 |
db => 'Analizo::Batch::Output::DB', |
| 48 |
); |
| 49 |
$available_outputs{$format}; |
| 50 |
} |
| 51 |
|
| 52 |
sub load_output_driver { |
| 53 |
my ($self, $format) = @_; |
| 54 |
my $output_driver = $self->output_driver($format); |
| 55 |
eval "require $output_driver"; |
| 56 |
return $output_driver->new; |
| 57 |
} |
| 58 |
|
| 59 |
sub execute { |
| 60 |
my ($self, $opt, $args) = @_; |
| 61 |
my $batch = Analizo::Batch::Git->new(@$args); |
| 62 |
if ($opt->list) { |
| 63 |
while (my $job = $batch->next()) { |
| 64 |
print $job->id, "\n"; |
| 65 |
} |
| 66 |
exit 0; |
| 67 |
} |
| 68 |
if ($opt->language) { |
| 69 |
require Analizo::LanguageFilter; |
| 70 |
my $language_filter = Analizo::LanguageFilter->new($opt->language); |
| 71 |
$batch->filters($language_filter); |
| 72 |
} |
| 73 |
if ($opt->exclude) { |
| 74 |
my @excluded_directories = split(':', $opt->exclude); |
| 75 |
$batch->exclude(@excluded_directories); |
| 76 |
} |
| 77 |
my $output = $self->load_output_driver($opt->format); |
| 78 |
if ($opt->output) { |
| 79 |
$output->file($opt->output); |
| 80 |
} |
| 81 |
my $runner = undef; |
| 82 |
if ($opt->parallel) { |
| 83 |
require Analizo::Batch::Runner::Parallel; |
| 84 |
$runner = Analizo::Batch::Runner::Parallel->new($opt->parallel); |
| 85 |
} else { |
| 86 |
require Analizo::Batch::Runner::Sequential; |
| 87 |
$runner = Analizo::Batch::Runner::Sequential->new; |
| 88 |
} |
| 89 |
if ($opt->progressbar) { |
| 90 |
require Term::ProgressBar; |
| 91 |
my $progressbar = Term::ProgressBar->new({ count => 100, ETA => 'linear' }); |
| 92 |
$runner->progress( |
| 93 |
sub { |
| 94 |
my ($job, $done, $total) = @_; |
| 95 |
$progressbar->update(100 * $done / $total); |
| 96 |
} |
| 97 |
); |
| 98 |
} |
| 99 |
$runner->run($batch, $output); |
| 100 |
} |
| 101 |
|
| 102 |
1; |
| 103 |
|
| 104 |
=head1 DESCRIPTION |
| 105 |
|
| 106 |
Processes a Git repository collection metrics for every single revision. |
| 107 |
|
| 108 |
B<analizo metrics-history> will process I<input>, a Git repository with a |
| 109 |
working copy of the source code (i.e. not a bare git repository), checkout |
| 110 |
every relevant commit and run B<analizo metrics> on it. The metrics for all of |
| 111 |
the revisions will be accumulated in a file called I<metrics.csv> inside |
| 112 |
I<input>. If I<input> is omitted, the current directory (.) s |
| 113 |
assumed. |
| 114 |
|
| 115 |
analizo metrics-history is part of the analizo suite. |
| 116 |
|
| 117 |
=head1 RELEVANT COMMITS |
| 118 |
|
| 119 |
B<analizo metrics-history> considers as relevant the commits that changed at |
| 120 |
least one source code file. Consequently, it skips all the commits where no |
| 121 |
source code file was changed, such as documentation, translations, build system |
| 122 |
changes, etc. |
| 123 |
|
| 124 |
Currently we support C, C++, Java and C# projects, and therefore files considered |
| 125 |
source code are the ones terminated in I<.c>, I<.h>, I<.cpp>, I<.cxx>, I<.cc>, |
| 126 |
I<.hh>, I<.hpp>, I<.java> and I<.cs>. |
| 127 |
|
| 128 |
=head1 OPTIONS |
| 129 |
|
| 130 |
=over |
| 131 |
|
| 132 |
=item --parallel N, -p N |
| 133 |
|
| 134 |
Activates support for parallel processing, using I<N> concurrent worker |
| 135 |
processes. Usually you will want N to be less than or equal to the number of |
| 136 |
CPUs in your machine. |
| 137 |
|
| 138 |
Note that analizo metrics extraction is a CPU-intensive process, so setting N |
| 139 |
as the exactly number of CPUs you have may bring your machine to an unusable |
| 140 |
state. |
| 141 |
|
| 142 |
=item --language LANGUAGE, --exclude DIRECTORY |
| 143 |
|
| 144 |
Use programming language and directory exclusion filters. See |
| 145 |
B<analizo-metrics(1)> for a description of these options. |
| 146 |
|
| 147 |
=item --output <file>, -o <file> |
| 148 |
|
| 149 |
Make the output be written to I<file>. The default value and valid values |
| 150 |
depend on the output format, see "Output formats" below. |
| 151 |
|
| 152 |
=item --format FORMAT, -f FORMAT |
| 153 |
|
| 154 |
Specifies with output driver, and consequently the output format, to use. See |
| 155 |
"Output Formats" below for a description of the available output drivers. |
| 156 |
|
| 157 |
=item --list, -l |
| 158 |
|
| 159 |
Instead of actually processing the history, just print out the ids of the |
| 160 |
commits that would be processed. |
| 161 |
|
| 162 |
=item --progressbar, -b |
| 163 |
|
| 164 |
Displays a progress bar during the execution, so that you know approximately how |
| 165 |
long analizo is going to take to finish. |
| 166 |
|
| 167 |
=back |
| 168 |
|
| 169 |
=head1 Output formats |
| 170 |
|
| 171 |
Using the I<--format> option, you can use the following output drivers: |
| 172 |
|
| 173 |
=head2 csv |
| 174 |
|
| 175 |
This is the default output driver. By default, the output will be written to |
| 176 |
the standard output. If can direct the output to a file using the I<--output> |
| 177 |
option. |
| 178 |
|
| 179 |
=head2 db |
| 180 |
|
| 181 |
Stores the extracted data in a relational database. |
| 182 |
|
| 183 |
When you use this driver, you can specify where exactly to store the data using |
| 184 |
the I<--output> option. If you do not specify an explicit target, analizo will |
| 185 |
write to a SQLite database in a file called I<output.sqlite3> in the current |
| 186 |
directory. If you pass a filename, and analizo will store the data in a SQLite |
| 187 |
database that will be created on that file. You can direct the output to any |
| 188 |
other database by using I<--output DSN>, where I<DSN> is a DBI Data Source |
| 189 |
Name. |
| 190 |
|
| 191 |
You can check B<DBI>(3pm) for details. Note that if you a database other than |
| 192 |
SQLite, you must make sure that you have the corresponding DBI driver installed. |
| 193 |
|
| 194 |
Examples: |
| 195 |
|
| 196 |
B<$ analizo metrics-history -f db -o history.db> |
| 197 |
|
| 198 |
Writes the output to a SQLite database called I<history.db>. |
| 199 |
|
| 200 |
B<$ analizo metrics-history -f db -o 'dbi:Pg:dbname=pgdb'> |
| 201 |
|
| 202 |
Writes the data to a PostgreSQL database called I<pgdb>. This requires the |
| 203 |
I<DBI::Pg> Perl module. |
| 204 |
|
| 205 |
analizo was not tested with MySQL yet. |
| 206 |
|
| 207 |
=head1 SEE ALSO |
| 208 |
|
| 209 |
B<analizo-metrics(1)> |
| 210 |
|
| 211 |
=head1 COPYRIGHT AND AUTHORS |
| 212 |
|
| 213 |
See B<analizo(1)>. |
| 214 |
|
| 215 |
=cut |