| 1 | package Analizo::Command::metrics_history; | ||||||||||
| 2 | 9 | ▶ | use Analizo -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 9 | ▶ | use parent qw(Analizo::Command); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 9 | ▶ | use Analizo::Batch::Git; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 5 | ▶ | sub usage_desc { "%c metrics-history %o [<input>]" } | ||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | |||||||||||
| 22 | 26 | ▶ | sub command_names { qw/metrics-history/ } | ||||||||
|
Subroutine
command_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | |||||||||||
| 24 | 5 | ▶ | sub opt_spec { | ||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 25 | return ( | ||||||||||
| 26 | 5 | [ '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 | 0 | ▶ | sub validate { | ||||||||
|
Subroutine
validate: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 37 | 0 | my ($self, $opt, $args) = @_; | |||||||||
| 38 | 0 | ▶ | unless ($self->output_driver($opt->format)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | $self->usage_error("Invalid output driver " . $opt->format); | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 4 | ▶ | sub output_driver { | ||||||||
|
Subroutine
output_driver: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 44 | 4 | my ($self, $format) = @_; | |||||||||
| 45 | 4 | my %available_outputs = ( | |||||||||
| 46 | csv => 'Analizo::Batch::Output::CSV', | ||||||||||
| 47 | db => 'Analizo::Batch::Output::DB', | ||||||||||
| 48 | ); | ||||||||||
| 49 | 4 | $available_outputs{$format}; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub load_output_driver { | ||||||||
|
Subroutine
load_output_driver: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 53 | 0 | my ($self, $format) = @_; | |||||||||
| 54 | 0 | my $output_driver = $self->output_driver($format); | |||||||||
| 55 | 0 | eval "require $output_driver"; | |||||||||
| 56 | 0 | return $output_driver->new; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 60 | 0 | my ($self, $opt, $args) = @_; | |||||||||
| 61 | 0 | my $batch = Analizo::Batch::Git->new(@$args); | |||||||||
| 62 | 0 | ▶ | if ($opt->list) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | ▶ | while (my $job = $batch->next()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | print $job->id, "\n"; | |||||||||
| 65 | } | ||||||||||
| 66 | 0 | exit 0; | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | ▶ | if ($opt->language) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | require Analizo::LanguageFilter; | |||||||||
| 70 | 0 | my $language_filter = Analizo::LanguageFilter->new($opt->language); | |||||||||
| 71 | 0 | $batch->filters($language_filter); | |||||||||
| 72 | } | ||||||||||
| 73 | 0 | ▶ | if ($opt->exclude) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 0 | my @excluded_directories = split(':', $opt->exclude); | |||||||||
| 75 | 0 | $batch->exclude(@excluded_directories); | |||||||||
| 76 | } | ||||||||||
| 77 | 0 | my $output = $self->load_output_driver($opt->format); | |||||||||
| 78 | 0 | ▶ | if ($opt->output) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $output->file($opt->output); | |||||||||
| 80 | } | ||||||||||
| 81 | 0 | my $runner = undef; | |||||||||
| 82 | 0 | ▶ | if ($opt->parallel) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | require Analizo::Batch::Runner::Parallel; | |||||||||
| 84 | 0 | $runner = Analizo::Batch::Runner::Parallel->new($opt->parallel); | |||||||||
| 85 | } else { | ||||||||||
| 86 | 0 | require Analizo::Batch::Runner::Sequential; | |||||||||
| 87 | 0 | $runner = Analizo::Batch::Runner::Sequential->new; | |||||||||
| 88 | } | ||||||||||
| 89 | 0 | ▶ | if ($opt->progressbar) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | require Term::ProgressBar; | |||||||||
| 91 | 0 | my $progressbar = Term::ProgressBar->new({ count => 100, ETA => 'linear' }); | |||||||||
| 92 | $runner->progress( | ||||||||||
| 93 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 94 | 0 | my ($job, $done, $total) = @_; | |||||||||
| 95 | 0 | $progressbar->update(100 * $done / $total); | |||||||||
| 96 | } | ||||||||||
| 97 | 0 | ); | |||||||||
| 98 | } | ||||||||||
| 99 | 0 | $runner->run($batch, $output); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 9 | 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 | ||||||||||