| 1 | package Analizo::Command::graph; | ||||||||||||||||||||||||||||
| 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::Extractor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Graph::Writer::Dot; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ABSTRACT: dependency graph generator | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | analizo-graph - dependency graph generator | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 USAGE | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | analizo graph [OPTIONS] <input> [<input> [<input> ...]] | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub usage_desc { "%c graph %o <input> [<input> [<input> ...]]" } | ||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | return ( | ||||||||||||||||||||||||||||
| 26 | 2 | [ 'extractor=s', 'which extractor method use to parse the source code' ], | |||||||||||||||||||||||||||
| 27 | [ 'output|o=s', 'output file name' ], | ||||||||||||||||||||||||||||
| 28 | [ 'omit=s', 'omit the given functions from the call graph', { default => '' } ], | ||||||||||||||||||||||||||||
| 29 | [ 'cluster', 'cluster the functions into files' ], | ||||||||||||||||||||||||||||
| 30 | [ 'modules', 'group the functions by modules(files)' ], | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | $self->usage_error("No input files!") unless @$args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my @unreadable = grep { ! -r $_ || ! -e $_ } @$args; | ||||||||||||||||||||||||||
|
Condition0%0/3
-r $_ && -e $_
MC/DC0%0/2
-r $_ && -e $_
-r $_
-e $_
Truth table0%0/3
A && B
A= -r $_B= -e $_
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (@unreadable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | foreach my $file (@unreadable) { | |||||||||||||||||||||||||||
| 40 | 0 | $self->usage_error("$file is not readable"); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($opt->output && ! -w dirname($opt->output)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->output and not -w dirname($opt->output)
MC/DC0%0/2
$opt->output and not -w dirname($opt->output)
$opt->output
not -w dirname($opt->output)
Truth table0%0/3
A and not(B)
A= $opt->outputB= not -w dirname($opt->output)
| |||||||||||||||||||||||||||||
| 44 | 0 | $self->usage_error("No such file or directory"); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 50 | 0 | my $extractor = Analizo::Extractor->load($opt->extractor); | |||||||||||||||||||||||||||
| 51 | 0 | $extractor->process(@$args); | |||||||||||||||||||||||||||
| 52 | 0 | my @omitted = split /,/, $opt->omit; | |||||||||||||||||||||||||||
| 53 | 0 | my $graph = $extractor->model->callgraph( | |||||||||||||||||||||||||||
| 54 | group_by_module => $opt->modules, | ||||||||||||||||||||||||||||
| 55 | omit => \@omitted, | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($opt->output) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | open STDOUT, '>', $opt->output or die "$!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | my $stdout = \*STDOUT; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | my $graph_writer = Graph::Writer::Dot->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | cluster => ($opt->cluster ? 'group' : undef), | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | 0 | $graph_writer->write_graph($graph, $stdout); | |||||||||||||||||||||||||||
| 65 | 0 | close STDOUT; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | analizo graph reads the dependency information from one or more source code | ||||||||||||||||||||||||||||
| 71 | directories passed as arguments, and produces as output the graph of | ||||||||||||||||||||||||||||
| 72 | dependencies between the modules of the software in the graphviz(1) format. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | analizo graph is part of the analizo suite. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 REQUIRED ARGUMENTS | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =over | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =item <input>... | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | The input directories (or files) with source code to be processed. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Although you can pass individual files as input, this tool is more useful if | ||||||||||||||||||||||||||||
| 85 | you pass entire source directories. If you pass just a couple of files, their | ||||||||||||||||||||||||||||
| 86 | dependencies on modules that are not declared and/or implemented in those | ||||||||||||||||||||||||||||
| 87 | files will not be calculated. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =back | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =over | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item --omit <functions> | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Omit the given functions from the call graph. Multiple function names | ||||||||||||||||||||||||||||
| 98 | may be given separated by commas. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =item --cluster | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Cluster the functions into files, so you can see in which files are the calling | ||||||||||||||||||||||||||||
| 103 | and called functions. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =item --modules | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Group the functions by modules (files or OO classes), and only represent calls between | ||||||||||||||||||||||||||||
| 108 | modules. This is useful to see the dependencies between the modules of the | ||||||||||||||||||||||||||||
| 109 | program, instead of focusing on specific functions. The arrows between the | ||||||||||||||||||||||||||||
| 110 | modules will be labelled with a number that represents the number of different | ||||||||||||||||||||||||||||
| 111 | places in which the calling module calls functions in the called module (i.e. | ||||||||||||||||||||||||||||
| 112 | how many times module A calls module B). | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | It doesn't make much sense to use --modules together with --cluster. | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item --extractor <extractor> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Define which extractor method use to parse the source code. Currently "Doxyparse" | ||||||||||||||||||||||||||||
| 119 | is the only extractor available. Default is Doxyparse. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item --output <file>, -o <file> | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Use a file as output | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =back | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 VIEWING THE GRAPH | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | To view the generated graph, pipe analizo's output to one of the | ||||||||||||||||||||||||||||
| 130 | Graphviz tools. You can use B<dotty(1)> to display the graph in a | ||||||||||||||||||||||||||||
| 131 | X11 window: | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | $ analizo graph src/ | dotty - | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | You can also generate a file to print or include in a document | ||||||||||||||||||||||||||||
| 136 | by using the B<dot(1)>. | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | To generate a PNG image called F<graph.png>: | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | $ analizo graph src/ | dot -Tpng -ograph.png - | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | To generate a PostScript version of the dependency graph for printing, you can | ||||||||||||||||||||||||||||
| 143 | also use the B<dot>. For example, to generate a dependency graph in the file | ||||||||||||||||||||||||||||
| 144 | F<graph.ps> fitting everything on a US letter size page in landscape mode, try | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | $ analizo graph src/ | dot -Grotate=90 -Gsize=11,8.5 -Tps -o graph.ps | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Sometimes, the graph will fit better if the dependencies arrows go from left to | ||||||||||||||||||||||||||||
| 149 | right instead of top to bottom. The B<dot> option B<-Grankdir=LR> will do | ||||||||||||||||||||||||||||
| 150 | that: | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | $ analizo graph src/ | dot -Gsize=8.5,11 -Grankdir=LR -Tps -o graph.ps | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | For large software, the graph may end up too small | ||||||||||||||||||||||||||||
| 155 | to comfortably read. If that happens, try N-up printing: | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | $ analizo graph src/ | dot -Gpage=8.5,11 -Tps -o graph.ps | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | You can also try playing with other B<dot> options such as B<-Gratio>, | ||||||||||||||||||||||||||||
| 160 | or for a different style of graph, try using B<neato> instead of | ||||||||||||||||||||||||||||
| 161 | B<dot>. See the Graphviz documentation for more information about the | ||||||||||||||||||||||||||||
| 162 | various options available for customizing the style of the graph. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 READING THE GRAPH | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | When generating a graph in the function level (i.g. without the I<--modules> | ||||||||||||||||||||||||||||
| 167 | option), function calls are displayed as solid arrows. A dotted arrow means | ||||||||||||||||||||||||||||
| 168 | that the function the arrow points from takes the address of the function the | ||||||||||||||||||||||||||||
| 169 | arrow points to; this typically indicates that the latter function is being | ||||||||||||||||||||||||||||
| 170 | used as a callback. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | When the I<--modules> option is on, then there are only solid arrows. An arrow | ||||||||||||||||||||||||||||
| 173 | from I<A> to I<B> means that I<A> depends on I<B>. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | B<dotty(1)>, B<dot(1)>, B<neato(1)>, B<analizo(1)> | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head1 COPYRIGHT AND AUTHORS | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | See B<analizo(1)>. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 9 | 1; | |||||||||||||||||||||||||||