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
22 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
25 f = open('/proc/self/status')
28 log('Warning: %s\n' % e)
32 # Note that on Solaris, this file exists but is binary. If that
33 # happens, this split() might not return two elements. We don't
34 # really need to care about the binary format since this output
35 # isn't used for much and report() can deal with missing entries.
36 t = re.split(r':\s*', line.strip(), 1)
43 last = last_u = last_s = start = 0
45 global last, last_u, last_s, start
46 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
47 ru = resource.getrusage(resource.RUSAGE_SELF)
49 rss = int(ru.ru_maxrss/1024)
51 rss = linux_memstat().get('VmRSS', '??')
54 int((ru.ru_utime - last_u) * 1000),
55 int((ru.ru_stime - last_s) * 1000),
56 int((now - last) * 1000)]
57 fmt = '%9s ' + ('%10s ' * len(fields))
59 print(fmt % tuple([count] + fields))
62 print(fmt % tuple([''] + headers))
65 # don't include time to run report() in usage counts
66 ru = resource.getrusage(resource.RUSAGE_SELF)
73 bup memtest [-n elements] [-c cycles]
75 n,number= number of objects per cycle [10000]
76 c,cycles= number of cycles to run [100]
77 ignore-midx ignore .midx files, use only .idx files
78 existing test with existing objects instead of fake ones
80 o = options.Options(optspec)
81 (opt, flags, extra) = o.parse(sys.argv[1:])
84 o.fatal('no arguments expected')
86 git.check_repo_or_die()
87 m = git.PackIdxList(git.repo('objects/pack'), ignore_midx=opt.ignore_midx)
98 objit = iter(foreverit(m))
100 for c in range(opt.cycles):
101 for n in range(opt.number):
104 assert(m.exists(bin))
106 bin = _helpers.random_sha()
108 # technically, a randomly generated object id might exist.
109 # but the likelihood of that is the likelihood of finding
110 # a collision in sha-1 by accident, which is so unlikely that
112 assert(not m.exists(bin))
113 report((c+1)*opt.number)
115 if bloom._total_searches:
116 print('bloom: %d objects searched in %d steps: avg %.3f steps/object'
117 % (bloom._total_searches, bloom._total_steps,
118 bloom._total_steps*1.0/bloom._total_searches))
119 if midx._total_searches:
120 print('midx: %d objects searched in %d steps: avg %.3f steps/object'
121 % (midx._total_searches, midx._total_steps,
122 midx._total_steps*1.0/midx._total_searches))
123 if git._total_searches:
124 print('idx: %d objects searched in %d steps: avg %.3f steps/object'
125 % (git._total_searches, git._total_steps,
126 git._total_steps*1.0/git._total_searches))
127 print('Total time: %.3fs' % (time.time() - start))