X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fmemtest-cmd.py;h=2fe71f516bc29370b1e4da931948bb82d65f4e71;hb=c38e02f0f5daa4ddf4d2c0a553d717d1f3ad02e5;hp=610e4395839c5b27ad3aa3c595bc3772bb81e1fd;hpb=8f7bd67638e5ca99d4eccb382e5c759944aa7ab8;p=bup.git diff --git a/cmd/memtest-cmd.py b/cmd/memtest-cmd.py index 610e439..2fe71f5 100755 --- a/cmd/memtest-cmd.py +++ b/cmd/memtest-cmd.py @@ -1,13 +1,19 @@ -#!/usr/bin/env python -import sys, re, struct, mmap, time, resource -from bup import git, options -from bup.helpers import * +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble -handle_ctrl_c() +from __future__ import absolute_import, print_function +import sys, re, struct, time, resource -def s_from_bytes(bytes): - clist = [chr(b) for b in bytes] - return ''.join(clist) +from bup import git, bloom, midx, options, _helpers +from bup.compat import range +from bup.helpers import handle_ctrl_c + + +handle_ctrl_c() _linux_warned = 0 @@ -17,14 +23,20 @@ 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 return {} for line in f: - k,v = re.split(r':\s*', line.strip(), 1) - d[k] = v + # Note that on Solaris, this file exists but is binary. If that + # happens, this split() might not return two elements. We don't + # really need to care about the binary format since this output + # isn't used for much and report() can deal with missing entries. + t = re.split(r':\s*', line.strip(), 1) + if len(t) == 2: + k,v = t + d[k] = v return d @@ -44,12 +56,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 @@ -65,7 +77,7 @@ c,cycles= number of cycles to run [100] ignore-midx ignore .midx files, use only .idx files existing test with existing objects instead of fake ones """ -o = options.Options('bup memtest', optspec) +o = options.Options(optspec) (opt, flags, extra) = o.parse(sys.argv[1:]) if extra: @@ -77,8 +89,7 @@ git.check_repo_or_die() m = git.PackIdxList(git.repo('objects/pack')) report(-1) -f = open('/dev/urandom') -a = mmap.mmap(-1, 20) +_helpers.random_sha() report(0) if opt.existing: @@ -87,17 +98,14 @@ if opt.existing: for e in mi: yield e objit = iter(foreverit(m)) - -for c in xrange(opt.cycles): - for n in xrange(opt.number): + +for c in range(opt.cycles): + for n in range(opt.number): if opt.existing: - bin = objit.next() + bin = next(objit) assert(m.exists(bin)) else: - b = f.read(3) - a[0:2] = b[0:2] - a[2] = chr(ord(b[2]) & 0xf0) - bin = str(a[0:20]) + bin = _helpers.random_sha() # technically, a randomly generated object id might exist. # but the likelihood of that is the likelihood of finding @@ -106,7 +114,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))