From 075abaaa9ffa03af26bed1a32d3e5114511ee786 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Wed, 19 Feb 2020 07:10:40 +0000 Subject: Added toolbin/squeeze2text.py, for processing output from MEMENTO_SQUEEZEAT=... An alternative to squeeze2html.pl, outputing just summary information. --- toolbin/squeeze2text.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 toolbin/squeeze2text.py (limited to 'toolbin/squeeze2text.py') 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 + Append output to . Write log to stdout. + -o + Write output to . Write log to stdout. + -p + Write progress information to log, every 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) -- cgit v1.2.1