blob: bc386e0f4320a986cc6aa07e5e3255ce239879a1 [file] [log] [blame]
Raef Coles8cbeed52024-03-11 16:24:57 +00001#!/usr/bin/python3
2# -----------------------------------------------------------------------------
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +00003# Copyright (c) 2024-2025, Arm Limited. All rights reserved.
Raef Coles8cbeed52024-03-11 16:24:57 +00004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# -----------------------------------------------------------------------------
8
9import argparse
10import logging
11import re
12import elftools
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000013from itertools import islice
Raef Coles8cbeed52024-03-11 16:24:57 +000014
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000015def parse_line_fvp(line: str) -> str:
Raef Coles8cbeed52024-03-11 16:24:57 +000016 split = line.split(" ")
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000017 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
26def 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 Coles8cbeed52024-03-11 16:24:57 +000035 return (addr, size)
36
37parser = argparse.ArgumentParser()
38parser.add_argument("--input_file", help="tarmac file to input", required=True)
39parser.add_argument("--log_level", help="Log level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="ERROR")
40parser.add_argument("--output_file", help="output file, in qa-tools format", required=True)
41args = parser.parse_args()
42
43# logging setup
44logging.basicConfig(level=args.log_level)
45
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000046instructions = []
47parse_function = parse_line_fvp
Raef Coles8cbeed52024-03-11 16:24:57 +000048hit_counts = {}
49
Jackson Cooper-Driver2d736062025-03-05 12:37:09 +000050with 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 Coles8cbeed52024-03-11 16:24:57 +000066
67with 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()])