Commit 17499cc7 authored by Guido van Rossum's avatar Guido van Rossum

Two robustness changes: catch interrupts, and recover from broken

records (all the broken records I've seen had a zero timestamp).
parent fee8531c
...@@ -135,71 +135,88 @@ def main(): ...@@ -135,71 +135,88 @@ def main():
byinterval = {} byinterval = {}
thisinterval = None thisinterval = None
h0 = he = None h0 = he = None
while 1: offset = 0
r = f.read(24) f_read = f.read
if len(r) < 24: struct_unpack = struct.unpack
break try:
records += 1 while 1:
ts, code, oid, serial = struct.unpack(">ii8s8s", r) r = f_read(8)
if t0 is None: if len(r) < 8:
t0 = ts break
thisinterval = t0 / interval offset += 8
h0 = he = ts ts, code = struct_unpack(">ii", r)
te = ts if ts == 0:
if ts / interval != thisinterval: # Must be a misaligned record caused by a crash
if not quiet: if not quiet:
dumpbyinterval(byinterval, h0, he) print "Skipping 8 bytes at offset", offset-8
byinterval = {} continue
thisinterval = ts / interval r = f_read(16)
h0 = ts if len(r) < 16:
he = ts break
dlen, code = code & 0x7fffff00, code & 0xff offset += 16
if dlen: records += 1
datarecords += 1 oid, serial = struct_unpack(">8s8s", r)
datasize += dlen if t0 is None:
version = '-' t0 = ts
if code & 0x80: thisinterval = t0 / interval
version = 'V' h0 = he = ts
versions += 1 te = ts
current = code & 1 if ts / interval != thisinterval:
if current: if not quiet:
file1 += 1 dumpbyinterval(byinterval, h0, he)
else: byinterval = {}
file0 += 1 thisinterval = ts / interval
code = code & 0x7e h0 = ts
bycode[code] = bycode.get(code, 0) + 1 he = ts
byinterval[code] = byinterval.get(code, 0) + 1 dlen, code = code & 0x7fffff00, code & 0xff
if dlen: if dlen:
if code & 0x70 == 0x20: # All loads datarecords += 1
bysize[dlen] = d = bysize.get(dlen) or {} datasize += dlen
d[oid] = d.get(oid, 0) + 1 version = '-'
elif code == 0x3A: # Update if code & 0x80:
bysizew[dlen] = d = bysizew.get(dlen) or {} version = 'V'
d[oid] = d.get(oid, 0) + 1 versions += 1
if verbose: current = code & 1
print "%s %d %02x %016x %016x %1s %s" % ( if current:
time.ctime(ts)[4:-5], file1 += 1
current, else:
code, file0 += 1
U64(oid), code = code & 0x7e
U64(serial), bycode[code] = bycode.get(code, 0) + 1
version, byinterval[code] = byinterval.get(code, 0) + 1
dlen and str(dlen) or "") if dlen:
if code & 0x70 == 0x20: if code & 0x70 == 0x20: # All loads
oids[oid] = oids.get(oid, 0) + 1 bysize[dlen] = d = bysize.get(dlen) or {}
total_loads += 1 d[oid] = d.get(oid, 0) + 1
if code in (0x00, 0x70): elif code == 0x3A: # Update
if not quiet: bysizew[dlen] = d = bysizew.get(dlen) or {}
dumpbyinterval(byinterval, h0, he) d[oid] = d.get(oid, 0) + 1
byinterval = {} if verbose:
thisinterval = ts / interval print "%s %d %02x %016x %016x %1s %s" % (
h0 = he = ts time.ctime(ts)[4:-5],
if not quiet: current,
print time.ctime(ts)[4:-5], code,
if code == 0x00: U64(oid),
print '='*20, "Restart", '='*20 U64(serial),
else: version,
print '-'*20, "Flip->%d" % current, '-'*20 dlen and str(dlen) or "")
if code & 0x70 == 0x20:
oids[oid] = oids.get(oid, 0) + 1
total_loads += 1
if code in (0x00, 0x70):
if not quiet:
dumpbyinterval(byinterval, h0, he)
byinterval = {}
thisinterval = ts / interval
h0 = he = ts
if not quiet:
print time.ctime(ts)[4:-5],
if code == 0x00:
print '='*20, "Restart", '='*20
else:
print '-'*20, "Flip->%d" % current, '-'*20
except KeyboardInterrupt:
print "\nInterrupted. Stats so far:\n"
f.close() f.close()
rte = time.time() rte = time.time()
......
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