]> arthur.barton.de Git - bup.git/blob - cmd/memtest-cmd.py
745550c3cd483f397ba029669c63a63f305acaf4
[bup.git] / cmd / memtest-cmd.py
1 #!/usr/bin/env python
2 import sys, re, struct, mmap
3 from bup import git, options
4 from bup.helpers import *
5
6 handle_ctrl_c()
7
8 def s_from_bytes(bytes):
9     clist = [chr(b) for b in bytes]
10     return ''.join(clist)
11
12
13 def report(count):
14     fields = ['VmSize', 'VmRSS', 'VmData', 'VmStk']
15     d = {}
16     for line in open('/proc/self/status').readlines():
17         l = re.split(r':\s*', line.strip(), 1)
18         d[l[0]] = l[1]
19     if count >= 0:
20         e1 = count
21         fields = [d[k] for k in fields]
22     else:
23         e1 = ''
24     print ('%9s  ' + ('%10s ' * len(fields))) % tuple([e1] + fields)
25     sys.stdout.flush()
26
27
28 optspec = """
29 bup memtest [-n elements] [-c cycles]
30 --
31 n,number=  number of objects per cycle [10000]
32 c,cycles=  number of cycles to run [100]
33 ignore-midx  ignore .midx files, use only .idx files
34 """
35 o = options.Options('bup memtest', optspec)
36 (opt, flags, extra) = o.parse(sys.argv[1:])
37
38 if extra:
39     o.fatal('no arguments expected')
40
41 git.ignore_midx = opt.ignore_midx
42
43 git.check_repo_or_die()
44 m = git.PackIdxList(git.repo('objects/pack'))
45
46 report(-1)
47 f = open('/dev/urandom')
48 a = mmap.mmap(-1, 20)
49 report(0)
50 for c in xrange(opt.cycles):
51     for n in xrange(opt.number):
52         b = f.read(3)
53         if 0:
54             bytes = list(struct.unpack('!BBB', b)) + [0]*17
55             bytes[2] &= 0xf0
56             bin = struct.pack('!20s', s_from_bytes(bytes))
57         else:
58             a[0:2] = b[0:2]
59             a[2] = chr(ord(b[2]) & 0xf0)
60             bin = str(a[0:20])
61         #print bin.encode('hex')
62         m.exists(bin)
63     report((c+1)*opt.number)