Changeset 363


Ignore:
Timestamp:
Mar 17, 2010, 1:06:42 PM (11 years ago)
Author:
zerodeux
Message:

Mainly fixes: buggy non-numeric sorting, -t <integer> check + goodies: showing sort column, optimal output buffering

Location:
phptop
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • phptop/NEWS

    r277 r363  
     1phptop 0.5 - Unreleased
     2
     3    * Showing sorting column with '>' on text output
     4    * Now checking that -t <value> is numeric
     5    * Fixed sorting which was not reliable (use proper <=> numeric comparison
     6      operator)
     7    * Using exactly one print per line (better buffering for large outputs
     8      or slow links)
     9
    110phptop 0.4.1 - 2009-11-21
    211
  • phptop/debian/control

    r276 r363  
    88Package: phptop
    99Architecture: all
    10 Depends: perl (>= 5.8), libwww-perl, libterm-size-perl, ${shlibs:Depends}, ${misc:Depends}
     10Depends: perl (>= 5.8), libwww-perl, libterm-size-perl, libhtml-template-perl, ${shlibs:Depends}, ${misc:Depends}
    1111Recommends: php5-cgi|libapache2-mod-php5|libapache2-mod-php5filter
    1212Description: php5 resource statistics tool
  • phptop/phptop

    r277 r363  
    2525use POSIX;
    2626use Term::Size;
     27use HTML::Template;
    2728
    2829my $package_name    = 'phptop';
    29 my $package_version = '0.4.1';
     30my $package_version = '0.5-dev';
    3031my $package_owner   = 'Copyright (C) 2009 Bearstech - http://bearstech.com/';
    3132my $package_url     = 'http://forge.bearstech.com/trac/wiki/PhpTop';
     
    197198
    198199    # Sort queries according to $sortkey (they are all numeric)
    199     my @sorted = sort { $stat{$b}{$sortkey} - $stat{$a}{$sortkey} } keys %stat;
     200    my @sorted = sort { $stat{$b}{$sortkey} <=> $stat{$a}{$sortkey} } keys %stat;
    200201 
    201202    # Compute URL column width
     
    209210    $width = $colmax if $width > $colmax;
    210211
     212    # Header
     213    my @headers = map {
     214        my $h = $_;
     215        $h = "$h/hit" if /^(mem|inc)$/;  # Mem and Inc are per-hit values
     216        $h = ucfirst $h;
     217        $h = ">$h" if $_ eq $sortkey;    # Use '>' to show sorting column
     218        sprintf('%8s', $h);
     219    } @keys;
     220    printf("%-${width}s %s\n", "", join(' ', @headers));
     221
     222    # Rows
    211223    $n = 0;
    212     printf("%-${width}s %s\n", "", join(' ', map { sprintf('%8s', ucfirst($_ =~ /^(mem|inc)$/ ? "$_/hit" : $_)) } @keys));
    213224    foreach my $url (@sorted) {
    214225        my $s = $stat{$url};
     
    220231            $url = substr($url, 0, $width - 3).'...';
    221232        }
    222         printf("%-${width}s", $url);
    223         printf($_ =~ m/hit|inc/ ? ' %8d' : ' %8.1f', $s->{$_}) foreach @keys;
    224         print "\n";
    225     }
    226     printf("\n%-${width}s", "Total (from last $span min)");
    227     printf($_ =~ m/hit/ ? ' %8d' : ' %8.1f', $total{$_}) foreach @tkeys;
    228     print "\n";
     233        my $row = sprintf("%-${width}s", $url);
     234        $row   .= sprintf($_ =~ m/hit|inc/ ? ' %8d' : ' %8.1f', $s->{$_}) foreach @keys;
     235        print "$row\n";
     236    }
     237
     238    my $footer = sprintf("\n%-${width}s", "Total (from last $span min)");
     239    $footer   .= sprintf($_ =~ m/hit/ ? ' %8d' : ' %8.1f', $total{$_}) foreach @tkeys;
     240    print "$footer\n";
    229241}
    230242
     
    237249    'p|path'         => \$path_only,
    238250    's|sort=s'       => \$sortkeys,
    239     't|time=s'       => \$span,
     251    't|time=i'       => \$span,
    240252    'v|version'      => \$version,
    241253)
     
    245257print_version() if $version;
    246258
    247 POSIX::setlocale(POSIX::LC_ALL, 'C'); # Use . as decimal separator
     259POSIX::setlocale(POSIX::LC_NUMERIC, 'C'); # Use . as decimal separator
    248260
    249261my @logfiles;
Note: See TracChangeset for help on using the changeset viewer.