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")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
17 from __future__ import absolute_import, print_function
18 import os.path, re, resource, struct, sys, time
20 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
22 from bup import compat, git, bloom, midx, options, _helpers
23 from bup.compat import range
24 from bup.helpers import handle_ctrl_c
25 from bup.io import byte_stream
34 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
37 f = open(b'/proc/self/status', 'rb')
40 log('Warning: %s\n' % e)
44 # Note that on Solaris, this file exists but is binary. If that
45 # happens, this split() might not return two elements. We don't
46 # really need to care about the binary format since this output
47 # isn't used for much and report() can deal with missing entries.
48 t = re.split(br':\s*', line.strip(), 1)
55 last = last_u = last_s = start = 0
56 def report(count, out):
57 global last, last_u, last_s, start
58 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
59 ru = resource.getrusage(resource.RUSAGE_SELF)
61 rss = int(ru.ru_maxrss // 1024)
63 rss = linux_memstat().get(b'VmRSS', b'??')
66 int((ru.ru_utime - last_u) * 1000),
67 int((ru.ru_stime - last_s) * 1000),
68 int((now - last) * 1000)]
69 fmt = '%9s ' + ('%10s ' * len(fields))
71 line = fmt % tuple([count] + fields)
72 out.write(line.encode('ascii') + b'\n')
75 out.write((fmt % tuple([''] + headers)).encode('ascii') + b'\n')
78 # don't include time to run report() in usage counts
79 ru = resource.getrusage(resource.RUSAGE_SELF)
86 bup memtest [-n elements] [-c cycles]
88 n,number= number of objects per cycle [10000]
89 c,cycles= number of cycles to run [100]
90 ignore-midx ignore .midx files, use only .idx files
91 existing test with existing objects instead of fake ones
93 o = options.Options(optspec)
94 opt, flags, extra = o.parse(compat.argv[1:])
97 o.fatal('no arguments expected')
99 git.check_repo_or_die()
100 m = git.PackIdxList(git.repo(b'objects/pack'), ignore_midx=opt.ignore_midx)
103 out = byte_stream(sys.stdout)
106 _helpers.random_sha()
114 objit = iter(foreverit(m))
116 for c in range(opt.cycles):
117 for n in range(opt.number):
120 assert(m.exists(bin))
122 bin = _helpers.random_sha()
124 # technically, a randomly generated object id might exist.
125 # but the likelihood of that is the likelihood of finding
126 # a collision in sha-1 by accident, which is so unlikely that
128 assert(not m.exists(bin))
129 report((c+1)*opt.number, out)
131 if bloom._total_searches:
132 out.write(b'bloom: %d objects searched in %d steps: avg %.3f steps/object\n'
133 % (bloom._total_searches, bloom._total_steps,
134 bloom._total_steps*1.0/bloom._total_searches))
135 if midx._total_searches:
136 out.write(b'midx: %d objects searched in %d steps: avg %.3f steps/object\n'
137 % (midx._total_searches, midx._total_steps,
138 midx._total_steps*1.0/midx._total_searches))
139 if git._total_searches:
140 out.write(b'idx: %d objects searched in %d steps: avg %.3f steps/object\n'
141 % (git._total_searches, git._total_steps,
142 git._total_steps*1.0/git._total_searches))
143 out.write(b'Total time: %.3fs\n' % (time.time() - start))