This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 524cb33729 tools/minudumpserver: support auto parse log file feature 524cb33729 is described below commit 524cb33729c4b9b47870e7add9a1b25f41116bb4 Author: xinbingnan <xinbing...@xiaomi.com> AuthorDate: Tue Sep 12 18:21:40 2023 +0800 tools/minudumpserver: support auto parse log file feature VELAPLATFO-16476 1. support to extract log and list all possible dumps from a full log file Signed-off-by: xinbingnan <xinbing...@xiaomi.com> --- tools/minidumpserver.py | 60 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/tools/minidumpserver.py b/tools/minidumpserver.py index 027039b173..82186582a3 100755 --- a/tools/minidumpserver.py +++ b/tools/minidumpserver.py @@ -22,6 +22,7 @@ import binascii import logging import os import re +import shutil import socket import struct import sys @@ -286,7 +287,7 @@ class DumpELFFile: class DumpLogFile: - def __init__(self, logfile: str): + def __init__(self, logfile): self.logfile = logfile self.registers = [] self.__memories = list() @@ -350,8 +351,11 @@ class DumpLogFile: data = bytes() start = 0 - with open(self.logfile, "r") as f: - lines = f.readlines() + if isinstance(self.logfile, list): + lines = self.logfile + else: + with open(self.logfile, "r") as f: + lines = f.readlines() for line_num, line in enumerate(lines): if line == "": @@ -614,6 +618,52 @@ def config_log(debug): logging.basicConfig(format="[%(levelname)s][%(name)s] %(message)s") +def auto_parse_log_file(logfile): + with open(logfile, errors="ignore") as f: + dumps = [] + tmp_dmp = [] + start = False + for line in f.readlines(): + line = line.strip() + if ( + "up_dump_register" in line + or "dump_stack" in line + or "stack_dump" in line + ): + start = True + else: + if start: + start = False + dumps.append(tmp_dmp) + tmp_dmp = [] + if start: + tmp_dmp.append(line) + + if start: + dumps.append(tmp_dmp) + + terminal_width, _ = shutil.get_terminal_size() + terminal_width = max(terminal_width - 4, 0) + + def get_one_line(lines): + return " ".join(lines[:2])[:terminal_width] + + if len(dumps) == 0: + logger.error(f"Cannot find any dump in {logfile}, exiting...") + sys.exit(1) + + if len(dumps) == 1: + return dumps[0] + + for i in range(len(dumps)): + print(f"{i}: {get_one_line(dumps[i])}") + + index_input = input("Dump number[0]: ").strip() + if index_input == "": + index_input = 0 + return dumps[int(index_input)] + + def main(args): if not os.path.isfile(args.elffile): logger.error(f"Cannot find file {args.elffile}, exiting...") @@ -625,7 +675,9 @@ def main(args): config_log(args.debug) - log = DumpLogFile(args.logfile) + res = auto_parse_log_file(args.logfile) + + log = DumpLogFile(res) log.parse(args.arch) elf = DumpELFFile(args.elffile) elf.parse()