From 70f51087b9f1003ba0de11e0325ddba3b3dc2c79 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 27 Jun 2019 09:26:16 +0200 Subject: [PATCH] Move conversion logic to ctf module --- .../tracetools_analysis/conversion/ctf.py | 19 +++++++++++++++++-- .../tracetools_analysis/convert.py | 12 +++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tracetools_analysis/tracetools_analysis/conversion/ctf.py b/tracetools_analysis/tracetools_analysis/conversion/ctf.py index 6ba3db9..c2927db 100644 --- a/tracetools_analysis/tracetools_analysis/conversion/ctf.py +++ b/tracetools_analysis/tracetools_analysis/conversion/ctf.py @@ -21,9 +21,9 @@ from tracetools_read import utils def ctf_to_pickle(trace_directory: str, target: Pickler) -> int: """ - Load CTF trace and convert to a pickle file. + Load CTF trace, convert events, and dump to a pickle file. - :param trace_directory: the main/top trace directory + :param trace_directory: the trace directory :param target: the target pickle file to write to :return: the number of events written """ @@ -51,3 +51,18 @@ def ctf_to_pickle(trace_directory: str, target: Pickler) -> int: count_written += 1 return count_written + + +def convert(trace_directory: str, pickle_target_path: str) -> int: + """ + Convert CTF trace to pickle file. + + :param trace_directory: the trace directory + :param pickle_target_path: the path to the pickle file that will be created + :return: the number of events written to the pickle file + """ + with open(pickle_target_path, 'wb') as f: + p = Pickler(f, protocol=4) + count = ctf_to_pickle(trace_directory, p) + + return count diff --git a/tracetools_analysis/tracetools_analysis/convert.py b/tracetools_analysis/tracetools_analysis/convert.py index cbd6ebc..d282c55 100644 --- a/tracetools_analysis/tracetools_analysis/convert.py +++ b/tracetools_analysis/tracetools_analysis/convert.py @@ -25,7 +25,7 @@ from tracetools_analysis.conversion import ctf def parse_args(): parser = argparse.ArgumentParser(description='Convert CTF trace data to a pickle file.') parser.add_argument('trace_directory', help='the path to the main CTF trace directory') - parser.add_argument('pickle_file', help='the target pickle file to generate') + parser.add_argument('pickle_path', help='the path to the target pickle file to generate') return parser.parse_args() @@ -33,11 +33,9 @@ def main(): args = parse_args() trace_directory = args.trace_directory - pickle_target_file = args.pickle_file + pickle_target_path = args.pickle_path start_time = time.time() - with open(pickle_target_file, 'wb') as f: - p = Pickler(f, protocol=4) - count = ctf.ctf_to_pickle(trace_directory, p) - time_diff = time.time() - start_time - print(f'converted {count} events in {time_diff * 1000:.2f} ms') + count = ctf.convert(trace_directory, pickle_target_path) + time_diff = time.time() - start_time + print(f'converted {count} events in {time_diff * 1000:.2f} ms')