Profiler/Visualizer/BasicGraphViz.pm

filter: Statementstmt 17.3% 8 / 46 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 0.0% 0 / 3 totaltotal 16.6% 10 / 60 CC 12 SCAR 47.7
CC
12
Cov
15%
OUTPUT
156.0
GET_ARGS
2.0
fix_label
2.0
CRAP 117.4
« Profiler/Parser.pm ↑ Summary Profiler/Visualizer/BasicSummary.pm »
1 # Declare our package
2 package POE::Devel::Profiler::Visualizer::BasicGraphViz;
3  
4 # Standard stuff to catch errors
5 1 ▶use strict qw(subs vars refs); # Make sure we can't mess up
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings FATAL => 'all'; # Enable warnings to catch errors
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Initialize our version
9 1 our $VERSION = '0.01';
10  
11 # Okay, we need to receive the arguments
12 0 ▶sub GET_ARGS {
Subroutine GET_ARGS: not called CC=1 SCAR=6.9
Pod undocumented
13 # We don't care!
14 0 return 1;
15 }
16  
17 # The actual work is here
18 0 ▶sub OUTPUT {
Subroutine OUTPUT: not called CC=12 SCAR=50.5
Pod undocumented
19 # Get the data structure
20 0 my( undef, $data ) = @_;
21
22 # Okay, start drawing the graph!
23 0 print "digraph " . fix_label( $data->{'PROGNAME'} ) . " {\n";
24
25 # Draw the sessions
26 0 foreach my $sess ( keys %{ $data->{'SESSION'} } ) {
27 0 print " subgraph cluster_session_" . fix_label( $sess ) . " {\n";
28
29 # Make a nice label
30 0 ▶ if ( exists $data->{'SESSION'}->{ $sess }->{'ALIASES'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{'SESSION'}{$sess}{'ALIASES'}) { } 0 0 0
31 0 my $alias = ( keys %{ $data->{'SESSION'}->{ $sess }->{'ALIASES'} } )[ rand( scalar( keys %{ $data->{'SESSION'}->{ $sess }->{'ALIASES'} } ) ) ];
32 0 print " label=\"$alias\";\n";
33 } else {
34 0 print " label=\"Session $sess\";\n";
35 }
36
37 # List the states
38 0 foreach my $state ( sort keys %{ $data->{'SESSION'}->{ $sess }->{'STATES'} } ) {
39 0 print " ses_" . fix_label( $sess ) . "_" . fix_label( $state ) . " [ label = \"$state\"];\n";
40 }
41
42 # End of session
43 0 print " }\n\n";
44 }
45
46 # Now, connect the dots!
47 0 foreach my $sess ( keys %{ $data->{'SESSION'} } ) {
48 # Loop over the states
49 0 foreach my $state ( keys %{ $data->{'SESSION'}->{ $sess }->{'STATES'} } ) {
50 0 my $label_from = "ses_" . fix_label( $sess ) . "_" . fix_label( $state );
51
52 # Loop over CALL/YIELD/POST
53 0 foreach my $type ( qw( CALL YIELD POST ) ) {
54 # Did this state do this?
55 0 ▶ if ( ! exists $data->{'SESSION'}->{ $sess }->{'STATES'}->{ $state }->{ $type } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $data->{"SESSION"}{$sess}{"STATES"}{$state}{$type}) 0 0 0
56 0 next;
57 }
58
59 # Are we yielding?
60 0 ▶ if ( $type eq 'YIELD' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'YIELD') { } 0 0 0
61 0 foreach my $yield_state ( keys %{ $data->{'SESSION'}->{ $sess }->{'STATES'}->{ $state }->{ $type } } ) {
62 # About time!
63 0 my $label_to = "ses_" . fix_label( $sess ) . "_" . fix_label( $yield_state );
64 0 print " $label_from -> $label_to;\n";
65 }
66 } else {
67 # Loop over all call/post
68 0 foreach my $ID ( keys %{ $data->{'SESSION'}->{ $sess }->{'STATES'}->{ $state }->{ $type } } ) {
69 # Now, we got the ID, loop over the states
70 0 foreach my $ID_state ( keys %{ $data->{'SESSION'}->{ $sess }->{'STATES'}->{ $state }->{ $type }->{ $ID } } ) {
71 # About time!
72 0 print " $label_from -> ses_" . fix_label( $ID ) . "_" . fix_label( $ID_state ) . ";\n";
73 }
74 }
75 }
76 }
77 }
78 }
79
80 # End the graph!
81 0 print "}\n";
82 }
83  
84 # Fixes annoying label typos
85 0 ▶sub fix_label {
Subroutine fix_label: not called CC=1 SCAR=6.9
Pod undocumented
86 0 my $label = shift;
87 0 $label =~ s/\W+/_/g;
88 0 return $label;
89 }
90  
91 # End of module
92 1 1;
93 __END__
« Profiler/Parser.pm ↑ Summary Profiler/Visualizer/BasicSummary.pm »