Commit c09bd60b authored by Guido van Rossum's avatar Guido van Rossum

Add summary printing, proper command line option parsing, and a -v

option.
parent 9203aa1c
...@@ -14,23 +14,49 @@ from ZODB.FileStorage import FileStorage ...@@ -14,23 +14,49 @@ from ZODB.FileStorage import FileStorage
from ZODB.utils import U64 from ZODB.utils import U64
from ZODB.fsdump import get_pickle_metadata from ZODB.fsdump import get_pickle_metadata
def main(path): def run(path, v=0):
fs = FileStorage(path, read_only=1) fs = FileStorage(path, read_only=1)
# break into the file implementation # break into the file implementation
if hasattr(fs._index, 'iterkeys'): if hasattr(fs._index, 'iterkeys'):
iter = fs._index.iterkeys() iter = fs._index.iterkeys()
else: else:
iter = fs._index.keys() iter = fs._index.keys()
totals = {}
for oid in iter: for oid in iter:
data, serialno = fs.load(oid, '') data, serialno = fs.load(oid, '')
mod, klass = get_pickle_metadata(data) mod, klass = get_pickle_metadata(data)
print "%8s %5d %s.%s" % (U64(oid), len(data), mod, klass) key = "%s.%s" % (mod, klass)
bytes, count = totals.get(key, (0, 0))
bytes += len(data)
count += 1
totals[key] = bytes, count
if v:
print "%8s %5d %s" % (U64(oid), len(data), key)
L = totals.items()
L.sort(lambda a, b: cmp(b, a))
L.reverse()
print "Totals per object class:"
for key, (bytes, count) in L:
print "%8d %8d %s" % (count, bytes, key)
if __name__ == "__main__": def main():
import sys import sys
import getopt
try: try:
path, = sys.argv[1:] opts, args = getopt.getopt(sys.argv[1:], "v")
except ValueError: except getopt.error, msg:
print __doc__ print msg
print "usage: space.py [-v] Data.fs"
sys.exit(2)
if len(args) != 1:
print "usage: space.py [-v] Data.fs"
sys.exit(2) sys.exit(2)
main(path) v = 0
for o, a in opts:
if o == "-v":
v += 1
path = args[0]
run(path, v)
if __name__ == "__main__":
main()
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