Commit 479d7ee6 authored by Christophe Bedard's avatar Christophe Bedard

Make process command convert directory if necessary

parent 7b19b9e0
Pipeline #88442258 passed with stage
in 1 minute and 24 seconds
......@@ -22,6 +22,9 @@ import time
from tracetools_analysis.conversion import ctf
def parse_args():
parser = argparse.ArgumentParser(
description='Convert CTF trace data to a file.')
......@@ -30,22 +33,30 @@ def parse_args():
help='the path to the main CTF trace directory')
'-o', '--output-file-path', dest='output_file_path',
help='the path to the output file to generate (default: $trace_directory/converted)')
help='the path to the output file to generate '
f'(default: $trace_directory/{DEFAULT_CONVERT_FILE_NAME})')
args = parser.parse_args()
if args.output_file_path is None:
args.output_file_path = os.path.join(args.trace_directory, 'converted')
args.output_file_path = os.path.join(args.trace_directory, DEFAULT_CONVERT_FILE_NAME)
return args
def main():
args = parse_args()
trace_directory = args.trace_directory
output_file_path = args.output_file_path
def convert(
trace_directory: str,
output_file_path: str,
) -> None:
print(f'importing trace directory: {trace_directory}')
start_time = time.time()
count = ctf.convert(trace_directory, output_file_path)
time_diff = time.time() - start_time
print(f'converted {count} events in {time_diff * 1000:.2f} ms')
print(f'output written to: {output_file_path}')
def main():
args = parse_args()
trace_directory = args.trace_directory
output_file_path = args.output_file_path
convert(trace_directory, output_file_path)
......@@ -16,28 +16,55 @@
"""Entrypoint/script to process events from a converted file to build a ROS model."""
import argparse
import os
import sys
import time
from tracetools_analysis.convert import convert
from tracetools_analysis.convert import DEFAULT_CONVERT_FILE_NAME
from tracetools_analysis.loading import load_file
from tracetools_analysis.processor.ros2 import Ros2Handler
from tracetools_read.trace import is_trace_directory
def parse_args():
parser = argparse.ArgumentParser(description='Process a file converted from a trace '
'directory and output model data.')
help='the converted file to import')
help='the path to a converted file to import, '
'or the path to a CTF directory to convert and process')
return parser.parse_args()
def main():
args = parse_args()
output_file_path = args.output_file_path
input_path = args.input_path
start_time = time.time()
events = load_file(output_file_path)
# Check if not a file
if not os.path.isfile(input_path):
# Might be a trace directory
# Check if there is a converted file
prospective_converted_file = os.path.join(input_path, DEFAULT_CONVERT_FILE_NAME)
if os.path.isfile(prospective_converted_file):
# Use that as the converted input file
print('found converted file')
input_path = prospective_converted_file
# Check if it is a trace directory
# Result could be unexpected because it will look for trace directories recursively
if is_trace_directory(input_path):
# Convert trace directory first to create converted file
convert(input_path, prospective_converted_file)
input_path = prospective_converted_file
# We cannot do anything
print('cannot find either a trace directory or a converted file', file=sys.stderr)
return 1
events = load_file(input_path)
ros2_handler = Ros2Handler.process(events)
time_diff = time.time() - start_time
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment