about summary refs log tree commit diff stats
path: root/tools/convert.py
diff options
context:
space:
mode:
authorTheofilos Augoustis <theofilos.augoustis@gmail.com>2025-02-25 15:48:20 +0100
committerTheofilos Augoustis <theofilos.augoustis@gmail.com>2025-02-25 15:48:20 +0100
commit849e5a6ec6e0246b5dde1fb2583aa13ed288e9c1 (patch)
tree0596e7ffdd2b18a1e7977a49b55afb6f46976f6a /tools/convert.py
parented536f04a716d585ce54bab0413f57aba1284b91 (diff)
parenta514b34d6f708ee80c4f0df91fefa9871d87ad39 (diff)
downloadfocaccia-849e5a6ec6e0246b5dde1fb2583aa13ed288e9c1.tar.gz
focaccia-849e5a6ec6e0246b5dde1fb2583aa13ed288e9c1.zip
Merge branch 'ta/develop'
Diffstat (limited to 'tools/convert.py')
-rwxr-xr-xtools/convert.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/convert.py b/tools/convert.py
new file mode 100755
index 0000000..f21a2fa
--- /dev/null
+++ b/tools/convert.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import argparse
+import sys
+
+import focaccia.parser as parser
+from focaccia.arch import supported_architectures
+
+convert_funcs = {
+    'qemu':     parser.parse_qemu,
+    'arancini': parser.parse_arancini,
+}
+
+def main():
+    """Main."""
+    prog = argparse.ArgumentParser()
+    prog.description = 'Convert other programs\' logs to focaccia\'s log format.'
+    prog.add_argument('file', help='The log to convert.')
+    prog.add_argument('--type',
+                      required=True,
+                      choices=convert_funcs.keys(),
+                      help='The log type of `file`')
+    prog.add_argument('--output', '-o',
+                      help='Output file (default is stdout)')
+    prog.add_argument('--arch',
+                      default='x86_64',
+                      choices=supported_architectures.keys(),
+                      help='Processor architecture of input log (default is x86)')
+    args = prog.parse_args()
+
+    # Parse arancini log
+    arch = supported_architectures[args.arch]
+    parse_log = convert_funcs[args.type]
+    with open(args.file, 'r') as in_file:
+        try:
+            snapshots = parse_log(in_file, arch)
+        except parser.ParseError as err:
+            print(f'Parse error: {err}. Exiting.', file=sys.stderr)
+            exit(1)
+
+    # Write log in focaccia's format
+    if args.output:
+        with open(args.output, 'w') as out_file:
+            parser.serialize_snapshots(snapshots, out_file)
+    else:
+        parser.serialize_snapshots(snapshots, sys.stdout)
+
+if __name__ == '__main__':
+    main()