]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/tools/handlerviz.pl
6 # A visualisation tool for post-processing the debug output generated by
7 # Asio-based programs. Programs write this output to the standard error stream
8 # when compiled with the define `BOOST_ASIO_ENABLE_HANDLER_TRACKING'.
10 # This tool generates output intended for use with the GraphViz tool `dot'. For
11 # example, to convert output to a PNG image, use:
13 # perl handlerviz.pl < output.txt | dot -Tpng > output.png
15 # To convert to a PDF file, use:
17 # perl handlerviz.pl < output.txt | dot -Tpdf > output.pdf
19 # Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
21 # Distributed under the Boost Software License, Version 1.0. (See accompanying
22 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
33 my %pending_nodes = ();
35 #-------------------------------------------------------------------------------
36 # Parse the debugging output and populate the nodes and edges.
38 sub parse_debug_output
()
44 if ($line =~ /\@asio\|([^|]*)\|([^|]*)\|(.*)$/)
51 if ($action =~ /^([0-9]+)\*([0-9]+)$/)
55 my $label = $description;
60 $begin = "a" . $anon_id++;
61 $anon_nodes{$begin} = $timestamp;
62 $all_nodes{"$timestamp-$begin"} = $begin;
65 my %edge = ( begin
=>$begin, end
=>$end, label
=>$label );
68 $pending_nodes{$end} = 1;
72 elsif ($action =~ /^([0-9]+)\^([0-9]+)$/)
76 if (not exists($locations{($1,$2)}))
78 $locations{($1,$2)} = ();
80 push(@{$locations{($1,$2)}}, $description);
84 # Begin handler invocation.
85 elsif ($action =~ /^>([0-9]+)$/)
87 my %new_node = ( label
=>$description, entry
=>$timestamp );
88 $new_node{content
} = ();
89 $nodes{$1} = \
%new_node;
90 $all_nodes{"$timestamp-$1"} = $1;
91 delete($pending_nodes{$1});
94 # End handler invocation.
95 elsif ($action =~ /^<([0-9]+)$/)
97 $nodes{$1}->{exit} = $timestamp;
100 # Handler threw exception.
101 elsif ($action =~ /^!([0-9]+)$/)
103 push(@{$nodes{$1}->{content
}}, "exception");
106 # Handler was destroyed without being invoked.
107 elsif ($action =~ /^~([0-9]+)$/)
109 my %new_node = ( label
=>"$timestamp destroyed" );
110 $new_node{content
} = ();
111 $nodes{$1} = \
%new_node;
112 $all_nodes{"$timestamp-$1"} = $1;
113 delete($pending_nodes{$1});
116 # Handler performed some operation.
117 elsif ($action =~ /^([0-9]+)$/)
121 my $id = "a" . $anon_id++;
122 $anon_nodes{$id} = "$timestamp\\l$description";
123 $all_nodes{"$timestamp-$id"} = $id;
127 push(@{$nodes{$1}->{content
}}, "$description");
134 #-------------------------------------------------------------------------------
135 # Helper function to convert a string to escaped HTML text.
140 $text =~ s/&/\&\;/g;
141 $text =~ s/</\<\;/g;
142 $text =~ s/>/\>\;/g;
147 #-------------------------------------------------------------------------------
148 # Templates for dot output.
150 my $graph_header = <<"EOF";
151 /* Generated by handlerviz.pl */
152 digraph "handlerviz output"
154 graph [ nodesep="1" ];
155 node [ shape="box", fontsize="9" ];
156 edge [ arrowtail="dot", fontsize="9" ];
159 my $graph_footer = <<"EOF";
163 my $node_header = <<"EOF";
166 label=<<table border="0" cellspacing="0">
167 <tr><td align="left" bgcolor="gray" border="0">%label%</td></tr>
170 my $node_footer = <<"EOF";
175 my $node_content = <<"EOF";
176 <tr><td align="left" bgcolor="white" border="0">
177 <font face="mono" point-size="9">%content%</font>
181 my $anon_nodes_header = <<"EOF";
183 node [ shape="record" ];
186 my $anon_nodes_footer = <<"EOF";
190 my $anon_node = <<"EOF";
191 "%name%" [ label="%label%", color="gray" ];
194 my $pending_nodes_header = <<"EOF";
196 node [ shape="record", color="red" ];
200 my $pending_nodes_footer = <<"EOF";
204 my $pending_node = <<"EOF";
208 my $edges_header = <<"EOF";
210 edge [ style="dashed", arrowhead="open" ];
213 my $edges_footer = <<"EOF";
218 "%begin%" -> "%end%" [ label="%label%", labeltooltip="%tooltip%" ]
221 my $node_order_header = <<"EOF";
223 node [ style="invisible" ];
224 edge [ style="invis", weight="100" ];
227 my $node_order_footer = <<"EOF";
231 my $node_order = <<"EOF";
237 "o%begin%" -> "o%end%";
240 #-------------------------------------------------------------------------------
241 # Generate dot output from the nodes and edges.
245 foreach my $name (sort keys %nodes)
247 my $node = $nodes{$name};
248 my $entry = $node->{entry
};
249 my $exit = $node->{exit};
250 my $label = escape
($node->{label
});
251 my $header = $node_header;
252 $header =~ s/%name%/$name/g;
253 $header =~ s/%label%/$label/g;
256 if (defined($exit) and defined($entry))
258 my $line = $node_content;
259 my $content = $entry . " + " . sprintf("%.6f", $exit - $entry) . "s";
260 $line =~ s/%content%/$content/g;
264 foreach my $content (@{$node->{content
}})
266 $content = escape
($content);
267 $content = " " if length($content) == 0;
268 my $line = $node_content;
269 $line =~ s/%content%/$content/g;
277 sub print_anon_nodes
()
279 print($anon_nodes_header);
280 foreach my $name (sort keys %anon_nodes)
282 my $label = $anon_nodes{$name};
283 my $line = $anon_node;
284 $line =~ s/%name%/$name/g;
285 $line =~ s/%label%/$label/g;
288 print($anon_nodes_footer);
291 sub print_pending_nodes
()
293 print($pending_nodes_header);
294 foreach my $name (sort keys %pending_nodes)
296 my $line = $pending_node;
297 $line =~ s/%name%/$name/g;
300 print($pending_nodes_footer);
305 print($edges_header);
306 foreach my $e (@edges)
308 my $begin = $e->{begin
};
310 my $label = $e->{label
};
312 if (exists($locations{($begin,$end)}))
314 for my $line (@{$locations{($begin,$end)}})
316 $tooltip = $tooltip . escape
($line) . "\n";
320 $line =~ s/%begin%/$begin/g;
321 $line =~ s/%end%/$end/g;
322 $line =~ s/%label%/$label/g;
323 $line =~ s/%tooltip%/$tooltip/g;
326 print($edges_footer);
329 sub print_node_order
()
332 print($node_order_header);
333 foreach my $name (sort keys %all_nodes)
338 my $end = $all_nodes{$name};
339 my $line = $node_order;
340 $line =~ s/%begin%/$begin/g;
341 $line =~ s/%end%/$end/g;
344 $prev = $all_nodes{$name};
346 foreach my $name (sort keys %pending_nodes)
351 my $line = $node_order;
352 $line =~ s/%begin%/$begin/g;
353 $line =~ s/%end%/$name/g;
358 print($node_order_footer);
363 print($graph_header);
366 print_pending_nodes
();
369 print($graph_footer);
372 #-------------------------------------------------------------------------------
374 parse_debug_output
();