2 from __future__ import absolute_import, print_function
3 import re, resource, sys, time
5 from bup import git, bloom, midx, options, _helpers
6 from bup.io import byte_stream
7 from bup.helpers import log
13 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
16 f = open(b'/proc/self/status', 'rb')
19 log('Warning: %s\n' % e)
23 # Note that on Solaris, this file exists but is binary. If that
24 # happens, this split() might not return two elements. We don't
25 # really need to care about the binary format since this output
26 # isn't used for much and report() can deal with missing entries.
27 t = re.split(br':\s*', line.strip(), 1)
34 last = last_u = last_s = start = 0
35 def report(count, out):
36 global last, last_u, last_s, start
37 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
38 ru = resource.getrusage(resource.RUSAGE_SELF)
40 rss = int(ru.ru_maxrss // 1024)
42 rss = linux_memstat().get(b'VmRSS', b'??')
45 int((ru.ru_utime - last_u) * 1000),
46 int((ru.ru_stime - last_s) * 1000),
47 int((now - last) * 1000)]
48 fmt = '%9s ' + ('%10s ' * len(fields))
50 line = fmt % tuple([count] + fields)
51 out.write(line.encode('ascii') + b'\n')
54 out.write((fmt % tuple([''] + headers)).encode('ascii') + b'\n')
57 # don't include time to run report() in usage counts
58 ru = resource.getrusage(resource.RUSAGE_SELF)
65 bup memtest [-n elements] [-c cycles]
67 n,number= number of objects per cycle [10000]
68 c,cycles= number of cycles to run [100]
69 ignore-midx ignore .midx files, use only .idx files
70 existing test with existing objects instead of fake ones
74 o = options.Options(optspec)
75 opt, flags, extra = o.parse_bytes(argv[1:])
78 o.fatal('no arguments expected')
80 git.check_repo_or_die()
82 out = byte_stream(sys.stdout)
88 with git.PackIdxList(git.repo(b'objects/pack'),
89 ignore_midx=opt.ignore_midx) as m:
96 objit = iter(foreverit(m))
98 for c in range(opt.cycles):
99 for n in range(opt.number):
102 assert(m.exists(bin))
104 bin = _helpers.random_sha()
106 # technically, a randomly generated object id might exist.
107 # but the likelihood of that is the likelihood of finding
108 # a collision in sha-1 by accident, which is so unlikely that
110 assert(not m.exists(bin))
111 report((c+1)*opt.number, out)
113 if bloom._total_searches:
114 out.write(b'bloom: %d objects searched in %d steps: avg %.3f steps/object\n'
115 % (bloom._total_searches, bloom._total_steps,
116 bloom._total_steps*1.0/bloom._total_searches))
117 if midx._total_searches:
118 out.write(b'midx: %d objects searched in %d steps: avg %.3f steps/object\n'
119 % (midx._total_searches, midx._total_steps,
120 midx._total_steps*1.0/midx._total_searches))
121 if git._total_searches:
122 out.write(b'idx: %d objects searched in %d steps: avg %.3f steps/object\n'
123 % (git._total_searches, git._total_steps,
124 git._total_steps*1.0/git._total_searches))
125 out.write(b'Total time: %.3fs\n' % (time.time() - start))