2 import sys, re, struct, time, resource
3 from bup import git, bloom, midx, options, _helpers
4 from bup.helpers import *
11 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
14 f = open('/proc/self/status')
17 log('Warning: %s\n' % e)
21 # Note that on Solaris, this file exists but is binary. If that
22 # happens, this split() might not return two elements. We don't
23 # really need to care about the binary format since this output
24 # isn't used for much and report() can deal with missing entries.
25 t = re.split(r':\s*', line.strip(), 1)
32 last = last_u = last_s = start = 0
34 global last, last_u, last_s, start
35 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
36 ru = resource.getrusage(resource.RUSAGE_SELF)
38 rss = int(ru.ru_maxrss/1024)
40 rss = linux_memstat().get('VmRSS', '??')
43 int((ru.ru_utime - last_u) * 1000),
44 int((ru.ru_stime - last_s) * 1000),
45 int((now - last) * 1000)]
46 fmt = '%9s ' + ('%10s ' * len(fields))
48 print fmt % tuple([count] + fields)
51 print fmt % tuple([''] + headers)
54 # don't include time to run report() in usage counts
55 ru = resource.getrusage(resource.RUSAGE_SELF)
62 bup memtest [-n elements] [-c cycles]
64 n,number= number of objects per cycle [10000]
65 c,cycles= number of cycles to run [100]
66 ignore-midx ignore .midx files, use only .idx files
67 existing test with existing objects instead of fake ones
69 o = options.Options(optspec)
70 (opt, flags, extra) = o.parse(sys.argv[1:])
73 o.fatal('no arguments expected')
75 git.ignore_midx = opt.ignore_midx
77 git.check_repo_or_die()
78 m = git.PackIdxList(git.repo('objects/pack'))
89 objit = iter(foreverit(m))
91 for c in xrange(opt.cycles):
92 for n in xrange(opt.number):
97 bin = _helpers.random_sha()
99 # technically, a randomly generated object id might exist.
100 # but the likelihood of that is the likelihood of finding
101 # a collision in sha-1 by accident, which is so unlikely that
103 assert(not m.exists(bin))
104 report((c+1)*opt.number)
106 if bloom._total_searches:
107 print ('bloom: %d objects searched in %d steps: avg %.3f steps/object'
108 % (bloom._total_searches, bloom._total_steps,
109 bloom._total_steps*1.0/bloom._total_searches))
110 if midx._total_searches:
111 print ('midx: %d objects searched in %d steps: avg %.3f steps/object'
112 % (midx._total_searches, midx._total_steps,
113 midx._total_steps*1.0/midx._total_searches))
114 if git._total_searches:
115 print ('idx: %d objects searched in %d steps: avg %.3f steps/object'
116 % (git._total_searches, git._total_steps,
117 git._total_steps*1.0/git._total_searches))
118 print 'Total time: %.3fs' % (time.time() - start)