[Zodb-checkins] CVS: ZODB3/Tools - parsezeolog.py:1.1.16.1
Jeremy Hylton
jeremy@zope.com
Thu, 12 Dec 2002 16:39:08 -0500
Update of /cvs-repository/ZODB3/Tools
In directory cvs.zope.org:/tmp/cvs-serv11786
Modified Files:
Tag: ZODB3-3_1-branch
parsezeolog.py
Log Message:
Backport from the trunk: A version that works with current ZEO2 log output.
=== ZODB3/Tools/parsezeolog.py 1.1 => 1.1.16.1 ===
--- ZODB3/Tools/parsezeolog.py:1.1 Mon Apr 29 11:12:48 2002
+++ ZODB3/Tools/parsezeolog.py Thu Dec 12 16:39:08 2002
@@ -1,4 +1,4 @@
-"""Parse the BLATHER logging generated by ZEO.
+"""Parse the BLATHER logging generated by ZEO2.
An example of the log format is:
2002-04-15T13:05:29 BLATHER(-100) ZEO Server storea(3235680, [714], 235339406490168806) ('10.0.26.30', 45514)
@@ -20,7 +20,7 @@
time_l = [int(elt) for elt in time_.split(':')]
return int(time.mktime(date_l + time_l + [0, 0, 0]))
-rx_meth = re.compile("ZEO Server (\w+)\((.*)\) \('(.*)', (\d+)")
+rx_meth = re.compile("zrpc:\d+ calling (\w+)\((.*)")
def parse_method(line):
pass
@@ -29,72 +29,92 @@
"""Parse a log entry and return time, method info, and client."""
t = parse_time(line)
if t is None:
- return None, None, None
+ return None, None
mo = rx_meth.search(line)
if mo is None:
- return None, None, None
+ return None, None
meth_name = mo.group(1)
- meth_args = mo.group(2)
+ meth_args = mo.group(2).strip()
+ if meth_args.endswith(')'):
+ meth_args = meth_args[:-1]
meth_args = [s.strip() for s in meth_args.split(",")]
m = meth_name, tuple(meth_args)
- c = mo.group(3), mo.group(4)
- return t, m, c
+ return t, m
class TStats:
- pass
+
+ counter = 1
+
+ def __init__(self):
+ self.id = TStats.counter
+ TStats.counter += 1
+
+ fields = ("time", "vote", "done", "user", "path")
+ fmt = "%-24s %5s %5s %-15s %s"
+ hdr = fmt % fields
+
+ def report(self):
+ """Print a report about the transaction"""
+ t = time.ctime(self.begin)
+ if hasattr(self, "vote"):
+ d_vote = self.vote - self.begin
+ else:
+ d_vote = "*"
+ if hasattr(self, "finish"):
+ d_finish = self.finish - self.begin
+ else:
+ d_finish = "*"
+ print self.fmt % (time.ctime(self.begin), d_vote, d_finish,
+ self.user, self.url)
class TransactionParser:
def __init__(self):
- self.transactions = []
- self.cur_t = {}
+ self.txns = {}
self.skipped = 0
def parse(self, line):
- t, m, c = parse_line(line)
+ t, m = parse_line(line)
if t is None:
return
name = m[0]
meth = getattr(self, name, None)
if meth is not None:
- meth(t, m[1], c)
+ meth(t, m[1])
- def tpc_begin(self, time, args, client):
+ def tpc_begin(self, time, args):
t = TStats()
t.begin = time
+ t.user = args[1]
t.url = args[2]
t.objects = []
- self.cur_t[client] = t
+ tid = eval(args[0])
+ self.txns[tid] = t
+
+ def get_txn(self, args):
+ tid = eval(args[0])
+ try:
+ return self.txns[tid]
+ except KeyError:
+ print "uknown tid", repr(tid)
+ return None
- def tpc_finish(self, time, args, client):
- t = self.cur_t.get(client, None)
+ def tpc_finish(self, time, args):
+ t = self.get_txn(args)
if t is None:
- self.skipped += 1
return
t.finish = time
-## self.transactions.append(t)
- self.report(t)
- self.cur_t[client] = None
- def storea(self, time, args, client):
- t = self.cur_t.get(client, None)
+ def vote(self, time, args):
+ t = self.get_txn(args)
if t is None:
- self.skipped += 1
return
- # append the oid and the length of the object
- # parse the length as [NNN]
- info = int(args[0]), int(args[1][1:-1])
- t.objects.append(info)
+ t.vote = time
- def report(self, t):
- """Print a report about the transaction"""
- if t.objects:
- bytes = reduce(operator.add, [size for oid, size in t.objects])
- else:
- bytes = 0
- print "%s %2d %4d %10d %s" % (t.begin, t.finish - t.begin,
- len(t.objects), bytes,
- time.ctime(t.begin)), t.url
+ def get_txns(self):
+ L = [(t.id, t) for t in self.txns.values()]
+ L.sort()
+ return [t for (id, t) in L]
if __name__ == "__main__":
import fileinput
@@ -108,4 +128,7 @@
except:
print "line", i
raise
- print len(p.transactions)
+ print "Transaction: %d" % len(p.txns)
+ print TStats.hdr
+ for txn in p.get_txns():
+ txn.report()