mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
style: format python files with isort and double-quote-string-fixer
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import struct
|
||||
import sys
|
||||
|
||||
import elftools.elf.elffile as elffile
|
||||
import espytrace.apptrace as apptrace
|
||||
|
||||
@@ -21,7 +23,7 @@ class ESPLogTraceRecord(object):
|
||||
self.args = log_args
|
||||
|
||||
def __repr__(self):
|
||||
return "fmt_addr = 0x%x, args = %d/%s" % (self.fmt_addr, len(self.args), self.args)
|
||||
return 'fmt_addr = 0x%x, args = %d/%s' % (self.fmt_addr, len(self.args), self.args)
|
||||
|
||||
|
||||
def logtrace_parse(fname):
|
||||
@@ -32,40 +34,40 @@ def logtrace_parse(fname):
|
||||
try:
|
||||
ftrc = open(fname, 'rb')
|
||||
except OSError as e:
|
||||
raise ESPLogTraceParserError("Failed to open trace file (%s)!" % e)
|
||||
raise ESPLogTraceParserError('Failed to open trace file (%s)!' % e)
|
||||
# data_ok = True
|
||||
while True:
|
||||
# read args num and format str addr
|
||||
try:
|
||||
trc_buf = ftrc.read(ESP32_LOGTRACE_HDR_SZ)
|
||||
except IOError as e:
|
||||
raise ESPLogTraceParserError("Failed to read log record header (%s)!" % e)
|
||||
raise ESPLogTraceParserError('Failed to read log record header (%s)!' % e)
|
||||
if len(trc_buf) < ESP32_LOGTRACE_HDR_SZ:
|
||||
# print "EOF"
|
||||
if len(trc_buf) > 0:
|
||||
print("Unprocessed %d bytes of log record header!" % len(trc_buf))
|
||||
print('Unprocessed %d bytes of log record header!' % len(trc_buf))
|
||||
# data_ok = False
|
||||
break
|
||||
try:
|
||||
nargs,fmt_addr = struct.unpack(ESP32_LOGTRACE_HDR_FMT, trc_buf)
|
||||
except struct.error as e:
|
||||
raise ESPLogTraceParserError("Failed to unpack log record header (%s)!" % e)
|
||||
raise ESPLogTraceParserError('Failed to unpack log record header (%s)!' % e)
|
||||
# read args
|
||||
args_sz = struct.calcsize('<%sL' % nargs)
|
||||
try:
|
||||
trc_buf = ftrc.read(args_sz)
|
||||
except IOError as e:
|
||||
raise ESPLogTraceParserError("Failed to read log record args (%s)!" % e)
|
||||
raise ESPLogTraceParserError('Failed to read log record args (%s)!' % e)
|
||||
if len(trc_buf) < args_sz:
|
||||
# print("EOF")
|
||||
if len(trc_buf) > 0:
|
||||
print("Unprocessed %d bytes of log record args!" % len(trc_buf))
|
||||
print('Unprocessed %d bytes of log record args!' % len(trc_buf))
|
||||
# data_ok = False
|
||||
break
|
||||
try:
|
||||
log_args = struct.unpack('<%sL' % nargs, trc_buf)
|
||||
except struct.error as e:
|
||||
raise ESPLogTraceParserError("Failed to unpack log record args (%s)!" % e)
|
||||
raise ESPLogTraceParserError('Failed to unpack log record args (%s)!' % e)
|
||||
# print(log_args)
|
||||
recs.append(ESPLogTraceRecord(fmt_addr, list(log_args)))
|
||||
|
||||
@@ -78,7 +80,7 @@ def logtrace_formated_print(recs, elfname, no_err):
|
||||
try:
|
||||
felf = elffile.ELFFile(open(elfname, 'rb'))
|
||||
except OSError as e:
|
||||
raise ESPLogTraceParserError("Failed to open ELF file (%s)!" % e)
|
||||
raise ESPLogTraceParserError('Failed to open ELF file (%s)!' % e)
|
||||
|
||||
for lrec in recs:
|
||||
fmt_str = apptrace.get_str_from_elf(felf, lrec.fmt_addr)
|
||||
@@ -104,8 +106,8 @@ def logtrace_formated_print(recs, elfname, no_err):
|
||||
pass
|
||||
except Exception as e:
|
||||
if not no_err:
|
||||
print("Print error (%s)" % e)
|
||||
print("\nFmt = {%s}, args = %d/%s" % (fmt_str, len(lrec.args), lrec.args))
|
||||
print('Print error (%s)' % e)
|
||||
print('\nFmt = {%s}, args = %d/%s' % (fmt_str, len(lrec.args), lrec.args))
|
||||
felf.stream.close()
|
||||
|
||||
|
||||
@@ -123,21 +125,21 @@ def main():
|
||||
try:
|
||||
print("Parse trace file '%s'..." % args.trace_file)
|
||||
lrecs = logtrace_parse(args.trace_file)
|
||||
print("Parsing completed.")
|
||||
print('Parsing completed.')
|
||||
except ESPLogTraceParserError as e:
|
||||
print("Failed to parse log trace (%s)!" % e)
|
||||
print('Failed to parse log trace (%s)!' % e)
|
||||
sys.exit(2)
|
||||
# print recs
|
||||
# get format strings and print info
|
||||
print("====================================================================")
|
||||
print('====================================================================')
|
||||
try:
|
||||
logtrace_formated_print(lrecs, args.elf_file, args.no_errors)
|
||||
except ESPLogTraceParserError as e:
|
||||
print("Failed to print log trace (%s)!" % e)
|
||||
print('Failed to print log trace (%s)!' % e)
|
||||
sys.exit(2)
|
||||
print("\n====================================================================\n")
|
||||
print('\n====================================================================\n')
|
||||
|
||||
print("Log records count: %d" % len(lrecs))
|
||||
print('Log records count: %d' % len(lrecs))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user