[padb-devel] [padb] r290 committed - When displaying a list of variables with type names ensure that the va...

codesite-noreply at google.com codesite-noreply at google.com
Thu Oct 15 17:39:15 BST 2009


Revision: 290
Author: apittman
Date: Thu Oct 15 09:38:57 2009
Log: When displaying a list of variables with type names ensure that the  
variable
names are right justified and that they are no further to the right than  
they
need to be.  Apply this logic to both tree and normal stack traces, tree
stacks were all over the place, normal ones were justified but always left
a space between the longest type and the longest var, now we just ensure  
that
there is at least one space between each type and it's matching var.

http://code.google.com/p/padb/source/detail?r=290

Modified:
  /trunk/src/padb

=======================================
--- /trunk/src/padb	Thu Oct 15 06:30:47 2009
+++ /trunk/src/padb	Thu Oct 15 09:38:57 2009
@@ -3235,6 +3235,35 @@
      }
      return;
  }
+
+# Calculate the formatting needed for displaying a list of variables and
+# their types allowing them to be neatly formatted on the screen.  Take an
+# array of hashes and combine {name} and {type} into a new value
+# {type_name} which is the same length as {type_name} for all other entries
+# in the array.
+sub format_local_vars {
+    my ($list) = @_;
+
+    my $max = 0;
+    foreach my $var ( @{$list} ) {
+        my $name_len = length $var->{name};
+        my $type_len = length $var->{type};
+        if ( $name_len + $type_len > $max ) {
+            $max = $name_len + $type_len;
+        }
+    }
+
+    $max++;
+
+    foreach my $var ( @{$list} ) {
+        my $name_len = length $var->{name};
+        my $type_len = length $var->{type};
+        my $pad      = $max - ( $name_len + $type_len );
+        $var->{type_name} = $var->{type} . " " x $pad . $var->{name};
+    }
+
+    return;
+}

  sub _display_tree {
      my ( $tree, $d, $parent, $indent, $path, $enforce_spec ) = @_;
@@ -3274,34 +3303,44 @@
                  my @params = split $COMMA, $params_lists[0];

                  $ret .= "$indent      params\n" if ( @params > 0 );
+
+                my @all_vars;
                  foreach my $var (@params) {
-
+                    my @type_list =
+                      sort keys %{ $d->{target_data}{"$peer|param_type| 
$var"} };
+                    my $type = $type_list[0];
+                    push @all_vars,
+                      {
+                        name => $var,
+                        type => $type,
+                      };
+                }
+
+                format_local_vars( \@all_vars );
+
+                foreach my $vref (@all_vars) {
+                    my $var    = $vref->{name};
                      my $key    = "$l|var|$var";
                      my @values = keys %{ $d->{target_data}{$key} };
-
-                    my $type = '<unknown>';
-
-                    my @type_list =
-                      sort keys %{ $d->{target_data}{"$peer|param_type| 
$var"} };
-                    $type = $type_list[0];
+                    my $type   = $vref->{type};

                      $child_enforce_spec = 1;
                      if ( @values == 1 ) {
                          foreach my $value ( sort @values ) {
                              $ret .=
-                              "$indent        $type    $var = '$value' "
+                              "$indent        $vref->{type_name}  
= '$value' "
                                . rng_convert_to_user(
                                  $d->{target_data}{$key}{$value} )
                                . "\n";
                          }
                      } elsif ( @values > $max_show ) {
                          $ret .=
-"$indent        $type    $var: <more than $max_show distinct values>\n";
+"$indent        $vref->{type_name}: <more than $max_show distinct  
values>\n";
                      } else {
-                        $ret .= "$indent        $type    $var:\n";
+                        $ret .= "$indent        $vref->{type_name}:\n";
                          foreach my $value ( sort @values ) {
                              $ret .=
-                              "$indent          '$value' "
+                              "$indent            '$value' "
                                . rng_convert_to_user(
                                  $d->{target_data}{$key}{$value} )
                                . "\n";
@@ -3320,34 +3359,44 @@
                  my @locals = split $COMMA, join( q{,}, @locals_lists );

                  $ret .= "$indent      locals\n" if ( @locals > 0 );
+
+                my @all_vars;
                  foreach my $var (@locals) {
-
+                    my @type_list =
+                      sort keys %{ $d->{target_data}{"$peer|var_type| 
$var"} };
+                    my $type = $type_list[0];
+                    push @all_vars,
+                      {
+                        name => $var,
+                        type => $type,
+                      };
+                }
+
+                format_local_vars( \@all_vars );
+
+                foreach my $vref (@all_vars) {
+                    my $var    = $vref->{name};
                      my $key    = "$l|var|$var";
                      my @values = keys %{ $d->{target_data}{$key} };
-
-                    my $type = '<unknown>';
-
-                    my @type_list =
-                      sort keys %{ $d->{target_data}{"$peer|var_type| 
$var"} };
-                    $type = $type_list[0];
+                    my $type   = $vref->{type};

                      $child_enforce_spec = 1;
                      if ( @values == 1 ) {
                          foreach my $value ( sort @values ) {
                              $ret .=
-                              "$indent        $type    $var = '$value' "
+                              "$indent        $vref->{type_name}  
= '$value' "
                                . rng_convert_to_user(
                                  $d->{target_data}{$key}{$value} )
                                . "\n";
                          }
                      } elsif ( @values > $max_show ) {
                          $ret .=
-"$indent        $type    $var: <more than $max_show distinct values>\n";
+"$indent        $vref->{type_name}: <more than $max_show distinct  
values>\n";
                      } else {
-                        $ret .= "$indent        $type    $var:\n";
+                        $ret .= "$indent        $vref->{type_name}:\n";
                          foreach my $value ( sort @values ) {
                              $ret .=
-                              "$indent          '$value' "
+                              "$indent            '$value' "
                                . rng_convert_to_user(
                                  $d->{target_data}{$key}{$value} )
                                . "\n";
@@ -5509,9 +5558,9 @@

                      if ( $str_name ne 'exit' and $str_name ne 'dmsg' ) {

-			# Report the string back to the outer process,
-			# don't bother forwarding exit status as that's
-			# done below.
+                        # Report the string back to the outer process,
+                        # don't bother forwarding exit status as that's
+                        # done below.
                          target_key_pair( $vp, "minfo_msg_$str_name",
                              $str_value );
                          target_key_pair( $vp, "minfo_msg", $str_name );
@@ -5848,11 +5897,12 @@
              foreach my $value ( sort @values ) {
                  printf("----------------\n");
                  printf(
-
-		     rng_convert_to_user(
+
+                    rng_convert_to_user(
                          $lines->{target_data}{"minfo_msg_$key"}{$value}
-                      ) .
-		    ": $head\n");
+                      )
+                      . ": $head\n"
+                );
                  printf("----------------\n");
                  printf( "%s\n", $value );
              }
@@ -6075,7 +6125,8 @@
              } elsif ( $line =~ /^msg\d+/ ) {
                  ;    # nop
              } else {
-		#print "Failed to match minfo output: $line\n";
+
+                #print "Failed to match minfo output: $line\n";
              }
          }
          $coll_data{$rank} = \%lid;
@@ -6700,18 +6751,12 @@
      my ( $vp, $frame, $type ) = @_;
      return unless defined $frame->{$type};
      return if ( @{ $frame->{$type} } == 0 );
-    my %l = ( t => 0, n => 0 );
-    foreach my $arg ( @{ $frame->{$type} } ) {
-        $l{t} = length $arg->{type} if ( length $arg->{type} > $l{t} );
-        $l{n} = length $arg->{name} if ( length $arg->{name} > $l{n} );
-    }
-    my $header = "  $type:";
-    output( $vp, $header );
+
+    format_local_vars( $frame->{$type} );
+    output( $vp, "  $type:" );
      foreach my $arg ( @{ $frame->{$type} } ) {
          my $value = ( defined $arg->{value} ? $arg->{value} : '??' );
-        my $output = sprintf "    %-$l{t}s %$l{n}s = %s", $arg->{type},
-          $arg->{name}, $value;
-        output( $vp, $output );
+        output( $vp, "    $arg->{type_name} = $value" );
      }
      return;
  }




More information about the padb-devel mailing list