add utility for profiling memory usage of encryption
[python-delta-tar] / deltatar / memory-profile.py
CommitLineData
93966bd3
PG
1import binascii
2import sys
3
4import crypto
5
6FIXED_FILE = "no-such-file"
7FIXED_PASS = "swordfish"
8FIXED_NACL = binascii.unhexlify (b"00112233445566778899aabbccddeeff")
9
10def noise (*a, **b):
11 print (file=sys.stderr, *a, **b)
12
13
14def create_objects (n):
15 """
16 Repeatedly apply the .next () method of the Encrypt handle for profiling.
17 """
18
19 enc = crypto.Encrypt (1, 1, password=FIXED_PASS, nacl=FIXED_NACL)
20
21 for i in range (n):
22 _ = enc.next (FIXED_FILE)
23
24 noise ("accumulated %d ivs" % len (enc.get_used_ivs ()))
25
26 noise ("")
27 noise ("** <C-d> to terminate **")
28 _ = sys.stdin.read () # halt here so we get a chance to inspec /proc/$$/status
29
30 return 0
31
32
33def main (argv):
34 if len (argv) != 2:
35 noise ("number of iterations required!")
36 return 42
37
38 n = argv [1]
39 n = int (n)
40
41 return create_objects (n)
42
43if __name__ == "__main__":
44 sys.exit (main (sys.argv))