From 186b7e157d37180323ba4f14436ea0ef9a2e25ea Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Fri, 4 Apr 2025 13:21:08 -0400 Subject: [PATCH 1/2] Added common helper function to define log search arguments. --- .../fusion_engine_client/analysis/analyzer.py | 18 ++--------------- .../applications/p1_print.py | 20 +++---------------- python/fusion_engine_client/utils/log.py | 19 ++++++++++++++++++ 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/python/fusion_engine_client/analysis/analyzer.py b/python/fusion_engine_client/analysis/analyzer.py index 83ba6750..ceb781b1 100755 --- a/python/fusion_engine_client/analysis/analyzer.py +++ b/python/fusion_engine_client/analysis/analyzer.py @@ -28,7 +28,7 @@ from .data_loader import DataLoader, TimeRange from ..utils import trace as logging from ..utils.argument_parser import ArgumentParser, ExtendedBooleanAction, TriStateBooleanAction, CSVAction -from ..utils.log import locate_log, DEFAULT_LOG_BASE_DIR +from ..utils.log import define_cli_arguments as define_log_search_arguments, locate_log from ..utils.numpy_utils import find_first from ..utils.trace import HighlightFormatter @@ -2929,21 +2929,7 @@ def main(args=None): "unless an 'abs' type is specified or --absolute-time is set.") log_group = parser.add_argument_group('Input File/Log Control') - log_group.add_argument( - '--ignore-index', action=ExtendedBooleanAction, - help="If set, do not load the .p1i index file corresponding with the .p1log data file. If specified and a " - ".p1i file does not exist, do not generate one. Otherwise, a .p1i file will be created automatically to " - "improve data read speed in the future.") - log_group.add_argument( - '--log-base-dir', metavar='DIR', default=DEFAULT_LOG_BASE_DIR, - help="The base directory containing FusionEngine logs to be searched if a log pattern is specified.") - log_group.add_argument( - 'log', - help="The log to be read. May be one of:\n" - "- The path to a .p1log file or a file containing FusionEngine messages and other content\n" - "- The path to a FusionEngine log directory\n" - "- A pattern matching a FusionEngine log directory under the specified base directory " - "(see find_fusion_engine_log() and --log-base-dir)") + define_log_search_arguments(log_group) output_group = parser.add_argument_group('Output Control') output_group.add_argument( diff --git a/python/fusion_engine_client/applications/p1_print.py b/python/fusion_engine_client/applications/p1_print.py index 30977ce7..1a5bb173 100755 --- a/python/fusion_engine_client/applications/p1_print.py +++ b/python/fusion_engine_client/applications/p1_print.py @@ -10,7 +10,7 @@ from ..parsers import MixedLogReader from ..utils import trace as logging from ..utils.argument_parser import ArgumentParser, ExtendedBooleanAction, CSVAction -from ..utils.log import locate_log, DEFAULT_LOG_BASE_DIR +from ..utils.log import define_cli_arguments as define_log_search_arguments, locate_log from ..utils.print_utils import DeviceSummary, add_print_format_argument, print_message, print_summary_table from ..utils.time_range import TimeRange from ..utils.trace import HighlightFormatter, BrokenPipeStreamHandler @@ -65,25 +65,11 @@ def main(): parser.add_argument('-v', '--verbose', action='count', default=0, help="Print verbose/trace debugging messages.") - log_parser = parser.add_argument_group('Log Control') - log_parser.add_argument( - '--ignore-index', action='store_true', - help="If set, do not load the .p1i index file corresponding with the .p1log data file. If specified and a .p1i " - "file does not exist, do not generate one. Otherwise, a .p1i file will be created automatically to " - "improve data read speed in the future.") - log_parser.add_argument( - '--log-base-dir', metavar='DIR', default=DEFAULT_LOG_BASE_DIR, - help="The base directory containing FusionEngine logs to be searched if a log pattern is specified.") + log_parser = parser.add_argument_group('Input File/Log Control') + define_log_search_arguments(log_parser) log_parser.add_argument( '--progress', action='store_true', help="Print file read progress to the console periodically.") - log_parser.add_argument( - 'log', - help="The log to be read. May be one of:\n" - "- The path to a .p1log file or a file containing FusionEngine messages and other content\n" - "- The path to a FusionEngine log directory\n" - "- A pattern matching a FusionEngine log directory under the specified base directory " - "(see find_fusion_engine_log() and --log-base-dir)") options = parser.parse_args() diff --git a/python/fusion_engine_client/utils/log.py b/python/fusion_engine_client/utils/log.py index 27bae896..87c3b0ae 100644 --- a/python/fusion_engine_client/utils/log.py +++ b/python/fusion_engine_client/utils/log.py @@ -7,6 +7,7 @@ from ..messages import MessageType from ..parsers.file_index import FileIndexBuilder, FileIndex from ..parsers.mixed_log_reader import MixedLogReader +from ..utils.argument_parser import ExtendedBooleanAction _logger = logging.getLogger('point_one.utils.log') @@ -44,6 +45,24 @@ DEFAULT_LOG_BASE_DIR = os.path.expanduser("~/point_one/logs") +def define_cli_arguments(parser_group): + parser_group.add_argument( + '--ignore-index', action=ExtendedBooleanAction, + help="If set, do not load the .p1i index file corresponding with the .p1log data file. If specified and a " + ".p1i file does not exist, do not generate one. Otherwise, a .p1i file will be created automatically to " + "improve data read speed in the future.") + parser_group.add_argument( + '--log-base-dir', metavar='DIR', default=DEFAULT_LOG_BASE_DIR, + help="The base directory containing FusionEngine logs to be searched if a log pattern is specified.") + parser_group.add_argument( + 'log', + help="The log to be read. May be one of:\n" + "- The path to a .p1log file or a file containing FusionEngine messages and other content\n" + "- The path to a FusionEngine log directory\n" + "- A pattern matching a FusionEngine log directory under the specified base directory " + "(see find_fusion_engine_log() and --log-base-dir)") + + def find_log_by_pattern(pattern, log_base_dir=DEFAULT_LOG_BASE_DIR, allow_multiple=False, skip_empty_files=True, log_test_filenames=(MANIFEST_FILE_NAME,), return_test_file=False): """! From 7dc7e61e361fa11cccbd1e94c30ec0e6c5c26075 Mon Sep 17 00:00:00 2001 From: Adam Shapiro Date: Fri, 4 Apr 2025 16:21:35 -0400 Subject: [PATCH 2/2] Set p1_display output_dir even for non-P1 logs (i.e., bare .p1log files). --- python/fusion_engine_client/analysis/analyzer.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/python/fusion_engine_client/analysis/analyzer.py b/python/fusion_engine_client/analysis/analyzer.py index ceb781b1..a1925d5c 100755 --- a/python/fusion_engine_client/analysis/analyzer.py +++ b/python/fusion_engine_client/analysis/analyzer.py @@ -2968,8 +2968,8 @@ def main(args=None): time_range = None # Locate the input file and set the output directory. - input_path, output_dir, log_id = locate_log(input_path=options.log, log_base_dir=options.log_base_dir, - return_output_dir=True, return_log_id=True) + input_path, log_dir, log_id = locate_log(input_path=options.log, log_base_dir=options.log_base_dir, + return_output_dir=True, return_log_id=True) if input_path is None: # locate_log() will log an error. sys.exit(1) @@ -2980,8 +2980,7 @@ def main(args=None): _logger.info('Loading %s (log ID: %s).' % (input_path, log_id)) if options.output is None: - if log_id is not None: - output_dir = os.path.join(output_dir, 'plot_fusion_engine') + output_dir = os.path.join(log_dir, 'plot_fusion_engine') else: output_dir = options.output