Commit 80ca4194 authored by Chris McDonough's avatar Chris McDonough

Fixed bugs that could give nonsensical results when analyzing in timed mode.

parent 49b25cc9
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
""" Request log profiler script """ """ Request log profiler script """
__version__='$Revision: 1.12 $'[11:-2] __version__='$Revision: 1.13 $'[11:-2]
import string, sys, time, getopt, tempfile import string, sys, time, getopt, tempfile, math
class ProfileException(Exception): pass class ProfileException(Exception): pass
...@@ -322,17 +322,14 @@ def analyze(files, top, sortf, start=None, end=None, mode='cumulative', ...@@ -322,17 +322,14 @@ def analyze(files, top, sortf, start=None, end=None, mode='cumulative',
raise "Invalid mode." raise "Invalid mode."
if mode=='timed': if mode=='timed':
timeDict = {}
timesort(timeDict,requests)
if start and end: if start and end:
timewrite(timeDict,start,end,resolution) timewrite(requests,start,end,resolution)
if start and not end: if start and not end:
timewrite(timeDict,start,computed_end,resolution) timewrite(requests,start,computed_end,resolution)
if end and not start: if end and not start:
timewrite(timeDict,computed_start,end,resolution) timewrite(requests,computed_start,end,resolution)
if not end and not start: if not end and not start:
timewrite(timeDict,computed_start,computed_end,resolution) timewrite(requests,computed_start,computed_end,resolution)
else: else:
dict.sort(sortf) dict.sort(sortf)
write(dict, top) write(dict, top)
...@@ -363,54 +360,59 @@ def getdate(val): ...@@ -363,54 +360,59 @@ def getdate(val):
except: except:
raise ProfileException, "bad date %s" % val raise ProfileException, "bad date %s" % val
def getTimeslice(period, utime):
low = int(math.floor(utime)) - period + 1
high = int(math.ceil(utime)) + 1
for x in range(low, high):
if x % period == 0:
return x
def timesort(dict,requests): def timewrite(requests, start, end, resolution):
for r in requests:
if not r.t_end: r.t_end=r.start
for t in range(r.start,r.t_end+1):
if not dict.has_key(t):
dict[t] = 0
dict[t]=dict[t]+1
def timewrite(dict,start,end,resolution):
max_requests = 0 max_requests = 0
print "Start: %s End: %s Resolution: %d secs" % \ print "Start: %s End: %s Resolution: %d secs" % \
(tick2str(start),tick2str(end),resolution) (tick2str(start), tick2str(end), resolution)
print "-" * 78 print "-" * 78
print print
print "Date/Time #requests requests/second" print "Date/Time #requests requests/second"
for t in range(start,end,resolution): d = {}
s = tick2str(t) for r in requests:
t = r.start
num = 0 slice = getTimeslice(resolution,t)
for tick in range(t,t+resolution): if d.has_key(slice):
if dict.has_key(tick): d[slice] = d[slice] + 1
num = num + dict[tick] else:
d[slice] = 1
if num>max_requests: max_requests = num
num = 0
hits = 0
avg_requests = None
slices = d.keys()
slices.sort()
for slice in slices:
num = d[slice]
if num>max_requests: max_requests = num
hits = hits + num
if avg_requests is None:
avg_requests = num
else:
avg_requests = (avg_requests + num) / 2
s = tick2str(slice)
s = s + " %6d %4.2lf" % (num,num*1.0/resolution) s = s + " %6d %4.2lf" % (num,num*1.0/resolution)
print s print s
print '='*78 print '='*78
print "Peak: %6d %4.2lf" % \ print " Peak: %6d %4.2lf" % \
(max_requests,max_requests*1.0/resolution) (max_requests,max_requests*1.0/resolution)
print " Avg: %6d %4.2lf" % \
(avg_requests,avg_requests*1.0/resolution)
print "Total: %6d n/a " % (hits)
def tick2str(t): def tick2str(t):
return time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(t)) return time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(t))
def codesort(v1, v2): def codesort(v1, v2):
v1 = v1.endstage() v1 = v1.endstage()
...@@ -658,9 +660,8 @@ if __name__ == '__main__': ...@@ -658,9 +660,8 @@ if __name__ == '__main__':
sortf = codesort sortf = codesort
else: else:
sortf = Sort(sortby) sortf = Sort(sortby)
elif mode=='timed': elif mode=='timed':
sortf = timesort sortf = None
else: else:
raise 'Invalid mode' raise 'Invalid mode'
......
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