add utility for profiling memory usage of encryption
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Wed, 22 Apr 2020 10:01:38 +0000 (12:01 +0200)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 24 Apr 2020 06:55:25 +0000 (08:55 +0200)
deltatar/memory-profile.py [new file with mode: 0644]

diff --git a/deltatar/memory-profile.py b/deltatar/memory-profile.py
new file mode 100644 (file)
index 0000000..b1449f5
--- /dev/null
@@ -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 ("** <C-d> 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))