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