summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extract/src/memento.py')
-rwxr-xr-xextract/src/memento.py39
1 files changed, 34 insertions, 5 deletions
diff --git a/extract/src/memento.py b/extract/src/memento.py
index 987cd4fd..55171e39 100755
--- a/extract/src/memento.py
+++ b/extract/src/memento.py
@@ -3,20 +3,29 @@
'''
Post-processor for Memento.
+Usage:
+ memento.py <args> [<command> ...]
+
Args:
-q <quiet>
Controls how often we output 'Memory squeezing @ ...' lines. E.g. '-q
10' outputs for multiples of 10.
+
+If <command> is specified we run it and look at the output. Otherwise we assume
+that Memento output is available on our stdin.
'''
import os
import re
+import subprocess
import sys
def main():
quiet = 1
+ quiet_next = 0
out_raw = None
+ command = None
args = iter(sys.argv[1:])
while 1:
try:
@@ -29,15 +38,32 @@ def main():
out_raw = open(next(args), 'w')
elif arg == '-q':
quiet = int(next(args))
- else:
+ elif arg.startswith('-'):
raise Exception(f'unrecognised arg: {arg}')
+ else:
+ command = arg
+ for a in args:
+ command += f' {a}'
+
+ if command:
+ print(f'Running: {command}')
+ child = subprocess.Popen(
+ command,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ shell=True,
+ text=True,
+ )
+ stdin = child.stdout
+ else:
+ stdin = sys.stdin
openbsd = os.uname()[0] == 'OpenBSD'
n = None
segv = 0
leaks = 0
lines = []
- for line in sys.stdin:
+ for line in stdin:
if out_raw:
out_raw.write(line)
m = re.match('^Memory squeezing @ ([0-9]+)( complete)?', line)
@@ -45,7 +71,7 @@ def main():
if not m.group(2):
# Start of squeeze.
- if not openbsd:
+ if 0 and not openbsd:
# Looks like memento's forked processes might terminate
# before they get to output the 'Memory squeezing @ <N>
# complete' line.
@@ -53,9 +79,10 @@ def main():
assert n is None, f'n={n} line={line!r}'
n = int(m.group(1))
- if n % quiet == 0:
- sys.stdout.write(line)
+ if n >= quiet_next:
+ sys.stdout.write(f'quiet_next={quiet_next!r} n={n!r}: {line}')
sys.stdout.flush()
+ quiet_next = (n + quiet) // quiet * quiet
else:
# End of squeeze.
assert n == int(m.group(1))
@@ -66,6 +93,8 @@ def main():
if l.endswith('\n'):
l = l[:-1]
print(f' {l}')
+ if command:
+ print(f'Examine with: MEMENTO_FAILAT={n} {command}')
lines = []
segv = 0
leaks = 0