Changeset 262


Ignore:
Timestamp:
Nov 13, 2009, 12:59:02 PM (11 years ago)
Author:
zerodeux
Message:

Really fixed time/span computing, re-ordered regexes for faster parsing

Location:
phptop
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • phptop/NEWS

    r261 r262  
    11phptop 0.3 - unreleased
    22
    3     * Fixed an awful bug about timespan being 5x than necessary (forgot debug code)
     3    * Fixed an awful bug about timespan being 12x less than necessary
    44    * Refactored code with functions and less globals
     5    * Changed default time span from 1h to 10min
     6    * Reordered parsing regexes for more logical and faster result
    57
    68phptop 0.2.2 - 2009-11-06
  • phptop/phptop

    r261 r262  
    3737my $count = 10;
    3838my $sortkeys = 'hit';
    39 my $span = 60;
     39my $span = 10;
    4040my $path_only;
    4141
     
    101101    while (<$lh>) {
    102102        chomp;
    103         s/(\d),(\d)/$1.$2/g; # Be independent of the PHP locale, normalize on dot decimal separator
    104         s/, referer.*//;     # Apache may append a referer in error.log, ignore
    105103        next if not /\bphptop ([^ ]+) (.*)/;
    106 
    107104        my ($uri, $pairs) = ($1, $2);
    108         $uri =~ s/index\.php\/?//;  # / == /index.php (99.9% of the time)
    109         $uri =~ s/\?.*// if not defined $full_query;
    110         $uri =~ s/^https?:\/\/[^\/]+// if defined $path_only;
    111105
    112106        # Only keep records within expected time span. If a time stamp is not found or
     
    114108        if (/^\[(.*?)\]/) {
    115109            my $stamp = str2time($1);
    116             next if defined $stamp && ($now - $stamp) > $span;
     110            next if defined $stamp && ($now - $stamp) > $span * 60;
    117111        }
    118112
    119         # Protect against bogus/wrapped phptop records, count pairs
     113        $pairs =~ s/, referer.*//;     # Apache may append a referer in error.log, ignore
     114        $pairs =~ s/(\d),(\d)/$1.$2/g; # Be independent of the PHP locale, normalize on dot decimal separator
    120115        my @kv = split(/ /, $pairs);
    121         next if @kv < 5;
     116        next if @kv < 5;               # Protect against bogus/wrapped phptop records, count pairs
     117
     118        # Fix URIs (depending on options)
     119        $uri =~ s/index\.php\/?//;  # / == /index.php (99.9% of the time)
     120        $uri =~ s/\?.*// if not defined $full_query;
     121        $uri =~ s/^https?:\/\/[^\/]+// if defined $path_only;
    122122
    123123        # For each 'key:<numeric val>' sum the numeric value per URI
    124124        foreach (@kv) {
    125125            my ($key, $val) = split(/:/, $_);
     126
    126127            # If we have a bogus key/value pair, zap the whole record
    127128            if ($key eq '' or not defined $val) {
Note: See TracChangeset for help on using the changeset viewer.