3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import, print_function
9 import sys, re, struct, time, resource
11 from bup import git, bloom, midx, options, _helpers
12 from bup.compat import range
13 from bup.helpers import handle_ctrl_c
14 from bup.io import byte_stream
23 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
26 f = open(b'/proc/self/status', 'rb')
29 log('Warning: %s\n' % e)
33 # Note that on Solaris, this file exists but is binary. If that
34 # happens, this split() might not return two elements. We don't
35 # really need to care about the binary format since this output
36 # isn't used for much and report() can deal with missing entries.
37 t = re.split(br':\s*', line.strip(), 1)
44 last = last_u = last_s = start = 0
45 def report(count, out):
46 global last, last_u, last_s, start
47 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
48 ru = resource.getrusage(resource.RUSAGE_SELF)
50 rss = int(ru.ru_maxrss // 1024)
52 rss = linux_memstat().get(b'VmRSS', b'??')
55 int((ru.ru_utime - last_u) * 1000),
56 int((ru.ru_stime - last_s) * 1000),
57 int((now - last) * 1000)]
58 fmt = '%9s ' + ('%10s ' * len(fields))
60 line = fmt % tuple([count] + fields)
61 out.write(line.encode('ascii') + b'\n')
64 out.write((fmt % tuple([''] + headers)).encode('ascii') + b'\n')
67 # don't include time to run report() in usage counts
68 ru = resource.getrusage(resource.RUSAGE_SELF)
75 bup memtest [-n elements] [-c cycles]
77 n,number= number of objects per cycle [10000]
78 c,cycles= number of cycles to run [100]
79 ignore-midx ignore .midx files, use only .idx files
80 existing test with existing objects instead of fake ones
82 o = options.Options(optspec)
83 (opt, flags, extra) = o.parse(sys.argv[1:])
86 o.fatal('no arguments expected')
88 git.check_repo_or_die()
89 m = git.PackIdxList(git.repo(b'objects/pack'), ignore_midx=opt.ignore_midx)
92 out = byte_stream(sys.stdout)
103 objit = iter(foreverit(m))
105 for c in range(opt.cycles):
106 for n in range(opt.number):
109 assert(m.exists(bin))
111 bin = _helpers.random_sha()
113 # technically, a randomly generated object id might exist.
114 # but the likelihood of that is the likelihood of finding
115 # a collision in sha-1 by accident, which is so unlikely that
117 assert(not m.exists(bin))
118 report((c+1)*opt.number, out)
120 if bloom._total_searches:
121 out.write(b'bloom: %d objects searched in %d steps: avg %.3f steps/object\n'
122 % (bloom._total_searches, bloom._total_steps,
123 bloom._total_steps*1.0/bloom._total_searches))
124 if midx._total_searches:
125 out.write(b'midx: %d objects searched in %d steps: avg %.3f steps/object\n'
126 % (midx._total_searches, midx._total_steps,
127 midx._total_steps*1.0/midx._total_searches))
128 if git._total_searches:
129 out.write(b'idx: %d objects searched in %d steps: avg %.3f steps/object\n'
130 % (git._total_searches, git._total_steps,
131 git._total_steps*1.0/git._total_searches))
132 out.write(b'Total time: %.3fs\n' % (time.time() - start))