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