3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/bup-python" || exit $?
13 exec "$bup_python" "$0"
17 from __future__ import absolute_import, print_function
18 import sys, re, struct, time, resource
20 from bup import compat, git, bloom, midx, options, _helpers
21 from bup.compat import range
22 from bup.helpers import handle_ctrl_c
23 from bup.io import byte_stream
32 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
35 f = open(b'/proc/self/status', 'rb')
38 log('Warning: %s\n' % e)
42 # Note that on Solaris, this file exists but is binary. If that
43 # happens, this split() might not return two elements. We don't
44 # really need to care about the binary format since this output
45 # isn't used for much and report() can deal with missing entries.
46 t = re.split(br':\s*', line.strip(), 1)
53 last = last_u = last_s = start = 0
54 def report(count, out):
55 global last, last_u, last_s, start
56 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
57 ru = resource.getrusage(resource.RUSAGE_SELF)
59 rss = int(ru.ru_maxrss // 1024)
61 rss = linux_memstat().get(b'VmRSS', b'??')
64 int((ru.ru_utime - last_u) * 1000),
65 int((ru.ru_stime - last_s) * 1000),
66 int((now - last) * 1000)]
67 fmt = '%9s ' + ('%10s ' * len(fields))
69 line = fmt % tuple([count] + fields)
70 out.write(line.encode('ascii') + b'\n')
73 out.write((fmt % tuple([''] + headers)).encode('ascii') + b'\n')
76 # don't include time to run report() in usage counts
77 ru = resource.getrusage(resource.RUSAGE_SELF)
84 bup memtest [-n elements] [-c cycles]
86 n,number= number of objects per cycle [10000]
87 c,cycles= number of cycles to run [100]
88 ignore-midx ignore .midx files, use only .idx files
89 existing test with existing objects instead of fake ones
91 o = options.Options(optspec)
92 opt, flags, extra = o.parse(compat.argv[1:])
95 o.fatal('no arguments expected')
97 git.check_repo_or_die()
98 m = git.PackIdxList(git.repo(b'objects/pack'), ignore_midx=opt.ignore_midx)
101 out = byte_stream(sys.stdout)
104 _helpers.random_sha()
112 objit = iter(foreverit(m))
114 for c in range(opt.cycles):
115 for n in range(opt.number):
118 assert(m.exists(bin))
120 bin = _helpers.random_sha()
122 # technically, a randomly generated object id might exist.
123 # but the likelihood of that is the likelihood of finding
124 # a collision in sha-1 by accident, which is so unlikely that
126 assert(not m.exists(bin))
127 report((c+1)*opt.number, out)
129 if bloom._total_searches:
130 out.write(b'bloom: %d objects searched in %d steps: avg %.3f steps/object\n'
131 % (bloom._total_searches, bloom._total_steps,
132 bloom._total_steps*1.0/bloom._total_searches))
133 if midx._total_searches:
134 out.write(b'midx: %d objects searched in %d steps: avg %.3f steps/object\n'
135 % (midx._total_searches, midx._total_steps,
136 midx._total_steps*1.0/midx._total_searches))
137 if git._total_searches:
138 out.write(b'idx: %d objects searched in %d steps: avg %.3f steps/object\n'
139 % (git._total_searches, git._total_steps,
140 git._total_steps*1.0/git._total_searches))
141 out.write(b'Total time: %.3fs\n' % (time.time() - start))