]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/asio/tools/handlerviz.pl
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / asio / tools / handlerviz.pl
index 7e8de3df24632828993c73e31a4940e9e4f71223..7c1ff13c5066365109110c59a77e290e610e4428 100755 (executable)
@@ -16,7 +16,7 @@
 #
 #   perl handlerviz.pl < output.txt | dot -Tpdf > output.pdf
 #
-# Copyright (c) 2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+# Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 #
 # Distributed under the Boost Software License, Version 1.0. (See accompanying
 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -26,9 +26,11 @@ use strict;
 
 my %nodes = ();
 my @edges = ();
+my %locations = ();
 my %anon_nodes = ();
 my $anon_id = 0;
 my %all_nodes = ();
+my %pending_nodes = ();
 
 #-------------------------------------------------------------------------------
 # Parse the debugging output and populate the nodes and edges.
@@ -62,6 +64,21 @@ sub parse_debug_output()
 
         my %edge = ( begin=>$begin, end=>$end, label=>$label );
         push(@edges, \%edge);
+
+        $pending_nodes{$end} = 1;
+      }
+
+      # Handler location.
+      elsif ($action =~ /^([0-9]+)\^([0-9]+)$/)
+      {
+        if ($1 ne "0")
+        {
+          if (not exists($locations{($1,$2)}))
+          {
+            $locations{($1,$2)} = ();
+          }
+          push(@{$locations{($1,$2)}}, $description);
+        }
       }
 
       # Begin handler invocation. 
@@ -71,6 +88,7 @@ sub parse_debug_output()
         $new_node{content} = ();
         $nodes{$1} = \%new_node;
         $all_nodes{"$timestamp-$1"} = $1;
+        delete($pending_nodes{$1});
       }
 
       # End handler invocation.
@@ -92,6 +110,7 @@ sub parse_debug_output()
         $new_node{content} = ();
         $nodes{$1} = \%new_node;
         $all_nodes{"$timestamp-$1"} = $1;
+        delete($pending_nodes{$1});
       }
 
       # Handler performed some operation.
@@ -129,8 +148,8 @@ sub escape($)
 # Templates for dot output.
 
 my $graph_header = <<"EOF";
-/* Generated by asioviz.pl */
-digraph G
+/* Generated by handlerviz.pl */
+digraph "handlerviz output"
 {
 graph [ nodesep="1" ];
 node [ shape="box", fontsize="9" ];
@@ -172,9 +191,23 @@ my $anon_node = <<"EOF";
 "%name%" [ label="%label%", color="gray" ];
 EOF
 
+my $pending_nodes_header = <<"EOF";
+{
+node [ shape="record", color="red" ];
+rank = "max";
+EOF
+
+my $pending_nodes_footer = <<"EOF";
+}
+EOF
+
+my $pending_node = <<"EOF";
+"%name%";
+EOF
+
 my $edges_header = <<"EOF";
 {
-edge [ style="dashed", arrowhead="open", weight="100" ];
+edge [ style="dashed", arrowhead="open" ];
 EOF
 
 my $edges_footer = <<"EOF";
@@ -182,12 +215,13 @@ my $edges_footer = <<"EOF";
 EOF
 
 my $edge = <<"EOF";
-"%begin%" -> "%end%" [ label="%label%" ]
+"%begin%" -> "%end%" [ label="%label%", labeltooltip="%tooltip%" ]
 EOF
 
 my $node_order_header = <<"EOF";
 {
-edge [ style="invis", weight="1" ];
+node [ style="invisible" ];
+edge [ style="invis", weight="100" ];
 EOF
 
 my $node_order_footer = <<"EOF";
@@ -195,7 +229,12 @@ my $node_order_footer = <<"EOF";
 EOF
 
 my $node_order = <<"EOF";
-"%begin%" -> "%end%"
+{
+rank="same"
+"%begin%";
+"o%begin%";
+}
+"o%begin%" -> "o%end%";
 EOF
 
 #-------------------------------------------------------------------------------
@@ -214,10 +253,13 @@ sub print_nodes()
     $header =~ s/%label%/$label/g;
     print($header);
 
-    my $line = $node_content;
-    my $content = $entry . " + " . sprintf("%.6f", $exit - $entry) . "s";
-    $line =~ s/%content%/$content/g;
-    print($line);
+    if (defined($exit) and defined($entry))
+    {
+      my $line = $node_content;
+      my $content = $entry . " + " . sprintf("%.6f", $exit - $entry) . "s";
+      $line =~ s/%content%/$content/g;
+      print($line);
+    }
 
     foreach my $content (@{$node->{content}})
     {
@@ -243,7 +285,19 @@ sub print_anon_nodes()
     $line =~ s/%label%/$label/g;
     print($line);
   }
-  print($edges_footer);
+  print($anon_nodes_footer);
+}
+
+sub print_pending_nodes()
+{
+  print($pending_nodes_header);
+  foreach my $name (sort keys %pending_nodes)
+  {
+    my $line = $pending_node;
+    $line =~ s/%name%/$name/g;
+    print($line);
+  }
+  print($pending_nodes_footer);
 }
 
 sub print_edges()
@@ -254,10 +308,19 @@ sub print_edges()
     my $begin = $e->{begin};
     my $end = $e->{end};
     my $label = $e->{label};
+    my $tooltip = "";
+    if (exists($locations{($begin,$end)}))
+    {
+      for my $line (@{$locations{($begin,$end)}})
+      {
+        $tooltip = $tooltip . escape($line) . "\n";
+      }
+    }
     my $line = $edge;
     $line =~ s/%begin%/$begin/g;
     $line =~ s/%end%/$end/g;
     $line =~ s/%label%/$label/g;
+    $line =~ s/%tooltip%/$tooltip/g;
     print($line);
   }
   print($edges_footer);
@@ -280,6 +343,18 @@ sub print_node_order()
     }
     $prev = $all_nodes{$name};
   }
+  foreach my $name (sort keys %pending_nodes)
+  {
+    if ($prev ne "")
+    {
+      my $begin = $prev;
+      my $line = $node_order;
+      $line =~ s/%begin%/$begin/g;
+      $line =~ s/%end%/$name/g;
+      print($line);
+    }
+    last;
+  }
   print($node_order_footer);
 }
 
@@ -288,6 +363,7 @@ sub generate_dot()
   print($graph_header);
   print_nodes();
   print_anon_nodes();
+  print_pending_nodes();
   print_edges();
   print_node_order();
   print($graph_footer);