3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
8 from __future__ import absolute_import
9 import sys, re, struct, time, resource
11 from bup import git, bloom, midx, options, _helpers
12 from bup.helpers import handle_ctrl_c
21 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
24 f = open('/proc/self/status')
27 log('Warning: %s\n' % e)
31 # Note that on Solaris, this file exists but is binary. If that
32 # happens, this split() might not return two elements. We don't
33 # really need to care about the binary format since this output
34 # isn't used for much and report() can deal with missing entries.
35 t = re.split(r':\s*', line.strip(), 1)
42 last = last_u = last_s = start = 0
44 global last, last_u, last_s, start
45 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
46 ru = resource.getrusage(resource.RUSAGE_SELF)
48 rss = int(ru.ru_maxrss/1024)
50 rss = linux_memstat().get('VmRSS', '??')
53 int((ru.ru_utime - last_u) * 1000),
54 int((ru.ru_stime - last_s) * 1000),
55 int((now - last) * 1000)]
56 fmt = '%9s ' + ('%10s ' * len(fields))
58 print fmt % tuple([count] + fields)
61 print fmt % tuple([''] + headers)
64 # don't include time to run report() in usage counts
65 ru = resource.getrusage(resource.RUSAGE_SELF)
72 bup memtest [-n elements] [-c cycles]
74 n,number= number of objects per cycle [10000]
75 c,cycles= number of cycles to run [100]
76 ignore-midx ignore .midx files, use only .idx files
77 existing test with existing objects instead of fake ones
79 o = options.Options(optspec)
80 (opt, flags, extra) = o.parse(sys.argv[1:])
83 o.fatal('no arguments expected')
85 git.ignore_midx = opt.ignore_midx
87 git.check_repo_or_die()
88 m = git.PackIdxList(git.repo('objects/pack'))
99 objit = iter(foreverit(m))
101 for c in xrange(opt.cycles):
102 for n in xrange(opt.number):
105 assert(m.exists(bin))
107 bin = _helpers.random_sha()
109 # technically, a randomly generated object id might exist.
110 # but the likelihood of that is the likelihood of finding
111 # a collision in sha-1 by accident, which is so unlikely that
113 assert(not m.exists(bin))
114 report((c+1)*opt.number)
116 if bloom._total_searches:
117 print ('bloom: %d objects searched in %d steps: avg %.3f steps/object'
118 % (bloom._total_searches, bloom._total_steps,
119 bloom._total_steps*1.0/bloom._total_searches))
120 if midx._total_searches:
121 print ('midx: %d objects searched in %d steps: avg %.3f steps/object'
122 % (midx._total_searches, midx._total_steps,
123 midx._total_steps*1.0/midx._total_searches))
124 if git._total_searches:
125 print ('idx: %d objects searched in %d steps: avg %.3f steps/object'
126 % (git._total_searches, git._total_steps,
127 git._total_steps*1.0/git._total_searches))
128 print 'Total time: %.3fs' % (time.time() - start)