Improvements to my test log parser that were just lying aroudn
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5113 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -69,24 +69,57 @@ if summary:
|
|||||||
createCount, confirm.len(), fail.len(), orphanCount,
|
createCount, confirm.len(), fail.len(), orphanCount,
|
||||||
(float(orphanCount) * 100 / createCount))
|
(float(orphanCount) * 100 / createCount))
|
||||||
|
|
||||||
|
class Path:
|
||||||
|
def __init__(self, name, *transitions):
|
||||||
|
self.transitions = transitions
|
||||||
|
self.name = name
|
||||||
|
self.id = None
|
||||||
|
|
||||||
validPaths = [
|
def describe (self, now):
|
||||||
[pending, destroy],
|
'''Describe a path, including a description of the time since the last change'''
|
||||||
[pending, delayCreate, confirm, destroy, dconfirm],
|
names = ", ".join(map(lambda t: t.name, self.transitions))
|
||||||
[pending, delayCreate, destroy, confirm, dconfirm],
|
if self.id != None and len(self.transitions) > 0:
|
||||||
[create, confirm, destroy, dconfirm],
|
time = self.transitions[-1].ids[self.id][0].group('time')
|
||||||
[create, destroy, confirm, dconfirm],
|
time = parseTime(time)
|
||||||
]
|
names = "%s (%s ago)" % (names, describeTimeDelta(now - time))
|
||||||
|
return "%s: %s" % (self.name, names)
|
||||||
|
|
||||||
def findPath (id):
|
@staticmethod
|
||||||
path = []
|
def calculate (id):
|
||||||
for trans in transitions:
|
'''Determine the sequence of transitions taken by an agent'''
|
||||||
if not trans.ids.has_key(id): continue
|
path = []
|
||||||
path.append(trans)
|
for trans in transitions:
|
||||||
path.sort(lambda a, b: a.ids[id][1] - b.ids[id][1])
|
if not trans.ids.has_key(id): continue
|
||||||
return path
|
path.append(trans)
|
||||||
|
path.sort(lambda a, b: a.ids[id][1] - b.ids[id][1])
|
||||||
|
path = Path("Agent " + id, *path)
|
||||||
|
path.id = id
|
||||||
|
return path
|
||||||
|
|
||||||
|
class PathSequence:
|
||||||
|
def __init__(self, *paths):
|
||||||
|
self.paths = paths
|
||||||
|
|
||||||
|
def match (self, path):
|
||||||
|
path = path.transitions
|
||||||
|
for i in range(0, len(self.paths)):
|
||||||
|
myPath = self.paths[i].transitions
|
||||||
|
if path == myPath:
|
||||||
|
return ("exact", self.paths[i])
|
||||||
|
if path == myPath[0:len(path)]:
|
||||||
|
return ("partial", self.paths[i])
|
||||||
|
return None
|
||||||
|
|
||||||
|
validPaths = PathSequence(
|
||||||
|
Path("Aborted", pending, destroy),
|
||||||
|
Path("Pending-normal", pending, delayCreate, confirm, destroy, dconfirm),
|
||||||
|
Path("Pending-stillborn", pending, delayCreate, destroy, confirm, dconfirm),
|
||||||
|
Path("Normal", create, confirm, destroy, dconfirm),
|
||||||
|
Path("Stillborn", create, destroy, confirm, dconfirm),
|
||||||
|
)
|
||||||
|
|
||||||
def describeTimeDelta (delta):
|
def describeTimeDelta (delta):
|
||||||
|
'''Quick english description of a time interval'''
|
||||||
seconds = delta.seconds
|
seconds = delta.seconds
|
||||||
if delta.days > 0:
|
if delta.days > 0:
|
||||||
desc = "%d days"
|
desc = "%d days"
|
||||||
@@ -98,17 +131,6 @@ def describeTimeDelta (delta):
|
|||||||
desc = "%s seconds" % seconds
|
desc = "%s seconds" % seconds
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
def describePath (id, now, path):
|
|
||||||
names = ", ".join(map(lambda p: p.name, path))
|
|
||||||
if id != None and len(path) > 0:
|
|
||||||
time = path[-1].ids[id][0].group('time')
|
|
||||||
time = parseTime(time)
|
|
||||||
names = "%s (%s ago)" % (names, describeTimeDelta(now - time))
|
|
||||||
return names
|
|
||||||
|
|
||||||
def describeId (id, now):
|
|
||||||
path = findPath(id)
|
|
||||||
print "ID %s: %s" % (id, describePath(id, now, path))
|
|
||||||
|
|
||||||
def getAllIds ():
|
def getAllIds ():
|
||||||
all = {}
|
all = {}
|
||||||
@@ -119,28 +141,32 @@ def getAllIds ():
|
|||||||
all.sort(lambda a, b: int(a) - int(b))
|
all.sort(lambda a, b: int(a) - int(b))
|
||||||
return all
|
return all
|
||||||
|
|
||||||
def matchPath (path, pathSeq):
|
|
||||||
for i in range(0, len(pathSeq)):
|
|
||||||
if path == pathSeq[i]:
|
|
||||||
return "exact"
|
|
||||||
if path == pathSeq[i][0:len(path)]:
|
|
||||||
return "partial"
|
|
||||||
return None
|
|
||||||
|
|
||||||
def getBureau (id, path):
|
def getBureau (id, path):
|
||||||
|
# Can't get this since t is on a different log line and we only match single lines
|
||||||
return "??"
|
return "??"
|
||||||
|
|
||||||
def checkAll (ids, now, verbose=False):
|
def checkAll (ids, now, verbose=False):
|
||||||
|
completedPathCounts = {}
|
||||||
|
|
||||||
for id in ids:
|
for id in ids:
|
||||||
if verbose: print "Checking %s" % id
|
if verbose: print "Checking %s" % id
|
||||||
path = findPath(id)
|
|
||||||
match = matchPath(path, validPaths)
|
path = Path.calculate(id)
|
||||||
|
if verbose: print path.describe(now)
|
||||||
|
|
||||||
|
match = validPaths.match(path)
|
||||||
|
if verbose: print match
|
||||||
|
|
||||||
if match == None:
|
if match == None:
|
||||||
print "Path for id %s (bureau %s) invalid: %s" % (id, getBureau(id, path), describePath(id, now, path))
|
print "Invalid path: %s" % path.describe(now)
|
||||||
elif match == "partial":
|
elif match[0] == "partial":
|
||||||
print "Path for id %s (bureau %s) partially matched: %s" % (id, getBureau(id, path), describePath(id, now, path))
|
print "Incomplete path: %s" % path.describe(now)
|
||||||
elif verbose:
|
elif match[0] == "exact":
|
||||||
print describePath(id, now, path)
|
completedPathCounts[match[1]] = completedPathCounts.get(match[1], 0) + 1
|
||||||
|
|
||||||
|
for path in validPaths.paths:
|
||||||
|
count = completedPathCounts.get(path, 0)
|
||||||
|
print "Path %s completed %d times" % (path.name, count)
|
||||||
|
|
||||||
print "Checking"
|
print "Checking"
|
||||||
checkAll(getAllIds(), lastTimeInLog)
|
checkAll(getAllIds(), lastTimeInLog)
|
||||||
|
|||||||
Reference in New Issue
Block a user