def setUp(self):
     BaseTracingTestsImpl.setUp(self)
     self.processor = None
     self.trace_ctrl = [{
         'src': '',
         'reader': None,
         'parser': None
     } for i in range(self.cores_num)]
     for i in range(self.cores_num):
         # create parser
         try:
             parser = sysview.SysViewMultiTraceDataParser(
                 print_events=False, core_id=i)
             parser.add_stream_parser(
                 sysview.SysViewTraceDataParser.STREAMID_HEAP,
                 sysview.SysViewHeapTraceDataParser(print_events=False,
                                                    core_id=i))
             parser.add_stream_parser(
                 sysview.SysViewTraceDataParser.STREAMID_LOG,
                 sysview.SysViewLogTraceDataParser(print_events=False,
                                                   core_id=i))
             self.trace_ctrl[i]['parser'] = parser
         except Exception as e:
             traceback.print_exc()
             self.fail("Failed to create data parser ({})!".format(e))
         # create reader with trace source URL
         self.trace_ctrl[i]['src'], self.trace_ctrl[i][
             'reader'] = _create_file_reader()
         if not self.trace_ctrl[i]['reader']:
             if i == 1:
                 self.trace_ctrl[0]['reader'].cleanup()
             self.fail("Failed to create trace reader for core %d!" % i)
 def setUp(self):
     BaseTracingTestsImpl.setUp(self)
     self.processor = None
     self.trace_ctrl = {'src': '', 'reader': None, 'parser': None}
     # create parser
     try:
         parser = sysview.SysViewMultiTraceDataParser(print_events=False)
         parser.add_stream_parser(
             sysview.SysViewTraceDataParser.STREAMID_HEAP,
             sysview.SysViewHeapTraceDataParser(print_events=False))
         parser.add_stream_parser(
             sysview.SysViewTraceDataParser.STREAMID_LOG,
             sysview.SysViewLogTraceDataParser(print_events=False))
         self.trace_ctrl['parser'] = parser
     except Exception as e:
         traceback.print_exc()
         self.fail("Failed to create data parser ({})!".format(e))
     # create reader with trace source URL
     self.trace_ctrl['src'], self.trace_ctrl[
         'reader'] = _create_file_reader()
     if not self.trace_ctrl['reader']:
         self.fail("Failed to create trace reader!")
Beispiel #3
0
def main():

    verbosity_levels = [
        logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO,
        logging.DEBUG
    ]

    parser = argparse.ArgumentParser(
        description='ESP32 SEGGER SystemView Trace Parsing Tool')

    parser.add_argument(
        'trace_sources',
        help='Trace data sources. Format: [file://]/path/to/file.',
        nargs='+',
        type=str)
    parser.add_argument('--elf-file',
                        '-b',
                        help='Path to program ELF file.',
                        type=str,
                        default='')
    parser.add_argument(
        '--tmo',
        '-w',
        help='Data wait timeout in sec. -1: infinite, 0: no wait',
        type=int,
        default=0)
    parser.add_argument('--dump-events',
                        '-d',
                        help='Dump all events.',
                        action='store_true')
    parser.add_argument(
        '--print-events',
        '-p',
        help=
        'Print events of selected types. By default only reports are printed',
        action='store_true')
    parser.add_argument('--include-events',
                        '-i',
                        help='Events types to be included into report.',
                        type=str,
                        choices=['heap', 'log', 'all'],
                        default='all')
    parser.add_argument('--toolchain',
                        '-t',
                        help='Toolchain prefix.',
                        type=str,
                        default='xtensa-esp32-elf-')
    parser.add_argument('--events-map',
                        '-e',
                        help='Events map file.',
                        type=str,
                        default=os.path.join(os.path.dirname(__file__),
                                             'SYSVIEW_FreeRTOS.txt'))
    parser.add_argument('--to-json',
                        '-j',
                        help='Print JSON.',
                        action='store_true',
                        default=False)
    parser.add_argument('--verbose',
                        '-v',
                        help='Verbosity level. Default 1',
                        choices=range(0, len(verbosity_levels)),
                        type=int,
                        default=1)
    args = parser.parse_args()

    def sig_int_handler(signum, frame):
        reader.cleanup()

    signal.signal(signal.SIGINT, sig_int_handler)

    include_events = {'heap': False, 'log': False}
    if args.include_events == 'all':
        for k in include_events:
            include_events[k] = True
    elif args.include_events == 'heap':
        include_events['heap'] = True
    elif args.include_events == 'log':
        include_events['log'] = True

    logging.basicConfig(level=verbosity_levels[args.verbose],
                        format='[%(levelname)s] %(message)s')

    # parse trace files
    parsers = []
    for i, trace_source in enumerate(args.trace_sources):
        try:
            parser = sysview.SysViewMultiTraceDataParser(print_events=False,
                                                         core_id=i)
            if include_events['heap']:
                parser.add_stream_parser(
                    sysview.SysViewTraceDataParser.STREAMID_HEAP,
                    sysview.SysViewHeapTraceDataParser(print_events=False,
                                                       core_id=i))
            if include_events['log']:
                parser.add_stream_parser(
                    sysview.SysViewTraceDataParser.STREAMID_LOG,
                    sysview.SysViewLogTraceDataParser(print_events=False,
                                                      core_id=i))
            parsers.append(parser)
        except Exception as e:
            logging.error("Failed to create data parser (%s)!", e)
            traceback.print_exc()
            sys.exit(2)
        reader = apptrace.reader_create(trace_source, args.tmo)
        if not reader:
            logging.error("Failed to create trace reader!")
            sys.exit(2)
        try:
            # logging.info("Parse trace from '{}'...".format(trace_source))
            logging.info("Parse trace from '%s'...", trace_source)
            sysview.parse_trace(reader, parser, args.events_map)
            logging.info("Parsing completed.")
        except (apptrace.ReaderTimeoutError,
                apptrace.ReaderShutdownRequest) as e:
            logging.info("Stop parsing trace. (%s)", e)
        except Exception as e:
            logging.error("Failed to parse trace (%s)!", e)
            parser.cleanup()
            traceback.print_exc()
            sys.exit(2)
        finally:
            reader.cleanup()

    # merge and process traces
    try:
        proc = sysview.SysViewMultiStreamTraceDataProcessor(
            traces=parsers,
            print_events=args.dump_events,
            keep_all_events=True if args.to_json else False)
        if include_events['heap']:
            proc.add_stream_processor(
                sysview.SysViewTraceDataParser.STREAMID_HEAP,
                sysview.SysViewHeapTraceDataProcessor(
                    args.toolchain,
                    args.elf_file,
                    root_proc=proc,
                    print_heap_events=args.print_events))
        if include_events['log']:
            proc.add_stream_processor(
                sysview.SysViewTraceDataParser.STREAMID_LOG,
                sysview.SysViewLogTraceDataProcessor(
                    root_proc=proc, print_log_events=args.print_events))
    except Exception as e:
        logging.error("Failed to create data processor (%s)!", e)
        traceback.print_exc()
        sys.exit(2)

    try:
        logging.info("Process events from '%s'...", args.trace_sources)
        proc.merge_and_process()
        logging.info("Processing completed.")
    except Exception as e:
        logging.error("Failed to process trace (%s)!", e)
        traceback.print_exc()
        sys.exit(2)
    finally:
        if args.to_json:
            print(
                json.dumps(proc,
                           cls=sysview.SysViewTraceDataJsonEncoder,
                           indent=4,
                           separators=(',', ': '),
                           sort_keys=True))
        else:
            proc.print_report()
        proc.cleanup()
Beispiel #4
0
def main():

    parser = argparse.ArgumentParser(
        description='ESP32 SEGGER SystemView Trace Parsing Tool')

    parser.add_argument(
        'trace_sources',
        help='Trace data sources. Format: [file://]/path/to/file.',
        nargs='+',
        type=str)
    parser.add_argument('elf_file', help='Path to program ELF file.', type=str)
    parser.add_argument(
        '--tmo',
        '-w',
        help='Data wait timeout in sec. -1: infinite, 0: no wait',
        type=int,
        default=0)
    parser.add_argument('--dump-events',
                        '-d',
                        help='Dump all events.',
                        action='store_true')
    parser.add_argument(
        '--print-events',
        '-p',
        help=
        'Print events of selected types. By default only reports are printed',
        action='store_true')
    parser.add_argument('--include-events',
                        '-i',
                        help='Events types to be included into report.',
                        type=str,
                        choices=['heap', 'log', 'all'],
                        default='all')
    parser.add_argument('--toolchain',
                        '-t',
                        help='Toolchain prefix.',
                        type=str,
                        default='xtensa-esp32-elf-')
    parser.add_argument('--events-map',
                        '-e',
                        help='Events map file.',
                        type=str,
                        default=os.path.join(os.path.dirname(__file__),
                                             'SYSVIEW_FreeRTOS.txt'))
    args = parser.parse_args()

    def sig_int_handler(signum, frame):
        reader.cleanup()

    signal.signal(signal.SIGINT, sig_int_handler)

    include_events = {'heap': False, 'log': False}
    if args.include_events == 'all':
        for k in include_events:
            include_events[k] = True
    elif args.include_events == 'heap':
        include_events['heap'] = True
    elif args.include_events == 'log':
        include_events['log'] = True

    # parse trace files
    parsers = []
    for i, trace_source in enumerate(args.trace_sources):
        try:
            parser = sysview.SysViewMultiTraceDataParser(print_events=False,
                                                         core_id=i)
            if include_events['heap']:
                parser.add_stream_parser(
                    sysview.SysViewTraceDataParser.STREAMID_HEAP,
                    sysview.SysViewHeapTraceDataParser(print_events=False,
                                                       core_id=i))
            if include_events['log']:
                parser.add_stream_parser(
                    sysview.SysViewTraceDataParser.STREAMID_LOG,
                    sysview.SysViewLogTraceDataParser(print_events=False,
                                                      core_id=i))
            parsers.append(parser)
        except Exception as e:
            print("Failed to create data parser ({})!".format(e))
            traceback.print_exc()
            sys.exit(2)
        reader = apptrace.reader_create(trace_source, args.tmo)
        if not reader:
            print("Failed to create trace reader!")
            sys.exit(2)
        try:
            print("Parse trace from '{}'...".format(trace_source))
            sysview.parse_trace(reader, parser, args.events_map)
            print("Parsing completed.")
        except (apptrace.ReaderTimeoutError,
                apptrace.ReaderShutdownRequest) as e:
            print("Stop parsing trace. ({})".format(e))
        except Exception as e:
            print("Failed to parse trace ({})!".format(e))
            parser.cleanup()
            traceback.print_exc()
            sys.exit(2)
        finally:
            reader.cleanup()

    # merge and process traces
    try:
        proc = sysview.SysViewMultiTraceDataProcessor(
            traces=parsers, print_events=args.dump_events)
        if include_events['heap']:
            proc.add_stream_processor(
                sysview.SysViewTraceDataParser.STREAMID_HEAP,
                sysview.SysViewHeapTraceDataProcessor(
                    args.toolchain,
                    args.elf_file,
                    print_heap_events=args.print_events))
        if include_events['log']:
            proc.add_stream_processor(
                sysview.SysViewTraceDataParser.STREAMID_LOG,
                sysview.SysViewLogTraceDataProcessor(
                    print_log_events=args.print_events))
    except Exception as e:
        print("Failed to create data processor ({})!".format(e))
        traceback.print_exc()
        sys.exit(2)
    try:
        print("Process events from '{}'...".format(args.trace_sources))
        proc.merge_and_process()
        print("Processing completed.")
    except Exception as e:
        print("Failed to process trace ({})!".format(e))
        traceback.print_exc()
        sys.exit(2)
    finally:
        proc.print_report()