2 import sys, re, struct, mmap, time
3 from bup import git, options
4 from bup.helpers import *
8 def s_from_bytes(bytes):
9 clist = [chr(b) for b in bytes]
16 fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
18 for line in open('/proc/self/status').readlines():
19 l = re.split(r':\s*', line.strip(), 1)
22 d['ms'] = int((now - last) * 1000)
25 fields = [d[k] for k in fields]
29 print ('%9s ' + ('%10s ' * len(fields))) % tuple([e1] + fields)
35 bup memtest [-n elements] [-c cycles]
37 n,number= number of objects per cycle [10000]
38 c,cycles= number of cycles to run [100]
39 ignore-midx ignore .midx files, use only .idx files
40 existing test with existing objects instead of fake ones
42 o = options.Options('bup memtest', optspec)
43 (opt, flags, extra) = o.parse(sys.argv[1:])
46 o.fatal('no arguments expected')
48 git.ignore_midx = opt.ignore_midx
50 git.check_repo_or_die()
51 m = git.PackIdxList(git.repo('objects/pack'))
54 f = open('/dev/urandom')
63 objit = iter(foreverit(m))
65 for c in xrange(opt.cycles):
66 for n in xrange(opt.number):
73 a[2] = chr(ord(b[2]) & 0xf0)
76 # technically, a randomly generated object id might exist.
77 # but the likelihood of that is the likelihood of finding
78 # a collision in sha-1 by accident, which is so unlikely that
80 assert(not m.exists(bin))
81 report((c+1)*opt.number)
83 print ('%d objects searched in %d steps: avg %.3f steps/object'
84 % (git._total_searches, git._total_steps,
85 git._total_steps*1.0/git._total_searches))
86 print 'Total time: %.3fs' % (time.time() - start)