summaryrefslogtreecommitdiff
path: root/toolbin/squeeze2text.py
diff options
context:
space:
mode:
authorJulian Smith <jules@op59.net>2020-02-19 07:10:40 +0000
committerJulian Smith <jules@op59.net>2020-02-20 14:40:04 +0000
commit075abaaa9ffa03af26bed1a32d3e5114511ee786 (patch)
tree8c3e25bb901fdee78d6f42e81c1d922df0db47a8 /toolbin/squeeze2text.py
parentfbcf5865f688201fba239c5dde0078e6733538c4 (diff)
downloadghostpdl-075abaaa9ffa03af26bed1a32d3e5114511ee786.tar.gz
Added toolbin/squeeze2text.py, for processing output from MEMENTO_SQUEEZEAT=...
An alternative to squeeze2html.pl, outputing just summary information.
Diffstat (limited to 'toolbin/squeeze2text.py')
-rwxr-xr-xtoolbin/squeeze2text.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/toolbin/squeeze2text.py b/toolbin/squeeze2text.py
new file mode 100755
index 000000000..89e4db43b
--- /dev/null
+++ b/toolbin/squeeze2text.py
@@ -0,0 +1,77 @@
+#!/usr/bin/python3
+
+'''
+Reads memento squeeze output from stdin, and writes brief info to stdout or
+file.
+
+E.g.:
+ MEMENTO_SQUEEZEAT=1 ./membin/gpdl -sDEVICE=bit -o /dev/null examples/tiger.eps 2>&1 | toolbin/squeeze2text.py -o squeeze.txt
+
+Args:
+
+ -a <filename>
+ Append output to <filename>. Write log to stdout.
+ -o <filename>
+ Write output to <filename>. Write log to stdout.
+ -p <N>
+ Write progress information to log, every <N> blocks.
+
+If -o is not specified, we write output to stdout, and log to stderr.
+
+If -p is not specified, default is -p 1.
+
+'''
+
+import io
+import re
+import sys
+
+if __name__ == '__main__':
+
+ verbose = False
+ progress_n = 1
+ num_segv = 0
+ num_leak = 0
+ out = sys.stdout
+ log = sys.stderr
+
+ args = iter( sys.argv[1:])
+ while 1:
+ try:
+ arg = next(args)
+ except StopIteration:
+ break
+ if arg == '-p':
+ progress_n = int( next(args))
+ elif arg == '-a':
+ filename = next(args)
+ out = open( filename, 'a')
+ log = sys.stdout
+ elif arg == '-o':
+ filename = next(args)
+ out = open( filename, 'w')
+ log = sys.stdout
+ else:
+ raise Exception( 'unrecognised arg: %r' % arg)
+
+ # Use latin_1 encoding to ensure we can read all 8-bit bytes from stdin as
+ # characters.
+ f = io.TextIOWrapper( sys.stdin.buffer, encoding='latin_1')
+ for line in f:
+ m = re.match( '^Memory squeezing @ ([0-9]+)$', line)
+ if m:
+ memento_n = int( m.group(1))
+ if memento_n % progress_n == 0:
+ print( 'memento_n=%s. num_segv=%s num_leak=%s' % (
+ memento_n,
+ num_segv,
+ num_leak
+ ),
+ file=log,
+ )
+ if line.startswith( 'SEGV at:'):
+ num_segv += 1
+ print( 'memento_n=%s: segv' % memento_n, file=out)
+ elif line.startswith( 'Allocated blocks'):
+ num_leak += 1
+ print( 'memento_n=%s: leak' % memento_n, file=out)