| 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
| |||||||||||
| 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
| |||||||||||
| 56 | 0 | next; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | # Are we yielding? | ||||||||||
| 60 | 0 | ▶ | if ( $type eq 'YIELD' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||