X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=blobdiff_plain;f=cmd%2Fmemtest-cmd.py;h=88ee06d92cd919700dacd31467a1e0257b0f7d64;hp=4ed7c4742d4433d7631444239444624ebd1fea8a;hb=aeafe13a9330e7deca3dc6b9c0496937d904663a;hpb=6c2c0f678d458a90eaf606707b59154f62cef62b diff --git a/cmd/memtest-cmd.py b/cmd/memtest-cmd.py index 4ed7c47..88ee06d 100755 --- a/cmd/memtest-cmd.py +++ b/cmd/memtest-cmd.py @@ -1,10 +1,20 @@ -#!/usr/bin/env python +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble + +from __future__ import absolute_import, print_function import sys, re, struct, time, resource -from bup import git, options, _helpers -from bup.helpers import * + +from bup import git, bloom, midx, options, _helpers +from bup.helpers import handle_ctrl_c + handle_ctrl_c() + _linux_warned = 0 def linux_memstat(): global _linux_warned @@ -12,7 +22,7 @@ def linux_memstat(): d = {} try: f = open('/proc/self/status') - except IOError, e: + except IOError as e: if not _linux_warned: log('Warning: %s\n' % e) _linux_warned = 1 @@ -45,12 +55,12 @@ def report(count): int((now - last) * 1000)] fmt = '%9s ' + ('%10s ' * len(fields)) if count >= 0: - print fmt % tuple([count] + fields) + print(fmt % tuple([count] + fields)) else: start = now - print fmt % tuple([''] + headers) + print(fmt % tuple([''] + headers)) sys.stdout.flush() - + # don't include time to run report() in usage counts ru = resource.getrusage(resource.RUSAGE_SELF) last_u = ru.ru_utime @@ -78,7 +88,7 @@ git.check_repo_or_die() m = git.PackIdxList(git.repo('objects/pack')) report(-1) -_helpers.random_partial_sha() +_helpers.random_sha() report(0) if opt.existing: @@ -91,10 +101,10 @@ if opt.existing: for c in xrange(opt.cycles): for n in xrange(opt.number): if opt.existing: - bin = objit.next() + bin = next(objit) assert(m.exists(bin)) else: - bin = _helpers.random_partial_sha() + bin = _helpers.random_sha() # technically, a randomly generated object id might exist. # but the likelihood of that is the likelihood of finding @@ -103,7 +113,16 @@ for c in xrange(opt.cycles): assert(not m.exists(bin)) report((c+1)*opt.number) -print ('%d objects searched in %d steps: avg %.3f steps/object' - % (git._total_searches, git._total_steps, - git._total_steps*1.0/git._total_searches)) -print 'Total time: %.3fs' % (time.time() - start) +if bloom._total_searches: + print('bloom: %d objects searched in %d steps: avg %.3f steps/object' + % (bloom._total_searches, bloom._total_steps, + bloom._total_steps*1.0/bloom._total_searches)) +if midx._total_searches: + print('midx: %d objects searched in %d steps: avg %.3f steps/object' + % (midx._total_searches, midx._total_steps, + midx._total_steps*1.0/midx._total_searches)) +if git._total_searches: + print('idx: %d objects searched in %d steps: avg %.3f steps/object' + % (git._total_searches, git._total_steps, + git._total_steps*1.0/git._total_searches)) +print('Total time: %.3fs' % (time.time() - start))