Commit fbcf2b5c authored by Chris McDonough's avatar Chris McDonough

Windows compatibility and --today flag.

parent 0f055c5c
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
""" Request log profiler script """ """ Request log profiler script """
__version__='$Revision: 1.1 $'[11:-2] __version__='$Revision: 1.2 $'[11:-2]
import string, sys, time, getopt import string, sys, time, getopt
...@@ -190,7 +190,7 @@ class Cumulative: ...@@ -190,7 +190,7 @@ class Cumulative:
t = t + elapsed t = t + elapsed
return t return t
def analyze(f, top, sortf): def analyze(f, top, sortf, start=None, end=None):
requests={} requests={}
while 1: while 1:
line = f.readline() line = f.readline()
...@@ -205,8 +205,21 @@ def analyze(f, top, sortf): ...@@ -205,8 +205,21 @@ def analyze(f, top, sortf):
code, id, timestr, desc = tup code, id, timestr, desc = tup
else: else:
continue continue
gmtimetup = time.strptime(timestr, '%Y-%m-%dT%H:%M:%S') #gmtimetup = time.strptime(timestr, '%Y-%m-%dT%H:%M:%S')
fromepoch = time.mktime(gmtimetup) # this doesn't work on windows
timestr = string.strip(timestr)
year = int(timestr[:4])
month = int(timestr[5:7])
day = int(timestr[8:10])
hour = int(timestr[11:13])
minute = int(timestr[14:16])
second = int(timestr[17:19])
gmttup = (year, month, day, hour, minute, second, 0, 0, -1)
fromepoch = time.mktime(gmttup)
if start is not None:
if fromepoch < start: continue
if end is not None:
if fromepoch > end: continue
request = requests.get(id) request = requests.get(id)
if request is None: if request is None:
request = Request() request = Request()
...@@ -278,13 +291,15 @@ The default is 'total'. The sort order is decending unless indicated. ...@@ -278,13 +291,15 @@ The default is 'total'. The sort order is decending unless indicated.
If the 'top' argument is specified, only report on the top 'n' requests in If the 'top' argument is specified, only report on the top 'n' requests in
the log (as per the sort). The default is 10. the log (as per the sort). The default is 10.
If the 'verbose' argument is specified, do not trim url to fit into 80 cols.""" If the 'verbose' argument is specified, do not trim url to fit into 80 cols.
If the 'today' argument is specified, limit results to hits received today."""
return details return details
def usage(basic=1): def usage(basic=1):
usage = ( usage = (
""" """
Usage: %s filename [--sort=spec] [--top=n] [--verbose] [--help] Usage: %s filename [--sort=spec] [--top=n] [--verbose] [--today] [--help]
Provides a profile of the detailed (-M) Zope request log. Provides a profile of the detailed (-M) Zope request log.
""" % sys.argv[0] """ % sys.argv[0]
...@@ -303,9 +318,11 @@ if __name__ == '__main__': ...@@ -303,9 +318,11 @@ if __name__ == '__main__':
top = 10 top = 10
verbose = 0 verbose = 0
sortby = 'total' sortby = 'total'
start = None
end = None
try: try:
opts, extra = getopt.getopt( opts, extra = getopt.getopt(
sys.argv[2:], '', ['sort=', 'top=', 'help', 'verbose'] sys.argv[2:], '', ['sort=', 'top=', 'help', 'verbose', 'today']
) )
except: except:
print usage() print usage()
...@@ -317,7 +334,16 @@ if __name__ == '__main__': ...@@ -317,7 +334,16 @@ if __name__ == '__main__':
if opt=='--verbose': if opt=='--verbose':
global verbose global verbose
verbose = 1 verbose = 1
if opt=='--today':
now = time.gmtime(time.time())
# for testing - now = (2001, 04, 19, 0, 0, 0, 0, 0, -1)
start = list(now)
start[3] = start[4] = start[5] = 0
start = time.mktime(start)
end = list(now)
end[3] = 23; end[4] = 59; end[5] = 59
end = time.mktime(end)
if sortby in ['url', 'hits', 'hangs', 'max', 'min', 'median', 'mean', if sortby in ['url', 'hits', 'hangs', 'max', 'min', 'median', 'mean',
'total']: 'total']:
if sortby == 'url': if sortby == 'url':
...@@ -326,7 +352,7 @@ if __name__ == '__main__': ...@@ -326,7 +352,7 @@ if __name__ == '__main__':
else: else:
sortf = Sort(sortby) sortf = Sort(sortby)
try: try:
analyze(open(sys.argv[1]), top, sortf) analyze(open(sys.argv[1]), top, sortf, start, end)
except: except:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment