Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2024, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | # ----------------------------------------------------------------------------- |
| 8 | |
| 9 | import argparse |
| 10 | import logging |
| 11 | import re |
| 12 | import elftools |
| 13 | |
| 14 | def parse_line(line: str) -> str: |
| 15 | split = line.split(" ") |
| 16 | addr = split[5] |
| 17 | size = len(split[6]) // 2 |
| 18 | logging.debug("Instruction at {} of size {}".format(addr, size)) |
| 19 | return (addr, size) |
| 20 | |
| 21 | parser = argparse.ArgumentParser() |
| 22 | parser.add_argument("--input_file", help="tarmac file to input", required=True) |
| 23 | parser.add_argument("--log_level", help="Log level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="ERROR") |
| 24 | parser.add_argument("--output_file", help="output file, in qa-tools format", required=True) |
| 25 | args = parser.parse_args() |
| 26 | |
| 27 | # logging setup |
| 28 | logging.basicConfig(level=args.log_level) |
| 29 | |
| 30 | with open(args.input_file, "rt") as input_file: |
| 31 | trace = input_file.read() |
| 32 | |
| 33 | instructions = re.findall("[0-9]* [a-z]{2} [a-z\.]* IT .*", trace) |
| 34 | |
| 35 | hit_counts = {} |
| 36 | |
| 37 | for i in instructions: |
| 38 | addr = parse_line(i) |
| 39 | if addr in hit_counts.keys(): |
| 40 | hit_counts[addr] += 1 |
| 41 | else: |
| 42 | hit_counts[addr] = 1 |
| 43 | |
| 44 | with open(args.output_file, "w+") as output_file: |
| 45 | output_file.writelines(["{} {} {}\n".format(x[0], hit_counts[x], x[1]) for x in hit_counts.keys()]) |