Move conversion logic to ctf module

This commit is contained in:
Christophe Bedard 2019-06-27 09:26:16 +02:00
parent 1b7c909fff
commit 70f51087b9
2 changed files with 22 additions and 9 deletions

View file

@ -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

View file

@ -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')