Commit 12a6412a authored by Chris McDonough's avatar Chris McDonough

You can now again use requestprofiler with python1.5.

Timed modes no longer require a start and an end.  If a start and an end
is not specified, the start time will be considered the first time
encountered in the set of log files and the end time will be considered
the last time encountered.

The default resolution for timed mode is now 60 seconds.
parent 6b5ab40e
#!/usr/bin/env python2.1 #!/usr/bin/env python
############################################################################## ##############################################################################
# #
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
""" Request log profiler script """ """ Request log profiler script """
__version__='$Revision: 1.10 $'[11:-2] __version__='$Revision: 1.11 $'[11:-2]
import string, sys, time, getopt, tempfile import string, sys, time, getopt, tempfile
...@@ -256,17 +256,22 @@ def get_earliest_file_data(files): ...@@ -256,17 +256,22 @@ def get_earliest_file_data(files):
return retn return retn
def analyze(files, top, sortf, start=None, end=None, mode='cumulative', def analyze(files, top, sortf, start=None, end=None, mode='cumulative',
resolution='10'): resolution=60):
beginrequests = {} beginrequests = {}
cumulative = {} cumulative = {}
finished = [] finished = []
unfinished = {} unfinished = {}
decidelines = {} # filename to filepos decidelines = {} # filename to filepos
computed_start = None
computed_end = None
while 1: while 1:
tup = get_earliest_file_data(files) tup = get_earliest_file_data(files)
if tup is None: if tup is None:
break break
code, id, fromepoch, desc = tup code, id, fromepoch, desc = tup
if computed_start is None:
computed_start = fromepoch
computed_end = fromepoch
if start is not None and fromepoch < start: continue if start is not None and fromepoch < start: continue
if end is not None and fromepoch > end: break if end is not None and fromepoch > end: break
if code == 'U': if code == 'U':
...@@ -284,7 +289,11 @@ def analyze(files, top, sortf, start=None, end=None, mode='cumulative', ...@@ -284,7 +289,11 @@ def analyze(files, top, sortf, start=None, end=None, mode='cumulative',
for pending_req in unfinished.values(): for pending_req in unfinished.values():
pending_req.active = pending_req.active + 1 pending_req.active = pending_req.active + 1
unfinished[id] = request unfinished[id] = request
request.put(code, int(fromepoch), desc) t = int(fromepoch)
try:
request.put(code, t, desc)
except:
print "Unable to handle entry: %s %s %s"%(code, t, desc)
if request.isfinished(): if request.isfinished():
del unfinished[id] del unfinished[id]
finished.append(request) finished.append(request)
...@@ -315,7 +324,14 @@ def analyze(files, top, sortf, start=None, end=None, mode='cumulative', ...@@ -315,7 +324,14 @@ def analyze(files, top, sortf, start=None, end=None, mode='cumulative',
if mode=='timed': if mode=='timed':
timeDict = {} timeDict = {}
timesort(timeDict,requests) timesort(timeDict,requests)
if start and end:
timewrite(timeDict,start,end,resolution) timewrite(timeDict,start,end,resolution)
if start and not end:
timewrite(timeDict,start,computed_end,resolution)
if end and not start:
timewrite(timeDict,computed_start,end,resolution)
if not end and not start:
timewrite(timeDict,computed_start,computed_end,resolution)
else: else:
dict.sort(sortf) dict.sort(sortf)
...@@ -359,7 +375,7 @@ def timesort(dict,requests): ...@@ -359,7 +375,7 @@ def timesort(dict,requests):
if not dict.has_key(t): if not dict.has_key(t):
dict[t] = 0 dict[t] = 0
dict[t]+=1 dict[t]=dict[t]+1
def timewrite(dict,start,end,resolution): def timewrite(dict,start,end,resolution):
......
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