Changeset 94

Show
Ignore:
Timestamp:
03/31/10 21:01:53 (4 years ago)
Author:
jesus
Message:

cleaned up histogram output

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Sniffer-Postgres/bin/pgsniff

    r93 r94  
    170170  ++$hist->{$q->{query}}->{results}->{$log2}; 
    171171  $hist->{$q->{query}}->{total_tuples} += $q->{tuples}; 
     172 
     173  $hist->{$q->{query}}->{cnt}++; 
    172174  finish() if (--$limit == 0); 
    173175} 
     
    177179  my $invocations = 0; 
    178180  my ($bar, $cnt); 
    179   printf "== %d ==\n$q->{query}\n--- total run time: %2.f ms ---\n", $n, $q->{total_time} * 1000; 
     181  printf "== (rank: %d) run: %d, cumm. runtime %.3f ms, avg. tuples: %.2f ==\n", 
     182         $n, $q->{cnt}, $q->{total_time} * 1000, $q->{total_tuples} / $q->{cnt}; 
     183  print "\nQUERY: $q->{query}\n\n"; 
     184  printf "-- Runtime --\n"; 
    180185  my ($top) = sort { $b <=> $a } keys %{$q->{runtime}}; 
    181186  my ($max) = sort { $b <=> $a } values %{$q->{runtime}}; 
    182   while($top >= 0) { 
     187  my $nentries = keys %{$q->{runtime}}; 
     188  while($top >= 0 && $nentries > 0) { 
     189    $nentries-- if exists $q->{runtime}->{$top}; 
    183190    $cnt = exists $q->{runtime}->{$top} ? $q->{runtime}->{$top} : 0; 
    184191    $invocations += $cnt; 
    185192    $bar = "#" x int(40 * $cnt / $max); 
    186193    $bar .= " " x (40 - length($bar)); 
    187     printf " %10d ms | $bar     ($cnt)\n", (2 ** $top); 
     194    my $range = sprintf "[%d - %d) ms", int(2 ** ($top-1) ), (2 ** $top); 
     195    printf " %13s | $bar     ($cnt)\n", $range; 
    188196    $top--; 
    189197  } 
    190198 
    191   printf "--- average tuples returned: %.3f ---\n", $q->{total_tuples} / $invocations
     199  printf "\n-- Tuples Returned --\n"
    192200  ($top) = sort { $b <=> $a } keys %{$q->{results}}; 
    193201  ($max) = sort { $b <=> $a } values %{$q->{results}}; 
     202  $nentries = keys %{$q->{results}}; 
    194203  if($max > 0) { 
    195     while($top >= -1) { 
     204    while($top >= -1 && $nentries > 0) { 
     205      $nentries-- if exists $q->{results}->{$top}; 
    196206      $cnt = exists $q->{results}->{$top} ? $q->{results}->{$top} : 0; 
    197207      $bar = "#" x int(40 * $cnt / $max); 
    198208      $bar .= " " x (40 - length($bar)); 
    199       printf "    %10d | $bar     ($cnt)\n", ($top >= 0) ? (2 ** $top) : 0; 
     209      my ($start, $end) = (($top >= 0) ? (2 ** $top) : 0, (2 ** ($top+1)) - 1); 
     210      my $range = ($start < $end) ? sprintf "%d - %d", $start, $end : 
     211                                    sprintf "%d", $start; 
     212      printf " %13s | $bar     ($cnt)\n", $range; 
    200213      $top--; 
    201214    } 
    202215  } 
    203   print "\n"; 
     216  print "\n\n"; 
    204217} 
    205218sub finish {