2 import sys, re, struct, time, resource
3 from bup import git, 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 k,v = re.split(r':\s*', line.strip(), 1)
26 last = last_u = last_s = start = 0
28 global last, last_u, last_s, start
29 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
30 ru = resource.getrusage(resource.RUSAGE_SELF)
32 rss = int(ru.ru_maxrss/1024)
34 rss = linux_memstat().get('VmRSS', '??')
37 int((ru.ru_utime - last_u) * 1000),
38 int((ru.ru_stime - last_s) * 1000),
39 int((now - last) * 1000)]
40 fmt = '%9s ' + ('%10s ' * len(fields))
42 print fmt % tuple([count] + fields)
45 print fmt % tuple([''] + headers)
48 # don't include time to run report() in usage counts
49 ru = resource.getrusage(resource.RUSAGE_SELF)
56 bup memtest [-n elements] [-c cycles]
58 n,number= number of objects per cycle [10000]
59 c,cycles= number of cycles to run [100]
60 ignore-midx ignore .midx files, use only .idx files
61 existing test with existing objects instead of fake ones
63 o = options.Options('bup memtest', optspec)
64 (opt, flags, extra) = o.parse(sys.argv[1:])
67 o.fatal('no arguments expected')
69 git.ignore_midx = opt.ignore_midx
71 git.check_repo_or_die()
72 m = git.PackIdxList(git.repo('objects/pack'))
75 _helpers.random_partial_sha()
83 objit = iter(foreverit(m))
85 for c in xrange(opt.cycles):
86 for n in xrange(opt.number):
91 bin = _helpers.random_partial_sha()
93 # technically, a randomly generated object id might exist.
94 # but the likelihood of that is the likelihood of finding
95 # a collision in sha-1 by accident, which is so unlikely that
97 assert(not m.exists(bin))
98 report((c+1)*opt.number)
100 print ('%d objects searched in %d steps: avg %.3f steps/object'
101 % (git._total_searches, git._total_steps,
102 git._total_steps*1.0/git._total_searches))
103 print 'Total time: %.3fs' % (time.time() - start)