From: Philipp Gesang Date: Wed, 22 Apr 2020 10:01:38 +0000 (+0200) Subject: add utility for profiling memory usage of encryption X-Git-Tag: v2.2~1^2~2 X-Git-Url: http://developer.intra2net.com/git/?p=python-delta-tar;a=commitdiff_plain;h=93966bd339f93d71929a3eb066b02856712d3643 add utility for profiling memory usage of encryption --- diff --git a/deltatar/memory-profile.py b/deltatar/memory-profile.py new file mode 100644 index 0000000..b1449f5 --- /dev/null +++ b/deltatar/memory-profile.py @@ -0,0 +1,44 @@ +import binascii +import sys + +import crypto + +FIXED_FILE = "no-such-file" +FIXED_PASS = "swordfish" +FIXED_NACL = binascii.unhexlify (b"00112233445566778899aabbccddeeff") + +def noise (*a, **b): + print (file=sys.stderr, *a, **b) + + +def create_objects (n): + """ + Repeatedly apply the .next () method of the Encrypt handle for profiling. + """ + + enc = crypto.Encrypt (1, 1, password=FIXED_PASS, nacl=FIXED_NACL) + + for i in range (n): + _ = enc.next (FIXED_FILE) + + noise ("accumulated %d ivs" % len (enc.get_used_ivs ())) + + noise ("") + noise ("** to terminate **") + _ = sys.stdin.read () # halt here so we get a chance to inspec /proc/$$/status + + return 0 + + +def main (argv): + if len (argv) != 2: + noise ("number of iterations required!") + return 42 + + n = argv [1] + n = int (n) + + return create_objects (n) + +if __name__ == "__main__": + sys.exit (main (sys.argv))