Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # ----------------------------------------------------------------------------- |
Jackson Cooper-Driver | 2d73606 | 2025-03-05 12:37:09 +0000 | [diff] [blame] | 3 | # Copyright (c) 2024-2025, Arm Limited. All rights reserved. |
Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | # ----------------------------------------------------------------------------- |
| 8 | |
| 9 | import argparse |
| 10 | import logging |
| 11 | import re |
| 12 | import elftools |
Jackson Cooper-Driver | 2d73606 | 2025-03-05 12:37:09 +0000 | [diff] [blame] | 13 | from itertools import islice |
Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 14 | |
Jackson Cooper-Driver | 2d73606 | 2025-03-05 12:37:09 +0000 | [diff] [blame] | 15 | def parse_line_fvp(line: str) -> str: |
Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 16 | split = line.split(" ") |
Jackson Cooper-Driver | 2d73606 | 2025-03-05 12:37:09 +0000 | [diff] [blame] | 17 | try: |
| 18 | addr = split[5] |
| 19 | size = len(split[6]) // 2 |
| 20 | logging.debug("Instruction at {} of size {}".format(addr, size)) |
| 21 | except Exception as e: |
| 22 | print("Parse error {} for line {}".format(e,line)) |
| 23 | raise Exception |
| 24 | return (addr, size) |
| 25 | |
| 26 | def parse_line_rtl(line: str) -> str: |
| 27 | try: |
| 28 | split = line.split(" ")[1].replace("(", "").replace(")", "").split(":") |
| 29 | addr = split[0] |
| 30 | size = len(split[1]) // 2 |
| 31 | logging.debug("Instruction at {} of size {}".format(addr, size)) |
| 32 | except Exception as e: |
| 33 | print("Parse error {} for line {}".format(e,line)) |
| 34 | raise Exception |
Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 35 | return (addr, size) |
| 36 | |
| 37 | parser = argparse.ArgumentParser() |
| 38 | parser.add_argument("--input_file", help="tarmac file to input", required=True) |
| 39 | parser.add_argument("--log_level", help="Log level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="ERROR") |
| 40 | parser.add_argument("--output_file", help="output file, in qa-tools format", required=True) |
| 41 | args = parser.parse_args() |
| 42 | |
| 43 | # logging setup |
| 44 | logging.basicConfig(level=args.log_level) |
| 45 | |
Jackson Cooper-Driver | 2d73606 | 2025-03-05 12:37:09 +0000 | [diff] [blame] | 46 | instructions = [] |
| 47 | parse_function = parse_line_fvp |
Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 48 | hit_counts = {} |
| 49 | |
Jackson Cooper-Driver | 2d73606 | 2025-03-05 12:37:09 +0000 | [diff] [blame] | 50 | with open(args.input_file, "rt") as input_file: |
| 51 | while(lines := list(islice(input_file, 100000))): |
| 52 | lines = ''.join(lines) |
| 53 | chunk_instructions = re.findall(r'[0-9]* [a-z]{3} [a-z\.]* IT .*', lines) |
| 54 | |
| 55 | if len(chunk_instructions) == 0: |
| 56 | chunk_instructions = re.findall(r'[0-9]* clk ES (.*:.*).*', lines) |
| 57 | if len(chunk_instructions) != 0: |
| 58 | parse_function = parse_line_rtl |
| 59 | |
| 60 | for i in chunk_instructions: |
| 61 | addr = parse_function(i) |
| 62 | if addr in hit_counts.keys(): |
| 63 | hit_counts[addr] += 1 |
| 64 | else: |
| 65 | hit_counts[addr] = 1 |
Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame] | 66 | |
| 67 | with open(args.output_file, "w+") as output_file: |
| 68 | output_file.writelines(["{} {} {}\n".format(x[0], hit_counts[x], x[1]) for x in hit_counts.keys()]) |