Changeset 366


Ignore:
Timestamp:
Mar 18, 2010, 1:49:44 PM (11 years ago)
Author:
zerodeux
Message:

Cosmetics: code organisation and sub role in comments, output wrapped to 80 cols

Location:
phptop
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • phptop/NEWS

    r365 r366  
    11phptop 0.5 - Unreleased
    22
    3     * Gave up 'inc' measure and display; it could be seen as a code complexity
    4       measure but has been merely useless in production use for the last months
    53    * New -o|--output-mode option, refactored reporting internally
    6     * Showing sorting column with '>' on text output
     4    * Text output: showing sorting column with '>' on text output
     5    * Text output: multiple reports are globally column aligned
    76    * Now checking that -t <value> is numeric
    87    * Now checking that -s <key> uses a known key
     
    1211    * Using exactly one print per line (better buffering for large outputs
    1312      or slow links)
     13    * Gave up 'inc' measure and display; it could be seen as a code complexity
     14      measure but has been merely useless in production use for the last months
    1415
    1516phptop 0.4.1 - 2009-11-21
  • phptop/TODO

    r276 r366  
    11- HTML output mode
     2- CSV output mode ? (for spreadsheats)
    23- Man page, less verbose --help
     4- Term color mode
  • phptop/phptop

    r365 r366  
    22
    33# phptop - Analyse quickly system ressource usage across many PHP queries
    4 # Copyright (C) 2009 Bearstech - http://bearstech.com/
     4# Copyright (C) 2009,2010 Bearstech - http://bearstech.com/
    55#
    66# This program is free software: you can redistribute it and/or modify
     
    1616# You should have received a copy of the GNU General Public License
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18 
    19 # Depends on LWP aka libwww-perl (what else ?)
    2018
    2119use strict;
     
    2927my $package_name    = 'phptop';
    3028my $package_version = '0.5-dev';
    31 my $package_owner   = 'Copyright (C) 2009 Bearstech - http://bearstech.com/';
     29my $package_owner   = 'Copyright (C) 2009,2010 Bearstech - http://bearstech.com/';
    3230my $package_url     = 'http://forge.bearstech.com/trac/wiki/PhpTop';
    3331
     
    3735my @log;
    3836my $full_query;
    39 my $count = 10;
     37my $path_only;
    4038my @sortkeys;
    41 my $span = 10;
    42 my $path_only;
     39my $count = 10;
     40my $span   = 10;
    4341my $output = 'text';
    4442
     
    4947my $hits  = 0;
    5048my $bogus = 0;
     49
    5150
    5251sub print_short_help {
     
    7170  -p, --path-only      Only print path, skip http://host
    7271  -s, --sort key       Sort key: hit, time, user, sys or mem (default is @sortkeys)
    73   -t, --time N         Consider log events from now back to N minutes (default is $span)
     72  -t, --time N         Parse data from now back to N minutes (default is $span)
    7473  -v, --version        Display version number and copyright info
    7574
     
    9291}
    9392
     93# parse_log() is called for every log files and fills up the global %stat hash
     94#
    9495sub parse_log {
    9596    my $logfile = shift;
     
    101102    # Try to open logfile in 'reverse' mode first, using 'tac'
    102103    # (trying to parse less lines and hence being much faster)
    103 {
    104 # It's okay for open(tac|) to fail, and we handle the other open errors explicitly
    105 no warnings;
    106 
    107     if (open($lh, "tac $logfile |")) {
    108         $reverse = 1;
    109     }
    110     elsif (!open($lh, "<$logfile")) {
    111         warn "$logfile: $!";
    112         return 0;
    113     }
    114 }
     104    {
     105        # It's okay for open(tac|) to fail, and we handle the other open errors explicitly
     106        no warnings;
     107   
     108        if (open($lh, "tac $logfile |")) {
     109            $reverse = 1;
     110        }
     111        elsif (!open($lh, "<$logfile")) {
     112            warn "$logfile: $!";
     113            return 0;
     114        }
     115    }
     116
     117    POSIX::setlocale(POSIX::LC_NUMERIC, 'C'); # Use . as decimal separator
    115118
    116119  LINE:
     
    174177}
    175178
     179# fix_stat() is called once all log files have been parsed and only once,
     180# and modifies a few values in %stat for a useful display.
    176181sub fix_stat {
    177182    while (my ($url, $i) = each %stat) {
     
    183188}
    184189
     190# raw_report() compute the tabular report which is then rendered via another routine.
     191#
    185192sub raw_report {
    186193    my $sortkey = shift;
     
    215222}
    216223
     224# text_report() pretty prints in a terminal raw_report() result
     225#
    217226sub text_report {
    218227    # Compute all reports at first, we'll align all report columns
     
    241250
    242251        # Table separator (starting from 2nd report)
    243         print "--\n" if $report_nb++;
     252        print "\n" if $report_nb++;
    244253   
    245254        # Table header
     
    259268}
    260269
     270# html_report() renders a report from the inlined template in DATA section
     271#
    261272sub hmtl_report {
    262273}
    263274
     275
     276# Main
    264277
    265278GetOptions(
     
    291304print_version() if $version;
    292305
    293 POSIX::setlocale(POSIX::LC_NUMERIC, 'C'); # Use . as decimal separator
    294 
    295306my @logfiles;
    296307push(@log, '/var/log/apache2/error*log', '/var/log/apache2/*/error*log') if !@log;
     
    313324
    314325fix_stat();
    315 
    316326text_report() if $output eq 'text';
    317327html_report() if $output eq 'html';
Note: See TracChangeset for help on using the changeset viewer.