Commit e4d4762a authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Kirill Smelkov

support csv output by '-c' or '--csv'.

parent 8dc37247
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# Based on a transaction analyzer by Matt Kromer. # Based on a transaction analyzer by Matt Kromer.
import sys import sys
import os
import getopt
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB.utils import get_pickle_metadata from ZODB.utils import get_pickle_metadata
...@@ -39,30 +41,43 @@ def shorten(s, n): ...@@ -39,30 +41,43 @@ def shorten(s, n):
l = len(s) l = len(s)
return "..." + s return "..." + s
def report(rep): def report(rep, csv=False):
print "Processed %d records in %d transactions" % (rep.OIDS, rep.TIDS) if not csv:
print "Average record size is %7.2f bytes" % (rep.DBYTES * 1.0 / rep.OIDS) print "Processed %d records in %d transactions" % (rep.OIDS, rep.TIDS)
print ("Average transaction size is %7.2f bytes" % print "Average record size is %7.2f bytes" % (rep.DBYTES * 1.0 / rep.OIDS)
(rep.DBYTES * 1.0 / rep.TIDS)) print ("Average transaction size is %7.2f bytes" %
(rep.DBYTES * 1.0 / rep.TIDS))
print "Types used:" print "Types used:"
fmt = "%-46s %7s %9s %6s %7s %7s %9s %7s %9s" if csv:
fmtp = "%-46s %7d %9d %5.1f%% %7.2f %7d %9d %7d %9d" # per-class format fmt = "%s,%s,%s,%s,%s,%s,%s,%s,%s"
fmtp = "%s,%d,%d,%f%%,%f,%d,%d,%d,%d" # per-class format
else:
fmt = "%-46s %7s %9s %6s %7s %7s %9s %7s %9s"
fmtp = "%-46s %7d %9d %5.1f%% %7.2f %7d %9d %7d %9d" # per-class format
fmts = "%46s %7d %8dk %5.1f%% %7.2f" # summary format fmts = "%46s %7d %8dk %5.1f%% %7.2f" # summary format
print fmt % ("Class Name", "T.Count", "T.Bytes", "Pct", "AvgSize", print fmt % ("Class Name", "T.Count", "T.Bytes", "Pct", "AvgSize",
"C.Count", "C.Bytes", "O.Count", "O.Bytes") "C.Count", "C.Bytes", "O.Count", "O.Bytes")
print fmt % ('-'*46, '-'*7, '-'*9, '-'*5, '-'*7, '-'*7, '-'*9, '-'*7, '-'*9) if not csv:
print fmt % ('-'*46, '-'*7, '-'*9, '-'*5, '-'*7, '-'*7, '-'*9, '-'*7, '-'*9)
typemap = rep.TYPEMAP.keys() typemap = rep.TYPEMAP.keys()
typemap.sort(key=lambda a:rep.TYPESIZE[a]) typemap.sort(key=lambda a:rep.TYPESIZE[a])
cumpct = 0.0 cumpct = 0.0
for t in typemap: for t in typemap:
pct = rep.TYPESIZE[t] * 100.0 / rep.DBYTES pct = rep.TYPESIZE[t] * 100.0 / rep.DBYTES
cumpct += pct cumpct += pct
print fmtp % (shorten(t, 46), rep.TYPEMAP[t], rep.TYPESIZE[t], if csv:
t_display = t
else:
t_display = shorten(t, 46)
print fmtp % (t_display, rep.TYPEMAP[t], rep.TYPESIZE[t],
pct, rep.TYPESIZE[t] * 1.0 / rep.TYPEMAP[t], pct, rep.TYPESIZE[t] * 1.0 / rep.TYPEMAP[t],
rep.COIDSMAP[t], rep.CBYTESMAP[t], rep.COIDSMAP[t], rep.CBYTESMAP[t],
rep.FOIDSMAP.get(t, 0), rep.FBYTESMAP.get(t, 0)) rep.FOIDSMAP.get(t, 0), rep.FBYTESMAP.get(t, 0))
if csv:
return
print fmt % ('='*46, '='*7, '='*9, '='*5, '='*7, '='*7, '='*9, '='*7, '='*9) print fmt % ('='*46, '='*7, '='*9, '='*5, '='*7, '='*7, '='*9, '='*7, '='*9)
print "%46s %7d %9s %6s %6.2fk" % ('Total Transactions', rep.TIDS, ' ', print "%46s %7d %9s %6s %6.2fk" % ('Total Transactions', rep.TIDS, ' ',
' ', rep.DBYTES * 1.0 / rep.TIDS / 1024.0) ' ', rep.DBYTES * 1.0 / rep.TIDS / 1024.0)
...@@ -127,6 +142,36 @@ def analyze_rec(report, record): ...@@ -127,6 +142,36 @@ def analyze_rec(report, record):
except Exception, err: except Exception, err:
print err print err
__doc__ = """%(program)s: Data.fs analyzer
usage: %(program)s [options] /path/to/Data.fs
Options:
-h, --help this help screen
-c, --csv output CSV
"""
def usage(stream, msg=None):
if msg:
print >>stream, msg
print >>stream
program = os.path.basename(sys.argv[0])
print >>stream, __doc__ % {"program": program}
def main(): def main():
path = sys.argv[1] try:
report(analyze(path)) opts, args = getopt.getopt(sys.argv[1:],
'hc', ['help', 'csv'])
path = args[0]
except (getopt.GetoptError, IndexError), msg:
usage(sys.stderr, msg)
sys.exit(2)
csv = False
for opt, args in opts:
if opt in ('-c', '--csv'):
csv = True
elif opt in ('-h', '--help'):
usage(sys.stdout)
sys.exit()
report(analyze(path), csv)
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