2 import sys, re, struct, mmap, time, resource
3 from bup import git, options
4 from bup.helpers import *
8 def s_from_bytes(bytes):
9 clist = [chr(b) for b in bytes]
16 #fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk', 'ms']
19 f = open('/proc/self/status')
22 log('Warning: %s\n' % e)
26 k,v = re.split(r':\s*', line.strip(), 1)
31 last = last_u = last_s = start = 0
33 global last, last_u, last_s, start
34 headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
35 ru = resource.getrusage(resource.RUSAGE_SELF)
37 rss = int(ru.ru_maxrss/1024)
39 rss = linux_memstat().get('VmRSS', '??')
42 int((ru.ru_utime - last_u) * 1000),
43 int((ru.ru_stime - last_s) * 1000),
44 int((now - last) * 1000)]
45 fmt = '%9s ' + ('%10s ' * len(fields))
47 print fmt % tuple([count] + fields)
50 print fmt % tuple([''] + headers)
53 # don't include time to run report() in usage counts
54 ru = resource.getrusage(resource.RUSAGE_SELF)
61 bup memtest [-n elements] [-c cycles]
63 n,number= number of objects per cycle [10000]
64 c,cycles= number of cycles to run [100]
65 ignore-midx ignore .midx files, use only .idx files
66 existing test with existing objects instead of fake ones
68 o = options.Options('bup memtest', optspec)
69 (opt, flags, extra) = o.parse(sys.argv[1:])
72 o.fatal('no arguments expected')
74 git.ignore_midx = opt.ignore_midx
76 git.check_repo_or_die()
77 m = git.PackIdxList(git.repo('objects/pack'))
80 f = open('/dev/urandom')
89 objit = iter(foreverit(m))
91 for c in xrange(opt.cycles):
92 for n in xrange(opt.number):
99 a[2] = chr(ord(b[2]) & 0xf0)
102 # technically, a randomly generated object id might exist.
103 # but the likelihood of that is the likelihood of finding
104 # a collision in sha-1 by accident, which is so unlikely that
106 assert(not m.exists(bin))
107 report((c+1)*opt.number)
109 print ('%d objects searched in %d steps: avg %.3f steps/object'
110 % (git._total_searches, git._total_steps,
111 git._total_steps*1.0/git._total_searches))
112 print 'Total time: %.3fs' % (time.time() - start)