Skip to content

Commit

Permalink
fsdump/fsstats improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Oct 3, 2021
1 parent 1fb097b commit 403f986
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,12 @@
5.6.1 (unreleased)
==================

- Readd transaction size information to ``fsdump`` output;
adapt `fsstats` to ``fsdump``'s exchanged order for ``size`` and ``class``
information in data records;
(fixes `#354 <https://github.com/zopefoundation/ZODB/issues/354>_).
Make ``fsdump`` callable via Python's ``-m`` command line option.

- Fix UnboundLocalError when running fsoids.py script.
See `issue 285 <https://github.com/zopefoundation/ZODB/issues/285>`_.

Expand Down
14 changes: 10 additions & 4 deletions src/ZODB/FileStorage/fsdump.py
Expand Up @@ -23,12 +23,14 @@
def fsdump(path, file=None, with_offset=1):
iter = FileIterator(path)
for i, trans in enumerate(iter):
size = trans._tend - trans._tpos
if with_offset:
print(("Trans #%05d tid=%016x time=%s offset=%d" %
(i, u64(trans.tid), TimeStamp(trans.tid), trans._pos)), file=file)
print(("Trans #%05d tid=%016x size=%d time=%s offset=%d" %
(i, u64(trans.tid), size,
TimeStamp(trans.tid), trans._pos)), file=file)
else:
print(("Trans #%05d tid=%016x time=%s" %
(i, u64(trans.tid), TimeStamp(trans.tid))), file=file)
print(("Trans #%05d tid=%016x size=%d time=%s" %
(i, u64(trans.tid), size, TimeStamp(trans.tid))), file=file)
print((" status=%r user=%r description=%r" %
(trans.status, trans.user, trans.description)), file=file)

Expand Down Expand Up @@ -122,3 +124,7 @@ def dump_data(self, tloc):
def main():
import sys
fsdump(sys.argv[1])


if __name__ == "__main__":
main()
11 changes: 7 additions & 4 deletions src/ZODB/scripts/fsstats.py
Expand Up @@ -7,7 +7,7 @@
from six.moves import filter

rx_txn = re.compile("tid=([0-9a-f]+).*size=(\d+)")
rx_data = re.compile("oid=([0-9a-f]+) class=(\S+) size=(\d+)")
rx_data = re.compile("oid=([0-9a-f]+) size=(\d+) class=(\S+)")

def sort_byhsize(seq, reverse=False):
L = [(v.size(), k, v) for k, v in seq]
Expand Down Expand Up @@ -50,7 +50,10 @@ def mode(self):
return mode

def make_bins(self, binsize):
maxkey = max(six.iterkeys(self))
try:
maxkey = max(six.iterkeys(self))
except ValueError:
maxkey = 0
self.binsize = binsize
self.bins = [0] * (1 + maxkey / binsize)
for k, v in six.iteritems(self):
Expand Down Expand Up @@ -104,7 +107,7 @@ def class_detail(class_size):
# per class details
for klass, h in sort_byhsize(six.iteritems(class_size), reverse=True):
h.make_bins(50)
if len(filter(None, h.bins)) == 1:
if len(tuple(filter(None, h.bins))) == 1:
continue
h.report("Object size for %s" % klass, usebins=True)

Expand Down Expand Up @@ -146,7 +149,7 @@ def main(path=None):
m = rx_data.search(line)
if not m:
continue
oid, klass, size = m.groups()
oid, size, klass = m.groups()
size = int(size)

obj_size.add(size)
Expand Down

0 comments on commit 403f986

Please sign in to comment.